-
Notifications
You must be signed in to change notification settings - Fork 439
[SwiftLexicalLookup] Add support for #if
and macro declarations. More ASTScope
related fixes.
#2883
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
[SwiftLexicalLookup] Add support for #if
and macro declarations. More ASTScope
related fixes.
#2883
Conversation
…rt for macro declarations. Minor fixes.
@swift-ci Please test |
|
||
/// Creates a new lookup configuration. | ||
/// | ||
/// - `finishInSequentialScope` - specifies whether lookup should finish | ||
/// in the closest sequential scope. `false` by default. | ||
@_spi(Experimental) public init( | ||
finishInSequentialScope: Bool = false | ||
finishInSequentialScope: Bool = false, | ||
buildConfiguration: BuildConfiguration? = nil |
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.
It's probably worth taking in a ConfiguredRegions
here rather than a BuildConfiguration
. ConfiguredRegions
caches results so we aren't re-evaluating the same #if
s repeatedly.
if !containsExpressionSyntax && pattern.is(ExpressionPatternSyntax.self) { | ||
containsExpressionSyntax = true | ||
} | ||
|
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.
This is because we suppress the implicit error
when there is some kind of pattern? Please leave such a comment with a code example to remind our future selves.
} | ||
} | ||
|
||
@_spi(Experimental) extension IfConfigDeclSyntax: IntroducingToSequentialParentScopeSyntax, SequentialScopeSyntax { |
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.
This was quite straightforward, I love it!
@swift-ci please test Windows |
1 similar comment
@swift-ci please test Windows |
@swift-ci please test |
@swift-ci please test Windows |
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 only skimmed through it and that looked. Thank you, @MAJKFL 😍.
clause = | ||
clauses | ||
.first { clause in | ||
clause.poundKeyword.tokenKind == .poundElse | ||
} |
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.
Do we want to use the #else
clause if no configured regions are specified? It’s a question. I don’t know what the correct answer here should be.
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, that was my intention that when config.buildConfiguration
is set to nil
it should provide some "default" behavior. I think it makes sense to use #else
as the only other logical solution here I can think of would be maybe not including any names from #if
clauses? Either way, I'm open to debate and I'm curious what do you think about 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.
The only alternative I can think of would be to throw an error or something like that. @DougGregor Do you remember what we do in SwiftIfConfig
when we’re unable to answer a query in the build configuration?
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.
SwiftIfConfig treats the condition as having failed if the configuration can't answer the query.
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.
OK, I guess that matches picking the #else
clause then.
This PR includes more fixes that bring
SwiftLexicalLookup
unqualified lookup implementation closer to theASTScope
counterpart. Those include:#if
clauses thanks toSwiftIfConfig
..reversed()
for iteration. Since it's more likely code block contains more variable decls than named decls, sequential lookup first goes through all items, and collects named decls.wildcard
token filtering for names fromIdentifiableSyntax
.With this PR, I was able to run validation for the entire Swift standard library with just two remaining bugs!