-
Notifications
You must be signed in to change notification settings - Fork 10.5k
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
[Macros] Don't visit macro-generated extensions in visitAuxiliaryDecls
.
#66914
Conversation
@swift-ci please smoke test |
lib/Sema/TypeCheckMacros.cpp
Outdated
// hoisting behavior of macro-generated extensions, we simply expose the | ||
// extension to 'getTopLevelDecls()' and type check the extension eagerly | ||
// here. | ||
TypeChecker::typeCheckDecl(extension); |
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.
Could we instead visit these at the end of TypeCheckDeclPrimary's visitation? Doing a complete check of the extension seems unnecessary here.
(Also, you have typos "visitAuxiliarDecls" and "understsand").
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.
I suppose it's better to visit expanded extensions in TypeCheckDeclPrimary as opposed to visiting the top-level decls of SF->getSynthesizedFile()
at the end of TypeCheckSourceFileRequest::evaluate
because the former approach will definitely invoke the request if it hasn't already happened?
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.
I hadn't thought of TypeCheckSourceFileRequest::evaluate
. Visiting the top-level decls of the synthesized file there should work.
82bc829
to
b27efa0
Compare
b27efa0
to
6fe4845
Compare
…ls'. Macro-generated extensions are hoisted to file scope, because extensions are not valid in nested scopes. Callers of 'visitAuxiliaryDecls' assume that the auxiliary decls are in the same decl context as the original, which is clearly not the case for extensions, and it leads to issues like visiting extension at the wrong time during SILGen. The extensions are already added to the top-level decls, so we don't need to visit them as auxiliary decls, and we can type-check macro-expanded decls at the end of visitation in TypeCheckDeclPrimary.
6fe4845
to
83030a9
Compare
…s of the synthesized source file instead of a separate API to gather the extensions. This is how macro-generated extensions are visited everywhere else.
@swift-ci please smoke test |
Macro-generated extensions are hoisted to file scope, because extensions are not valid in nested scopes. Callers of
visitAuxiliaryDecls
assume that the auxiliary decls are in the same decl context as the original, which is clearly not the case for extensions, and it leads to issues like visiting extension at the wrong time during SILGen. The extensions are already added exposed viagetTopLevelDecls()
, so we don't need to visit them as auxiliary decls.Resolves: #66916, rdar://111000256