-
Notifications
You must be signed in to change notification settings - Fork 10.5k
ASTScope: Pre-compute the right source ranges instead of relying on widening #34205
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
ASTScope: Pre-compute the right source ranges instead of relying on widening #34205
Conversation
0397f93
to
9cf355e
Compare
@swift-ci Please smoke test |
@swift-ci Please test source compatibility |
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.
Can't do a detailed review today, but based on our offline conversation, the idea is sound. Let me know if you want me to go back and closely scrutinize it tomorrow.
@swift-ci Please test source compatibility |
@swift-ci Please smoke test |
@swift-ci Please test source compatibility |
@swift-ci Please smoke test Linux |
The source range needs to contain the argument expression.
The source range needs to contain any attributes on the subscript declaration, since those might create child scopes (@_specialize, property wrappers, etc).
The top-level scope for a conditional clause with a pattern is now ConditionalClausePatternUseScope, which introduces the pattern's bindings. Since the patterns are not visible in their own initializer, a new ConditionalClauseInitializerScope is used for the initializer. While it is nested inside of the ConditionalClausePatternUseScope, it's lookup parent skips one level, giving us the desired behavior.
Top-level code can contain guard statements which introduce bindings until the end of the parent scope, so plumb that through.
A SourceFile might contain TopLevelCodeDecls with guard statements, which introduce names until the end of the file, so plumb that through.
9cf355e
to
b8cccb1
Compare
@swift-ci Please test source compatibility |
@swift-ci Please smoke test |
Today, if the source range of a child scope extends beyond the bounds of the parent, we automatically extend the source range of the parent. This PR fixes the handful of scope implementations which relied on this behavior to compute their complete source range up-front.
Also, in a few places in the parser, we recover from a missing BraceStmt by creating a new, empty BraceStmt whose source location is where the brace was expected to be seen. This can overlap with a scope created for the following statement, though. To avoid violating invariants, we now skip creating a BraceStmtScope entirely if the corresponding BraceStmt is empty. Not only is this a small optimization, it also avoids creating the scope in the invalid case.