-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[Macros] Generalize conformance
macros as extension
macros
#66967
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
Changes from all commits
725374e
d3e2562
095542a
c867c7c
c3bdae6
81a1f64
43e2026
7e85ebd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1371,6 +1371,13 @@ bool DeclAttribute::printImpl(ASTPrinter &Printer, const PrintOptions &Options, | |
|
||
case DAK_MacroRole: { | ||
auto Attr = cast<MacroRoleAttr>(this); | ||
|
||
// Suppress @attached(extension) if needed. | ||
if (!Options.PrintExtensionMacroAttributes && | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fantastic, thank you! |
||
Attr->getMacroRole() == MacroRole::Extension) { | ||
break; | ||
} | ||
|
||
switch (Attr->getMacroSyntax()) { | ||
case MacroSyntax::Freestanding: | ||
Printer.printAttrName("@freestanding"); | ||
|
@@ -2491,23 +2498,32 @@ MacroRoleAttr::MacroRoleAttr(SourceLoc atLoc, SourceRange range, | |
MacroSyntax syntax, SourceLoc lParenLoc, | ||
MacroRole role, | ||
ArrayRef<MacroIntroducedDeclName> names, | ||
ArrayRef<TypeExpr *> conformances, | ||
SourceLoc rParenLoc, bool implicit) | ||
: DeclAttribute(DAK_MacroRole, atLoc, range, implicit), | ||
syntax(syntax), role(role), numNames(names.size()), lParenLoc(lParenLoc), | ||
syntax(syntax), role(role), numNames(names.size()), | ||
numConformances(conformances.size()), lParenLoc(lParenLoc), | ||
rParenLoc(rParenLoc) { | ||
auto *trailingNamesBuffer = getTrailingObjects<MacroIntroducedDeclName>(); | ||
std::uninitialized_copy(names.begin(), names.end(), trailingNamesBuffer); | ||
|
||
auto *trailingConformancesBuffer = getTrailingObjects<TypeExpr *>(); | ||
std::uninitialized_copy(conformances.begin(), conformances.end(), | ||
trailingConformancesBuffer); | ||
} | ||
|
||
MacroRoleAttr * | ||
MacroRoleAttr::create(ASTContext &ctx, SourceLoc atLoc, SourceRange range, | ||
MacroSyntax syntax, SourceLoc lParenLoc, MacroRole role, | ||
ArrayRef<MacroIntroducedDeclName> names, | ||
ArrayRef<TypeExpr *> conformances, | ||
SourceLoc rParenLoc, bool implicit) { | ||
unsigned size = totalSizeToAlloc<MacroIntroducedDeclName>(names.size()); | ||
unsigned size = | ||
totalSizeToAlloc<MacroIntroducedDeclName, TypeExpr *>( | ||
names.size(), conformances.size()); | ||
auto *mem = ctx.Allocate(size, alignof(MacroRoleAttr)); | ||
return new (mem) MacroRoleAttr(atLoc, range, syntax, lParenLoc, role, names, | ||
rParenLoc, implicit); | ||
conformances, rParenLoc, implicit); | ||
} | ||
|
||
ArrayRef<MacroIntroducedDeclName> MacroRoleAttr::getNames() const { | ||
|
@@ -2517,6 +2533,13 @@ ArrayRef<MacroIntroducedDeclName> MacroRoleAttr::getNames() const { | |
}; | ||
} | ||
|
||
ArrayRef<TypeExpr *> MacroRoleAttr::getConformances() const { | ||
return { | ||
getTrailingObjects<TypeExpr *>(), | ||
numConformances | ||
}; | ||
} | ||
|
||
bool MacroRoleAttr::hasNameKind(MacroIntroducedDeclNameKind kind) const { | ||
return llvm::find_if(getNames(), [kind](MacroIntroducedDeclName name) { | ||
return name.getKind() == kind; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -286,6 +286,10 @@ void ConformanceLookupTable::updateLookupTable(NominalTypeDecl *nominal, | |
ASTContext &ctx = nominal->getASTContext(); | ||
(void)evaluateOrDefault( | ||
ctx.evaluator, ExpandConformanceMacros{nominal}, { }); | ||
|
||
// Expand extension macros. | ||
(void)evaluateOrDefault( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This expansion is very "eager", in that we're expanding all extension macros even if they don't provide any conformances. I think it'll be okay for now. |
||
ctx.evaluator, ExpandExtensionMacros{nominal}, { }); | ||
}, | ||
[&](ExtensionDecl *ext, | ||
ArrayRef<ConformanceConstructionInfo> protos) { | ||
|
Uh oh!
There was an error while loading. Please reload this page.