-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[test] Improve testing of Swift features #76740
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@swift-ci please test |
e7c0602
to
14e2017
Compare
@swift-ci please test |
This seems like a good idea to me. |
14e2017
to
e6de4f2
Compare
@swift-ci please test |
e6de4f2
to
8ca4461
Compare
@swift-ci please test |
8ca4461
to
647cfde
Compare
@swift-ci please test |
647cfde
to
8bfab1b
Compare
@swift-ci please test |
8bfab1b
to
d4e1fa8
Compare
@swift-ci please test |
d4e1fa8
to
360656c
Compare
@swift-ci please test |
360656c
to
5208bd6
Compare
@swift-ci please test |
Would it be easy to separate out the |
It is in part for simplicity (and as you point out consistency). The
I use a script like the one in I can also split this PR in 2, but I tried to keep the three commits as "on topic" as possible to make review of the first and third commit as easy as possible. Since I have been working on this, I had to rebase and recalculate the second commit all the time, which I understand is difficult to review. I can maybe split it per feature "sets", if people think it is easier to review that way. BTW, I was planning to probably merge this over a weekend or similar, since it is the moment less people are working on the repos and I can probably avoid anybody introducing another usage of an experimental feature in the tests while this PR is being tested. |
5208bd6
to
ac667a0
Compare
@swift-ci please test |
d2126fb
to
6478445
Compare
@swift-ci please test |
6478445
to
4deecc9
Compare
@swift-ci please test |
4deecc9
to
1304a4f
Compare
@swift-ci please test |
Thinking in landing this over the weekend to be less disruptive, if nobody has more feedback and all the testing is green (I will probably rebase again and redo testing to avoid any race conditions landing with other code). I would appreciate a thumbs up, if nobody has any problems with the approach. |
Take the `Features.def` file used in other parts of the code and create a file that can be used from the LLVM Lit configuration files to add new available features that can be checked from the tests with `REQUIRES` and others. The file `lit.swift-features.cfg.inc` is preprocessed by Clang and generates a file with Python syntax that can be loaded from both `lit.site.cfg.in` files. The preprocessing output is copied into the different test directories in the build directory, and added it is added as a dependency of them, so it will be generate when the test run or when `Features.def` changes. `EXPERIMENTAL_FEATURES` are only enabled if they are available in production or the compiler is being built with assertions, while `UPCOMING_FEATURES` and the rest of the `LANGUAGE_FEATURES` are always available.
Find all the usages of `--enable-experimental-feature` or `--enable-upcoming-feature` in the tests and replace some of the `REQUIRES: asserts` to use `REQUIRES: swift-feature-Foo` instead, which should correctly apply to depending on the asserts/noasserts mode of the toolchain for each feature. Remove some comments that talked about enabling asserts since they don't apply anymore (but I might had miss some). All this was done with an automated script, so some formatting weirdness might happen, but I hope I fixed most of those. There might be some tests that were `REQUIRES: asserts` that might run in `noasserts` toolchains now. This will normally be because their feature went from experimental to upcoming/base and the tests were not updated.
The test will look for other tests using `RUN:` lines that use experimental or upcoming features and will check that the tests also are checking with the right `REQUIRES:` lines for the used features. This should avoid new tests being introduced without the right `REQUIRES` and should avoid breaking the toolchain in less tested configurations.
Quickly explain the feature, its intended usage and a warning about not longer needing `REQUIRES: asserts` anymore.`
68acf40
to
2f62bf4
Compare
@swift-ci please test |
After pulling this down and rebuilding swift from scratch, I'm unable to run tests:
|
Did you try with |
Yes, I made sure I re-ran with |
In Lines 1553 to 1554 in c0a55e1
SWIFT_INCLUDE_TESTS is not set, the full test/ subdirectory is skipped from CMake. I normally keep my presets with --test and --validation-test enabled, and then --skip-test-swift (and a bunch of others) so the tests do not actually run while building.
|
I wonder if there is much of a benefit to skipping the test subdirectory in the CMake when |
I am surprised that it was working for you without going into that directory at least once before. The code for |
|
I was not expecting features disappearing from that file. I can try to see what I can do. |
While doing swiftlang#76740 I iteratively was adding new `REQUIRES:` as new usages of the features were found, but I did not realize that at the same time other people might be removing some of those usages. The tests in this commit had some `REQUIRES:` line for a previous `-enable-experimental/upcoming-feature`, but they not longer use those features, so the `REQUIRES:` were effectively disabling the tests (at least in the case of `KeyPathWithStaticMembers`. In other cases they might still had executed).
While doing swiftlang#76740 I iteratively was adding new `REQUIRES:` as new usages of the features were found, but I did not realize that at the same time other people might be removing some of those usages. The tests in this commit had some `REQUIRES:` line for a previous `-enable-experimental/upcoming-feature`, but they not longer use those features, so the `REQUIRES:` were effectively disabling the tests (at least in the case of `KeyPathWithStaticMembers`. In other cases they might still had executed).
Sometimes features are removed from `Features.def`, but they are not removed from the test files. The compiler ignores every feature that does not exist. This leads to removed features still being tested, and with the introduction of swiftlang#76740, `REQUIRED:`. Modify the code that generates the active feature set for testing to also generate the set of existing features, and pass this list of existing features to the verifier script. If a feature is trying to be activated and does not exist, the verifier will warn the user. - `SwiftParser` feature was renamed `ParserASTGen`, but some tests were using both spellings. Remove the mentions of `SwiftParser` in the tests. - `ImportObjcForwardDeclarations` was spelled with upper case `C` in a couple of tests. Fix it so the matching is easier. - `TransferringArgsAndResults` was an experimental feature that was removed. - Ignore the usage of inexisting feature in `swift-export-as.swift` because it seems to be what the test is actually testing. - Ignore the test `availability_define.swift` because it tests the pseudo-feature `AvailabilityMacro=` which is not part of `Features.def`.
Sometimes features are removed from `Features.def`, but they are not removed from the test files. The compiler ignores every feature that does not exist. This leads to removed features still being tested, and with the introduction of #76740, `REQUIRED:`. Modify the code that generates the active feature set for testing to also generate the set of existing features, and pass this list of existing features to the verifier script. If a feature is trying to be activated and does not exist, the verifier will warn the user. - `SwiftParser` feature was renamed `ParserASTGen`, but some tests were using both spellings. Remove the mentions of `SwiftParser` in the tests. - `ImportObjcForwardDeclarations` was spelled with upper case `C` in a couple of tests. Fix it so the matching is easier. - `TransferringArgsAndResults` was an experimental feature that was removed. - Ignore the usage of inexisting feature in `swift-export-as.swift` because it seems to be what the test is actually testing. - Ignore the test `availability_define.swift` because it tests the pseudo-feature `AvailabilityMacro=` which is not part of `Features.def`.
@drodriguez – apologies for hijacking this PR commentary, but i just hit the same issue @tshortli reported above after updating my checkout to f88b29b yesterday and re-running the |
See my answer in the forums https://forums.swift.org/t/missing-lit-config-file-after-swift-compiler-build/76019/14. Were you running |
thanks for the feedback! as best i can tell from the shell history i have left, i ran it via |
I was trying to change things a little to avoid the failure in #77658. Hopefully that will avoid most of the errors, but it will hide whatever missing dependency is happening in your (and many others) case. I simply cannot repro the problem people are having. |
Features in Swift can be experimental, upcoming or base features. During their lifetime features evolve from one category to other categories. Usually experimental features are only available in "asserts" compilers, but they can also be experimental features in "non asserts" compilers. Upcoming and base features are available in both "asserts" and "non asserts" compilers.
When coding a new feature, the feature normally will start as an experimental feature. In the past this has required to mark the tests that use that feature with
REQUIRES: asserts
to avoid the test failing when testing in a "non asserts" compilers. This requisite is not always follow, and we forget to add thoseREQUIRES: asserts
from time to time. This causes breakages for people that test the "non asserts" compilers. For some experimental features that are available in production compilers theREQUIRES: asserts
is not even needed, which can make adding those lines work against one intentions. When the feature graduates from experimental to upcoming or base, we sometimes forget to update the the related tests to remove thoseREQUIRES: asserts
, so a "non asserts" compiler will not actually execute those tests, and bugs can be introduced by mistake in those compilers.The changes in this PR introduce a system that aims to simplify testing those experimental features and avoid some of the problems noted above.
The first change is take the canonical
Features.def
and transform its contents in something that LLVM Lit can createavailable_features
for. This is done abusing the Clang preprocessor to transform the.def
file into a Python file that can be loaded bylit.site.cfg
during testing. This is done for each build and will pick up changes in theFeatures.def
as they happen, so it will always be up-to-date. Additionally it understand when features as available depending on "asserts" or "non asserts" compilers, and will not incorrectly require an "asserts" compiler for non-production features, or let experimental features be tested in a "non asserts" compiler.The second part of the change is keeping the tests up-to-date with the features they are testing, so each test that uses a feature is marked as such. This is done with a test itself, which greps through the existing tests, checks for the usage of
-enable-experimental-feature
or-enable-upcoming-feature
and warns the user about the missingREQUIRES:
lines (failing the test suite, so nobody can submit a test that skips the requirements).Finally, the last change is modifying a huge number of tests to follow the new rules. All the tests that currently use
-enable-experimental-feature
or-enable-upcoming-feature
have been annotated withREQUIRES:
lines, and the (now unnecessary)REQUIRES: asserts
have been removed.