-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[ASTGen] Implement #if config handling using the SwiftIfConfig library #75937
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 smoke test |
f0df767
to
d2f5e13
Compare
Wherever there is a syntax collection in the syntax tree that can involve an `#if` clause, evaluate the `#if` conditions to find the active clause, then recurse into the active clause (if one exists) to "flatten" the translated collection to only contain active elements. Note that this does not yet handle #if for postfix expressions.
d2f5e13
to
1da2631
Compare
@swift-ci please smoke test |
@@ -18,9 +18,14 @@ import SwiftSyntax | |||
|
|||
/// A build configuration that uses the compiler's ASTContext to answer | |||
/// queries. | |||
struct CompilerBuildConfiguration: BuildConfiguration { | |||
final class CompilerBuildConfiguration: BuildConfiguration { |
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 we keep this a struct and construct it directly in the ASTGenVisitor's activeClause(in:)
instead?
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.
Yes. The real problem is that we don't have locations for import paths, so CompilerBuildConfiguration has mutable state for the location. I'm considering expanding BuildConfiguration to have a new "canImport" check that provides more source locations, which makes all of this cleaner.
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 really, really, really wanted to avoid having syntax nodes or source locations passed in to the BuildConfiguration
for philosophical reasons, but canImport
needs them. I'll go make those changes on the swift-syntax side and clean things up before coming back here to make this a struct
again and drop the mutable state.
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.
Just to be clear, I meant keeping the conditionLoc
on CompilerBuildConfiguration, but keeping it immutable by constructing it when querying the active clause, it doesn't seem like there are any other ASTGen methods that need it to be mutable state on self
. I agree that sinking it down into canImport
would probably be cleaner though.
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've moved it back to a struct
for now, pending the larger cleanup
Fixes a crash on Windows due to mismatched allocators.
@swift-ci please smoke test |
Wherever there is a syntax collection in the syntax tree that can involve an
#if
clause, evaluate the#if
conditions to find the active clause, then recurse into the active clause (if one exists) to "flatten" the translated collection to only contain active elements.Note that this does not yet handle #if for postfix expressions.