-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[Macros] Unify MacroExpansionDecl/MacroExpansionExpr expansion logic #66296
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
@swift-ci Please smoke test |
enum Kind { | ||
kExpr, // MacroExpansionExpr. | ||
kDecl, // MacroExpansionDecl. | ||
}; |
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.
Wouldn’t an enum class
be nicer here?
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.
Since I didn't want to pollute namespace of the subclasses, I hoisted this to global as FreestandingMacroKind
.
include/swift/AST/PrettyStackTrace.h
Outdated
@@ -93,7 +94,20 @@ class PrettyStackTraceAnyFunctionRef : public llvm::PrettyStackTraceEntry { | |||
virtual void print(llvm::raw_ostream &OS) const override; | |||
}; | |||
|
|||
void printExprDescription(llvm::raw_ostream &out, Expr *E, | |||
/// PrettyStackTraceAnyFreestandingMacroExpansion |
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.
This comment doesn’t seem to provide any value.
lib/Sema/TypeCheckMacros.cpp
Outdated
if (!macroRoles.contains(MacroRole::Expression)) { | ||
if (!macroRoles.contains(MacroRole::Declaration) && | ||
!ctx.LangOpts.hasFeature(Feature::CodeItemMacros)) { | ||
ctx.Diags.diagnose(loc, diag::macro_experimental, "code item", | ||
"CodeItemMacros"); | ||
return nullptr; | ||
} |
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 don’t think the implementation matches the comment here. Declaration macros don’t emit a diagnostic.
AFAIK declaration macros are enabled by default now, so I think you should be able to simplify this to
if (!macroRoles.contains(MacroRole::Expression)) { | |
if (!macroRoles.contains(MacroRole::Declaration) && | |
!ctx.LangOpts.hasFeature(Feature::CodeItemMacros)) { | |
ctx.Diags.diagnose(loc, diag::macro_experimental, "code item", | |
"CodeItemMacros"); | |
return nullptr; | |
} | |
if (macroRoles.contains(MacroRole::CodeItem) && | |
!ctx.LangOpts.hasFeature(Feature::CodeItemMacros)) { | |
ctx.Diags.diagnose(loc, diag::macro_experimental, "code item", | |
"CodeItemMacros"); | |
return nullptr; | |
} |
And yes, I just saw that you just copy-pasted this from the old implementation.
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.
Yeah I just moved this code. But let's do it in this PR. updated.
86fa585
to
a51ed72
Compare
@swift-ci Please smoke test |
'MacroExpansionDecl' and 'MacroExpansionExpr' have many common methods. Introduce a common base class 'FreestandingMacroExpansion' that holds 'MacroExpansionInfo'. Factor out common expansion logic to 'evaluateFreestandingMacro' function that resembles 'evaluateAttachedMacro'.
a51ed72
to
86d405b
Compare
@swift-ci Please smoke test |
1 similar comment
@swift-ci Please smoke test |
MacroExpansionDecl
andMacroExpansionExpr
have many common methods. Introduce a common base classFreestandingMacroExpansion
that holdsMacroExpansionInfo
.Factor out common expansion logic to
evaluateFreestandingMacro
function that resemblesevaluateAttachedMacro
.