-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[Macros] Freestanding declaration macros #62934
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] Freestanding declaration macros #62934
Conversation
6105347
to
d1f28a2
Compare
@swift-ci please test |
d1f28a2
to
a5b99bf
Compare
@swift-ci please test linux |
@swift-ci please test macos |
@swift-ci please clean test windows |
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.
A bunch of questions, but this is pretty awesome. Thank you!
lib/Sema/TypeCheckDeclPrimary.cpp
Outdated
llvm_unreachable("FIXME: macro expansion decl not handled in DeclChecker"); | ||
auto expanded = evaluateOrDefault( | ||
Ctx.evaluator, ExpandMacroExpansionDeclRequest{MED}, {}); | ||
// FIXME: Handle this in name lookup instead. |
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.
Definitely agreed that this should be handled in name lookup. This won't work across multiple source files.
// Call-like macros need to be resolved. | ||
else { | ||
using namespace constraints; | ||
ConstraintSystem cs(dc, ConstraintSystemOptions()); |
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 looks a whole lot like CSGen for MacroExpansionExpr
. Can we unify the implementations?
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 think we can pull it out to TypeCheckMacros.h
. I can do it in a separate patch.
@@ -498,3 +498,165 @@ Expr *swift::expandMacroExpr( | |||
"Type checking changed the result type?"); | |||
return expandedExpr; | |||
} | |||
|
|||
/// Expands the given macro expansion declaration and type-check the result. | |||
bool swift::expandFreestandingDeclarationMacro( |
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.
Hmm, lots of duplication with the expandMacro
for expressions. Can we unify them somehow?
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.
We can definitely pull out the buffer creation, source info creation and the call to ASTGen in a follow-up patch.
a5b99bf
to
dc9260d
Compare
@swift-ci please smoke test |
dc9260d
to
a6788e8
Compare
@swift-ci please smoke test and merge |
Add support for freestanding declaration macros. - Parse `@declaration` attribute. - Type check and expand `MacroExpansionDecl`. Known issues: - Generic macros are not yet handled. - Expansion does not work when the parent decl context is `BraceStmt`. Need to parse freestanding declaration macro expansions in `BraceStmt` as `MacroExpansionDecl`, and add expanded decls to name lookup.
a6788e8
to
f17b7c4
Compare
@swift-ci please smoke test and merge |
|
||
DeclAttribute('declaration', 'Declaration', | ||
OnMacro, AllowMultipleAttributes, | ||
ABIStableToAdd, ABIStableToRemove, APIStableToAdd, APIBreakingToRemove, # noqa: E501 |
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.
TIL what # noqa: E501
is for... Why doesn't it run on linux!?
Sorry for the CI breakage. I didn't know "test and merge" would bypass Windows CI. @shahmishal @compnerd |
Add support for freestanding declaration macros.
@declaration
attribute.MacroExpansionDecl
.Known issues:
BraceStmt
. Need to parse freestanding declaration macro expansions inBraceStmt
asMacroExpansionDecl
, and add expanded decls to name lookup.