-
Notifications
You must be signed in to change notification settings - Fork 10.6k
Rework computation of local discriminators for named entities. #62741
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
DougGregor
merged 6 commits into
swiftlang:main
from
DougGregor:local-named-discriminators
Jan 3, 2023
Merged
Rework computation of local discriminators for named entities. #62741
DougGregor
merged 6 commits into
swiftlang:main
from
DougGregor:local-named-discriminators
Jan 3, 2023
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
Local discriminators for named entities are currently being set by the parser, so entities not created by the parser (e.g., that come from synthesized code) don't get local discriminators. Moreover, there is no checking to ensure that every named local entity gets a local discriminator, so some entities would incorrectly get a local discriminator of 0. Assign local discriminators as part of setting closure discriminators, in response to a request asking for the local discriminator, so the parser does not need to track this information, and all local declarations---including synthesized ones---get local discriminators. And add checking to make sure that every entity that needs a local discriminator gets assigned one. There are a few interesting cases in here: * There was a potential mangling collision with local property wrappers because their generated variables weren't getting local discriminators * $interpolation variables introduced for string interpolation weren't getting local discriminators, they were just wrong. * "Local rename" when dealing with captures like `[x]` was dependent on the new delcaration of `x` *not* getting a local discriminator. There are funny cases involving nesting where it would do the wrong thing.
The parser no longer sets local discriminators, and this function is currently only responsible for adding local type declarations to the source file. Rename it and remove most of the former callers so it does just that.
The "local context" was only used to prevent parsing of closures in a non-local context, and also string interpolations because they are similar-ish to closures. However, this isn't something a parser should decide, so remove this special-case semantic check from the parser and eliminate the notion of "local context" entirely.
373c831 to
b399b92
Compare
Member
Author
|
@swift-ci please smoke test |
Member
Author
|
@swift-ci please test source compatibility |
Member
Author
|
@swift-ci please smoke test |
Member
Author
|
@swift-ci please test source compatibility |
Member
Author
|
@swift-ci please smoke test macOS |
Member
Author
|
@swift-ci please smoke test |
Member
Author
|
@swift-ci please smoke test |
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.
Local discriminators for named entities are currently being set by the
parser, so entities not created by the parser (e.g., that come from
synthesized code) don't get local discriminators. Moreover, there is
no checking to ensure that every named local entity gets a local
discriminator, so some entities would incorrectly get a local
discriminator of 0.
Assign local discriminators as part of setting closure discriminators,
in response to a request asking for the local discriminator, so the
parser does not need to track this information, and all local
declarations---including synthesized ones---get local discriminators.
And add checking to make sure that every entity that needs a local
discriminator gets assigned one.
There are a few interesting cases in here:
wrappers because their generated variables weren't getting local
discriminators
[x]was dependent onthe new delcaration of
xnot getting a local discriminator. Thereare funny cases involving nesting where it would do the wrong thing.
With the parser no longer assigning local named discriminators, eliminate
the notion of "local contexts" as parser state entirely.