-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Name lookup and type checking fixes for freestanding declaration macros #64803
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 12 commits into
swiftlang:release/5.9
from
DougGregor:freestanding-macro-lookup-and-single-type-check-5.9
Mar 31, 2023
Merged
Name lookup and type checking fixes for freestanding declaration macros #64803
DougGregor
merged 12 commits into
swiftlang:release/5.9
from
DougGregor:freestanding-macro-lookup-and-single-type-check-5.9
Mar 31, 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
Member
DougGregor
commented
Mar 31, 2023
- Explanation: Introduce two significant fixes for freestanding declaration macros, ensuring that their arguments aren't type-checked twice, and fixing name lookup within those macro arguments.
- Scope: Affects type-checking only for freestanding declaration macros.
- Issue: rdar://107388151
- Risk: Low; only affects freestanding declaration macros.
- Testing: Additional tests added.
- Reviews: @hborla and @rxwei
- Original pull request: [Macros] Name lookup and type checking fixes for freestanding declaration macros #64761
In preparation for supporting macros that are defined in terms of other macros, adopt macro definition checking provided by the `MacroDeclSyntax.checkDefinition` operation (implemented in swift-syntax). Use this in lieu of the checking on the C++ side. This required me to finally fix an issue with the source ranges for Fix-Its, where we were replacing the leading/trailing trivia of nodes along with the node itself, even though that's incorrect: we should only replce the node itself, and there are other Fix-It kinds for replacing leading or trailing trivia. (cherry picked from commit 49277f7)
We were enabling the `$Macros` feature unconditionally, even when the compiler itself doesn't support macros (because it's missing swift-syntax). Change this to only enable the feature when the compiler supports it. (cherry picked from commit 73a2041)
Handle a trivial macro defined in terms of another macro. (cherry picked from commit 9292231)
This enables macros to be defined in terms of other macros. (cherry picked from commit 40b3321)
These expressions are a little tricky, because we don't always type-check them in the way that clients would expect. We might want to change the representation here, but until then... don't walk the untypechecked ones. (cherry picked from commit aac0406)
(cherry picked from commit 38230b7)
This should complete the implementation of expanded macro definitions, rdar://104044325. (cherry picked from commit cfbdae5)
(cherry picked from commit 30f1794)
(cherry picked from commit 68b367b)
…s twice Instead of trying to work around a double-type-check of macro expansion declaration arguments, avoid type checking them twice in the first place. We're caching the `ResolveMacroRequest` output in a somewhat dodgy manner to account for the `MacroExpansionDecl`/`MacroExpansionExpr` cloning. (cherry picked from commit dd2d851)
Teach ASTScope to create child nodes for each of the arguments of a macro expansion declaration, so that we can perform name lookup into them. Otherwise, we cannot have nontrivial closures in arguments to a macro expansion declaration. Fixes rdar://107388151. (cherry picked from commit 82de47c)
Sometimes we build a `MacroExpansionDecl` from a `MacroExpansionExpr`. Sometimes we do it the other way. In both cases, we risk the two copies of must-by-shared data (macro arguments, resolved macro reference, etc.) getting out-of-sync. Instead, share the storage between the two representations when we create one from the other, so that they cannot get out-of-sync. This allows us to eliminate the extremely-dodgy `cacheOutput` call earlier. (cherry picked from commit 583ca47)
Note that this is 3 commits on top of #64802, but cannot be separated due to conflicts. |
@swift-ci please test |
nkcsgexi
approved these changes
Mar 31, 2023
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.