-
Notifications
You must be signed in to change notification settings - Fork 10.6k
Adopt SwiftIfConfig library to help with #if clause handling
#75014
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
Adopt SwiftIfConfig library to help with #if clause handling
#75014
Conversation
|
@swift-ci please smoke test |
7813360 to
444a9d6
Compare
|
I forgot a |
|
@swift-ci please smoke test |
444a9d6 to
37ebac2
Compare
|
Turns out that we had to model where the |
|
@swift-ci please smoke test |
hamishknight
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could take this opportunity to sink the mutating-ness into withBridgedString, it doesn't seem like any clients are really benefitting from it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought it was intentional (because String's withUTF8 is mutating), but if we don't care... yeah, we could do that.
|
@swift-ci please smoke test |
5a3ff4a to
a48871d
Compare
|
@swift-ci please smoke test |
1 similar comment
|
@swift-ci please smoke test |
This concrete implementation of the BuildConfiguration allows the use of the SwiftIfConfig library's APIs where the build configuration comes from the compiler itself.
The SwiftIfConfig library provides APIs for evaluating and extracting the active #if regions in source code. Use its "configured regions" API along with the ASTContext-backed build configuration to reimplement the extraction of active/inactive regions from the source. This approach has the benefit of being effectively stateless: where the existing solution relies on the C++ parser recording all of the `#if` clauses it sees as it is parsing (and then might have to sort them later), this version does a scan of source to collect the list without requiring any other state. The newer implementation is also conceptually cleaner, and can be shared with other clients that have their own take on the build configuration. The primary client of this information is the SourceKit request that identifies "inactive" regions within the source file, which IDEs can use to grey out inactive code within the current build configuration. There is also some profiling information that uses it. Those clients should be unaffected by this under-the-hood change. For the moment, I'm leaving the old code path in place for compiler builds that don't have swift-syntax. This should be considered temporary, and that code should be removed in favor of request'ifying this function and removing the incrementally-built state entirely.
…SwiftIfConfig The SIL coverage map generation depends on the locations of the `#endif` directives, but the mapping from SwiftIfConfig's configured regions wasn't producing them. The information is implicitly available in the SwiftIfConfig configured regions, so reconstitute it as we translate regions.
This implementation depends on ASTGen, which isn't linked as part of the AST library.
7d52780 to
a844f4f
Compare
|
@swift-ci please smoke test |
…dConfiguration Unlike all of the other build configuration checks, `canImport` has side effects including the emission of various diagnostics. Thread a source location through here so the diagnostics end up on the right line.
|
@swift-ci please smoke test |
|
@swift-ci please test source compatibility |
|
The failures from that debug build are also failing on |
…nstaller step swiftlang/swift#75014 added the new dependency, that the swift compiler depends on, and thus we need to make sure that this DLL is installed
Start adopting the new
SwiftIfConfiglibrary to reason about#ifclauses in a few places in the compiler. There are two aspects to this:CompilerBuildConfiguration, a wrapper around anASTContextthat conforms to the newBuildConfigurationprotocol from theSwiftIfConfiglibrary. This allows us to use the APIs inSwiftIfConfigbacked by the logic for compiler conditionals (hasFeature,os(XYZ),canImport, etc.) within the compiler itself.SourceFile::getIfConfigClauseRanges()with one based onSwiftIfConfig's enumeration of configured regions. This has the advantage of being less "stateful", because it doesn't need to rely on the C++ parser populating an array as it parses.