Skip to content

[Macros] Create type refinement context for MacroExpansionDecl #65959

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
merged 1 commit into from
May 17, 2023

Conversation

rintaro
Copy link
Member

@rintaro rintaro commented May 16, 2023

rdar://107386648

@rintaro
Copy link
Member Author

rintaro commented May 16, 2023

@swift-ci Please smoke test

@@ -53,6 +53,13 @@ TypeRefinementContext::createRoot(SourceFile *SF,
if (auto parentExpansion = SF->getMacroExpansion()) {
if (auto parentTRC =
SF->getEnclosingSourceFile()->getTypeRefinementContext()) {
// FIXME: Skip `MacroExpansionDecl` context?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you don't need this.

@@ -1482,7 +1482,7 @@ class Traversal : public ASTVisitor<Traversal, Expr*, Stmt*,

bool shouldSkip(Decl *D) {
if (!Walker.shouldWalkMacroArgumentsAndExpansion().second &&
D->isInMacroExpansionInContext())
D->isInMacroExpansionInContext() && !Walker.Parent.isNull())
Copy link
Member Author

@rintaro rintaro May 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TypeRefinementContextBuilder doesn't walk into expansions, but It does decl->walk(builder) on the top level decls of the synthesized buffer. In such cases, I think the caller explicitly want to walk to it regardless of the macro walk mode.

Comment on lines 61 to 69
public struct FuncWithClosureMacro: DeclarationMacro {
public static func expansion(
of node: some FreestandingMacroExpansionSyntax,
in context: some MacroExpansionContext
) throws -> [DeclSyntax] {

return ["func LocalFunc() {}", "var LocalVar: Int { 1 }"]
}
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated. Will remove this

Comment on lines +139 to +129
@available(macOS 99, *)
#funcFromClosureMacro(APIFrom99()) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add test case without this attribute. to check if it's diagnosed properly

@rintaro rintaro force-pushed the macros-typerefinement-context branch from 2d81379 to d49acf9 Compare May 17, 2023 03:46
@rintaro rintaro force-pushed the macros-typerefinement-context branch from d49acf9 to 7c2a73e Compare May 17, 2023 03:47
@rintaro rintaro marked this pull request as ready for review May 17, 2023 03:48
@rintaro
Copy link
Member Author

rintaro commented May 17, 2023

@swift-ci Please smoke test

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