-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[Macros] Always visit macro-produced decls as auxiliary decls #64071
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
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.
Awesome!
@swift-ci please test |
cb83b40
to
1f1188c
Compare
96e11df
to
cb079cd
Compare
Always use `Decl::visitAuxiliaryDecls` to visit decls produced by macros, including peer macros and declaration macros. Use name-driven expansion for peer macros. Remove `MacroExpansionDecl::getRewritten()`. Also make `ExpandMacroExpansionDeclRequest` cache the buffer ID (similar to other macros) instead of an array of decls.
@swift-ci please smoke test |
// RUN: %target-build-swift -swift-version 5 -I %swift-host-lib-dir -L %swift-host-lib-dir -emit-library -o %t/%target-library-name(MacroDefinition) -module-name=MacroDefinition %S/Inputs/syntax_macro_definitions.swift -g -no-toolchain-stdlib-rpath | ||
// RUN: %target-typecheck-verify-swift -swift-version 5 -load-plugin-library %t/%target-library-name(MacroDefinition) -I %swift-host-lib-dir -disable-availability-checking | ||
// RUN: %target-swift-frontend -swift-version 5 -typecheck -load-plugin-library %t/%target-library-name(MacroDefinition) -I %swift-host-lib-dir %s -disable-availability-checking -dump-macro-expansions > %t/expansions-dump.txt 2>&1 | ||
// RUN: %target-build-swift -swift-version 5 -I %swift-host-lib-dir -L %swift-host-lib-dir -emit-library -o %t/%target-library-name(MacroDefinition) -parse-as-library -module-name=MacroDefinition %S/Inputs/syntax_macro_definitions.swift -g -no-toolchain-stdlib-rpath |
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.
Note: Needed to add -parse-as-library
to use @main
.
} | ||
// Expand macros based on the name. | ||
if (introducesArbitraryNames || allIntroducedNames.contains(name)) | ||
member->visitAuxiliaryDecls([&](Decl *decl) { |
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.
Note: Since visitAuxiliaryDecls
already expands all attached peer macros, I'm unconditionally adding all macro expansions to the lookup table without checking whether the expansion is from the macro that declared the name. A future improvement could be specifying which CustomAttr
to expand as an argument to visitAuxiliaryDecls
.
@swift-ci please smoke test |
Always use
Decl::visitAuxiliaryDecls
to visit decls produced by macros, including peer macros and declaration macros. Use name-driven expansion for peer macros. RemoveMacroExpansionDecl::getRewritten()
.Also make
ExpandMacroExpansionDeclRequest
cache the buffer ID (similar to other macros) instead of an array of decls.