This is an archive of the discontinued LLVM Phabricator instance.

[split-file] Add flags to support comments and adding extension to output files
AcceptedPublic

Authored by Endill on May 19 2023, 12:43 PM.

Details

Summary
  • --allow-comments cuts part name at the colon if one is present
  • --add-file-extension adds specified extension to output files

We will change tests under clang/test/CXX/drs to use //--- dr164: 16 instead of // dr164: 16.
With --add-file-extension=.cpp --allow-comments, split-file will create a file named dr164.cpp instead of dr164: 16.
I go into more details on motivation in Discourse thread.

Diff Detail

Event Timeline

Endill created this revision.May 19 2023, 12:43 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 19 2023, 12:43 PM
Endill requested review of this revision.May 19 2023, 12:43 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 19 2023, 12:43 PM

Should this also update https://llvm.org/docs/TestingGuide.html#extra-files so we have some public documentation for the functionality?

llvm/utils/split-file/split-file.cpp
47
52
138–139

Should we be kind and look at addFileExtension.getValue()[0] to see if it's . already? e.g., the user does: --add-file-extension=.cpp

Endill updated this revision to Diff 524610.May 23 2023, 1:39 AM

Address Aaron's feedback

Endill marked 2 inline comments as done.May 23 2023, 1:51 AM

Should this also update https://llvm.org/docs/TestingGuide.html#extra-files so we have some public documentation for the functionality?

I don't think the features I implements blend in the motivating example of "Extra files" section.
I'd say we deserve our own subsection, e.g. "Grouping small tests in a single file", where we can showcase our use case, but that requires lit side of things (%{for-each-file}) to be merged as well. So I'd like to address this in a separate patch. Feel free to remind me if I get lazy or forget about this :)

llvm/utils/split-file/split-file.cpp
138–139

That's a good suggstion

I go into more details on motivation in Discourse thread.

Thanks for the link, but it seems that the thread doesn't give examples how --allow-comments and --add-file-extension are supposed to be used.

// dr164: 16 becomes //--- dr164: 16, which produces dr164.cpp file with the corresponding test.

I am confused by this comment. Does the option ignore everything starting from the :? Why?
The Discourse thread gives a link to https://github.com/llvm/llvm-project/blob/main/clang/test/CXX/drs/dr5xx.cpp which uses this notation, but the discourse thread doesn't elaborate on the syntax. This kind of detail is actually what I expect from the commit message/Phabricator summary, instead of some information embedded in a very long C++ DR specific forum post.

For testing, use llvm/test/tools/split-file/ and ninja check-llvm-tools-split-file.

I go into more details on motivation in Discourse thread.

Thanks for the link, but it seems that the thread doesn't give examples how --allow-comments and --add-file-extension are supposed to be used.

It does. Here's the link I used there: https://gist.github.com/Endilll/1d8035d42bdf0dc73eaaf8a8c343bf8c/revisions?diff=unified
There I diff current notation and notation we strive for.

// dr164: 16 becomes //--- dr164: 16, which produces dr164.cpp file with the corresponding test.

I am confused by this comment. Does the option ignore everything starting from the :? Why?

Yes, it ignores everything starting from the :, because in our use case that's where part name ends, and where additional data begins (which clang version implements the DR).

The Discourse thread gives a link to https://github.com/llvm/llvm-project/blob/main/clang/test/CXX/drs/dr5xx.cpp which uses this notation, but the discourse thread doesn't elaborate on the syntax. This kind of detail is actually what I expect from the commit message/Phabricator summary, instead of some information embedded in a very long C++ DR specific forum post.

What you can see today in dr5xx.cpp is a notation that we've been using for years and happy about. In that thread I go into why we need the change this patch is a part of, and why in this particular form. Explaining that would be copy-pasting large chunks from "Use case" section of that thread. I can do that for commit description if you find that helpful.

For testing, use llvm/test/tools/split-file/ and ninja check-llvm-tools-split-file.

Thank you, I'll try that.

// dr164: 16 becomes //--- dr164: 16, which produces dr164.cpp file with the corresponding test.

I am confused by this comment. Does the option ignore everything starting from the :? Why?

The current DR script works by looking for magic comments of the form // drNNNN: MM where NNNN is the DR # and MM is the version of Clang it's implemented in (or specifies it's not implemented, is partial, etc; there are non-numeric values for that). The idea behind this patch is to allow this to work with split-file commands so that we can have one test file with hundreds of DRs tested in it, but we can hermetically test some of those DRs to avoid interactions between tests (which happens today unfortunately). In order to support that need, we need some way to specify a file extension (otherwise the file ends up with no extension and we need to add -x c++ to the RUN lines which is unnatural and distracting) and we need some way to tell split-file that the splitting happens at a slightly differently than normal so that --- dr123: 16 doesn't try to generate a file named dr123: 16. --add-file-extension serves the first purpose and --allow-comments serves the second.

Thanks for the reply. The motivation looks good!

Those two features allow us to integrate split-file notation and C++ DR tests notation:
dr164: 16 becomes --- dr164: 16, which produces dr164.cpp file with the corresponding test.
I go into more details on motivation in Discourse thread.

I think this paragraph can be made clearer without being overly verbose:

We will change some tests under clang/test/CXX/drs to use //--- dr164: 16 instead of // dr164.
With --add-file-extension=.cpp --allow-comments, split-file will create a file named dr164.cpp instead of dr164: 16.

Endill edited the summary of this revision. (Show Details)May 24 2023, 9:01 AM

I think this paragraph can be made clearer without being overly verbose:

We will change some tests under clang/test/CXX/drs to use //--- dr164: 16 instead of // dr164.
With --add-file-extension=.cpp --allow-comments, split-file will create a file named dr164.cpp instead of dr164: 16.

Used it for description with minor edits. Thank you!

MaskRay requested changes to this revision.May 30 2023, 8:14 PM

LG once the test is added :)

This revision now requires changes to proceed.May 30 2023, 8:14 PM
Endill updated this revision to Diff 526978.May 31 2023, 3:00 AM

Add tests
@MaskRay please let me know if I missed anything

MaskRay accepted this revision.Jun 5 2023, 7:34 AM

LGTM.

This revision is now accepted and ready to land.Jun 5 2023, 7:34 AM