Skip to content

[Macros] Name lookup and type checking fixes for freestanding declaration macros #64761

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

Conversation

DougGregor
Copy link
Member

Introduce two significant fixes for freestanding declaration macros:

  • Ensure that we do not check the arguments of a freestanding declaration macro twice
  • Fix name lookup in macro arguments by adding them to the ASTScope tree

Fixes rdar://107388151.

…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.
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.
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.
@DougGregor
Copy link
Member Author

@swift-ci please smoke test

@DougGregor DougGregor merged commit 36c3a81 into swiftlang:main Mar 30, 2023
@DougGregor DougGregor deleted the freestanding-macro-lookup-and-single-type-check branch March 30, 2023 13:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants