-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Introduce a new data structure to explicitly model scopes in the AST #4609
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
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…he AST. The scope map models all of the name lookup scopes within a source file. It can be queried by source location to find the innermost scope that contains that source location. Then, one can follow the parent pointers in the scope to enumerate the enclosing scopes. The scope map itself is lazily constructed, only creating scope map nodes when required implicitly (e.g, when searching for a particular innermost scope) or forced for debugging purposes. using a lazily-constructed tree that can be searched by source location. A search within a particular source location will
* A child to evaluate the conditions, which covers expressions in the conditions * A child for the 'else' body, which does not have access to the names in the conditions * A child for the continuation, which re-introduces the names in the conditions for the rest of the body Now we can assert that the only out-of-order case is for accessors.
… properties in local scopes.
…on a given source location. Given a source location, we can find the innermost enclosing scope that describes that source location. Introduce this operation into the scope map, then add a testing mode where we probe the scope map at specifi locations to see what we find. Test for: 1) Finding the right innermost enclosing scope, and 2) That we're only expanding the part of the scope map that is needed to identify that scope.
Source ranges are non-trivial to compute, small to store, and used often. Cache 'em.
Part of making the scope map subsume the DeclContext change, so we can identify the nearest enclosing DeclContext.
Consistently model all pattern bindings in the scope map, as well as having specific nodes for their initializers. This provides us with more consistency (the declarations are represented) as well as giving us a scope we can use to extract the DeclContext for a non-local initializer.
…ing DeclContexts of a scope.
@swift-ci please test and merge |
@swift-ci please smoke test macOS |
(the runtime weak reference race tests failure was not related to this change, but I'll smoke-test again regardless) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR introduces a new data structure that explicitly models scopes in the AST allowing one to query the innermost scope based on a source location and then walk the enclosing scopes. The data structure itself operates on parsed ASTs (which may also be type-checked; it doesn't matter) and is lazily constructed as needed.
At the moment, there are no clients for this data structure. However, it is intended to be used for unqualified name lookup and should also be able to subsume the type refinement context.