Skip to content

Commit 24d39f6

Browse files
authored
Merge pull request #63257 from hborla/attached-macro-names
2 parents be00ae8 + 32a0705 commit 24d39f6

20 files changed

+35
-36
lines changed

include/swift/AST/MacroDeclaration.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ enum class MacroRole: uint32_t {
4848
MemberAttribute = 0x08,
4949
/// An attached macro that generates synthesized members
5050
/// inside the declaration.
51-
SynthesizedMembers = 0x10,
51+
Member = 0x10,
5252
};
5353

5454
/// The contexts in which a particular macro declaration can be used.

include/swift/Basic/SourceManager.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ class GeneratedSourceInfo {
4444
/// The expansion of a member attribute attached macro.
4545
MemberAttributeMacroExpansion,
4646

47-
/// The expansion of a synthesized member macro.
48-
SynthesizedMemberMacroExpansion,
47+
/// The expansion of an attached member macro.
48+
MemberMacroExpansion,
4949

5050
/// A new function body that is replacing an existing function body.
5151
ReplacedFunctionBody,

lib/AST/ASTMangler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3738,7 +3738,7 @@ void ASTMangler::appendMacroExpansionContext(
37383738

37393739
case GeneratedSourceInfo::AccessorMacroExpansion:
37403740
case GeneratedSourceInfo::MemberAttributeMacroExpansion:
3741-
case GeneratedSourceInfo::SynthesizedMemberMacroExpansion:
3741+
case GeneratedSourceInfo::MemberMacroExpansion:
37423742
case GeneratedSourceInfo::PrettyPrinted:
37433743
case GeneratedSourceInfo::ReplacedFunctionBody:
37443744
return appendContext(origDC, StringRef());

lib/AST/ASTScopeCreation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ ASTSourceFileScope::ASTSourceFileScope(SourceFile *SF,
260260
case MacroRole::MemberAttribute:
261261
parentLoc = expansion.getStartLoc();
262262
break;
263-
case MacroRole::SynthesizedMembers: {
263+
case MacroRole::Member: {
264264
// For synthesized member macros, take the end loc of the
265265
// enclosing declaration (before the closing brace), because
266266
// the macro expansion is inside this scope.

lib/AST/Decl.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9722,10 +9722,10 @@ StringRef swift::getMacroRoleString(MacroRole role) {
97229722
return "accessor";
97239723

97249724
case MacroRole::MemberAttribute:
9725-
return "memberAttributes";
9725+
return "memberAttribute";
97269726

9727-
case MacroRole::SynthesizedMembers:
9728-
return "synthesizedMembers";
9727+
case MacroRole::Member:
9728+
return "member";
97299729
}
97309730
}
97319731

@@ -9771,7 +9771,7 @@ static MacroRoles freestandingMacroRoles =
97719771
static MacroRoles attachedMacroRoles = (MacroRoles() |
97729772
MacroRole::Accessor |
97739773
MacroRole::MemberAttribute |
9774-
MacroRole::SynthesizedMembers);
9774+
MacroRole::Member);
97759775

97769776
bool swift::isFreestandingMacro(MacroRoles contexts) {
97779777
return bool(contexts & freestandingMacroRoles);
@@ -9924,7 +9924,7 @@ MacroDiscriminatorContext MacroDiscriminatorContext::getParentOf(
99249924

99259925
case GeneratedSourceInfo::AccessorMacroExpansion:
99269926
case GeneratedSourceInfo::MemberAttributeMacroExpansion:
9927-
case GeneratedSourceInfo::SynthesizedMemberMacroExpansion:
9927+
case GeneratedSourceInfo::MemberMacroExpansion:
99289928
case GeneratedSourceInfo::PrettyPrinted:
99299929
case GeneratedSourceInfo::ReplacedFunctionBody:
99309930
return origDC;

lib/AST/DeclContext.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -986,7 +986,7 @@ void IterableDeclContext::addMemberSilently(Decl *member, Decl *hint,
986986

987987
// Synthesized member macros can add new members in a macro expansion buffer.
988988
auto *memberSourceFile = member->getInnermostDeclContext()->getParentSourceFile();
989-
if (memberSourceFile->getFulfilledMacroRole() == MacroRole::SynthesizedMembers)
989+
if (memberSourceFile->getFulfilledMacroRole() == MacroRole::Member)
990990
return;
991991

992992
llvm::errs() << "Source ranges out of order in addMember():\n";

lib/AST/DiagnosticEngine.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1315,7 +1315,7 @@ std::vector<Diagnostic> DiagnosticEngine::getGeneratedSourceBufferNotes(
13151315
case GeneratedSourceInfo::FreestandingDeclMacroExpansion:
13161316
case GeneratedSourceInfo::AccessorMacroExpansion:
13171317
case GeneratedSourceInfo::MemberAttributeMacroExpansion:
1318-
case GeneratedSourceInfo::SynthesizedMemberMacroExpansion: {
1318+
case GeneratedSourceInfo::MemberMacroExpansion: {
13191319
SourceRange origRange = expansionNode.getSourceRange();
13201320
DeclName macroName;
13211321
if (auto customAttr = generatedInfo->attachedMacroCustomAttr) {

lib/AST/Module.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -915,8 +915,8 @@ Optional<MacroRole> SourceFile::getFulfilledMacroRole() const {
915915
case GeneratedSourceInfo::MemberAttributeMacroExpansion:
916916
return MacroRole::MemberAttribute;
917917

918-
case GeneratedSourceInfo::SynthesizedMemberMacroExpansion:
919-
return MacroRole::SynthesizedMembers;
918+
case GeneratedSourceInfo::MemberMacroExpansion:
919+
return MacroRole::Member;
920920

921921
case GeneratedSourceInfo::ReplacedFunctionBody:
922922
case GeneratedSourceInfo::PrettyPrinted:

lib/ASTGen/Sources/ASTGen/Macros.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ enum MacroRole: UInt8 {
3636
case FreestandingDeclaration = 0x02
3737
case Accessor = 0x04
3838
case MemberAttribute = 0x08
39-
case SynthesizedMembers = 0x10
39+
case Member = 0x10
4040
}
4141

4242
/// Resolve a reference to type metadata into a macro, if posible.
@@ -383,7 +383,7 @@ func expandAttachedMacro(
383383
$0.trimmedDescription
384384
}.joined(separator: " ")
385385

386-
case (let attachedMacro as MemberMacro.Type, .SynthesizedMembers):
386+
case (let attachedMacro as MemberMacro.Type, .Member):
387387
let members = try attachedMacro.expansion(
388388
of: customAttrNode,
389389
attachedTo: declarationNode,

lib/Basic/SourceLoc.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ void SourceManager::setGeneratedSourceInfo(
321321
case GeneratedSourceInfo::FreestandingDeclMacroExpansion:
322322
case GeneratedSourceInfo::AccessorMacroExpansion:
323323
case GeneratedSourceInfo::MemberAttributeMacroExpansion:
324-
case GeneratedSourceInfo::SynthesizedMemberMacroExpansion:
324+
case GeneratedSourceInfo::MemberMacroExpansion:
325325
case GeneratedSourceInfo::PrettyPrinted:
326326
break;
327327

lib/Parse/ParseDecl.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2192,8 +2192,8 @@ static Optional<MacroRole> getMacroRole(
21922192
.Case("declaration", MacroRole::Declaration)
21932193
.Case("expression", MacroRole::Expression)
21942194
.Case("accessor", MacroRole::Accessor)
2195-
.Case("memberAttributes", MacroRole::MemberAttribute)
2196-
.Case("synthesizedMembers", MacroRole::SynthesizedMembers)
2195+
.Case("memberAttribute", MacroRole::MemberAttribute)
2196+
.Case("member", MacroRole::Member)
21972197
.Default(None);
21982198

21992199
if (!role) {

lib/Parse/ParseRequests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ SourceFileParsingResult ParseSourceFileRequest::evaluate(Evaluator &evaluator,
174174
switch (generatedInfo->kind) {
175175
case GeneratedSourceInfo::FreestandingDeclMacroExpansion:
176176
case GeneratedSourceInfo::ExpressionMacroExpansion:
177-
case GeneratedSourceInfo::SynthesizedMemberMacroExpansion:
177+
case GeneratedSourceInfo::MemberMacroExpansion:
178178
case GeneratedSourceInfo::ReplacedFunctionBody:
179179
case GeneratedSourceInfo::PrettyPrinted: {
180180
parser.parseTopLevelItems(items);

lib/Sema/TypeCheckMacros.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -343,9 +343,9 @@ bool ExpandMemberAttributeMacros::evaluate(Evaluator &evaluator,
343343
bool ExpandSynthesizedMemberMacroRequest::evaluate(Evaluator &evaluator,
344344
Decl *decl) const {
345345
bool synthesizedMembers = false;
346-
decl->forEachAttachedMacro(MacroRole::SynthesizedMembers,
346+
decl->forEachAttachedMacro(MacroRole::Member,
347347
[&](CustomAttr *attr, MacroDecl *macro) {
348-
synthesizedMembers |= expandSynthesizedMembers(attr, macro, decl);
348+
synthesizedMembers |= expandMembers(attr, macro, decl);
349349
});
350350

351351
return synthesizedMembers;
@@ -1070,8 +1070,7 @@ bool swift::expandAttributes(CustomAttr *attr, MacroDecl *macro, Decl *member) {
10701070
return addedAttributes;
10711071
}
10721072

1073-
bool swift::expandSynthesizedMembers(CustomAttr *attr, MacroDecl *macro,
1074-
Decl *decl) {
1073+
bool swift::expandMembers(CustomAttr *attr, MacroDecl *macro, Decl *decl) {
10751074
auto *dc = decl->getInnermostDeclContext();
10761075
ASTContext &ctx = dc->getASTContext();
10771076
SourceManager &sourceMgr = ctx.SourceMgr;
@@ -1090,8 +1089,8 @@ bool swift::expandSynthesizedMembers(CustomAttr *attr, MacroDecl *macro,
10901089
// Evaluate the macro.
10911090
NullTerminatedStringRef evaluatedSource;
10921091

1093-
if (isFromExpansionOfMacro(attrSourceFile, macro, MacroRole::SynthesizedMembers) ||
1094-
isFromExpansionOfMacro(declSourceFile, macro, MacroRole::SynthesizedMembers)) {
1092+
if (isFromExpansionOfMacro(attrSourceFile, macro, MacroRole::Member) ||
1093+
isFromExpansionOfMacro(declSourceFile, macro, MacroRole::Member)) {
10951094
decl->diagnose(diag::macro_recursive, macro->getName());
10961095
return false;
10971096
}
@@ -1152,7 +1151,7 @@ bool swift::expandSynthesizedMembers(CustomAttr *attr, MacroDecl *macro,
11521151
swift_ASTGen_expandAttachedMacro(
11531152
&ctx.Diags,
11541153
externalDef.opaqueHandle,
1155-
static_cast<uint32_t>(MacroRole::SynthesizedMembers),
1154+
static_cast<uint32_t>(MacroRole::Member),
11561155
astGenAttrSourceFile, attr->AtLoc.getOpaquePointerValue(),
11571156
astGenDeclSourceFile, decl->getStartLoc().getOpaquePointerValue(),
11581157
/*parentDeclSourceFile*/nullptr, /*parentDeclLoc*/nullptr,
@@ -1207,7 +1206,7 @@ bool swift::expandSynthesizedMembers(CustomAttr *attr, MacroDecl *macro,
12071206
unsigned macroBufferID = sourceMgr.addNewSourceBuffer(std::move(macroBuffer));
12081207
auto macroBufferRange = sourceMgr.getRangeForBuffer(macroBufferID);
12091208
GeneratedSourceInfo sourceInfo{
1210-
GeneratedSourceInfo::SynthesizedMemberMacroExpansion,
1209+
GeneratedSourceInfo::MemberMacroExpansion,
12111210
decl->getEndLoc(),
12121211
SourceRange(macroBufferRange.getStart(), macroBufferRange.getEnd()),
12131212
ASTNode(decl).getOpaqueValue(),

lib/Sema/TypeCheckMacros.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ bool expandAttributes(CustomAttr *attr, MacroDecl *macro, Decl *member);
6262
///
6363
/// Returns \c true if the macro added new synthesized members, \c false
6464
/// otherwise.
65-
bool expandSynthesizedMembers(CustomAttr *attr, MacroDecl *macro, Decl *decl);
65+
bool expandMembers(CustomAttr *attr, MacroDecl *macro, Decl *decl);
6666

6767
} // end namespace swift
6868

lib/Serialization/ModuleFormat.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,7 @@ enum class MacroRole : uint8_t {
613613
Declaration,
614614
Accessor,
615615
MemberAttribute,
616-
SynthesizedMembers,
616+
Member,
617617
};
618618
using MacroRoleField = BCFixed<3>;
619619

lib/Serialization/Serialization.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2227,7 +2227,7 @@ static uint8_t getRawStableMacroRole(swift::MacroRole context) {
22272227
CASE(Declaration)
22282228
CASE(Accessor)
22292229
CASE(MemberAttribute)
2230-
CASE(SynthesizedMembers)
2230+
CASE(Member)
22312231
}
22322232
#undef CASE
22332233
llvm_unreachable("bad result declaration macro kind");

test/Macros/composed_macro.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
// FIXME: Swift parser is not enabled on Linux CI yet.
1010
// REQUIRES: OS=macosx
1111

12-
@attached(memberAttributes)
13-
@attached(synthesizedMembers)
12+
@attached(memberAttribute)
13+
@attached(member)
1414
macro myTypeWrapper() = #externalMacro(module: "MacroDefinition", type: "TypeWrapperMacro")
1515
@attached(accessor) macro accessViaStorage() = #externalMacro(module: "MacroDefinition", type: "AccessViaStorageMacro")
1616

test/Macros/macro_expand_attributes.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// FIXME: Swift parser is not enabled on Linux CI yet.
1010
// REQUIRES: OS=macosx
1111

12-
@attached(memberAttributes) macro wrapAllProperties() = #externalMacro(module: "MacroDefinition", type: "WrapAllProperties")
12+
@attached(memberAttribute) macro wrapAllProperties() = #externalMacro(module: "MacroDefinition", type: "WrapAllProperties")
1313

1414
@propertyWrapper
1515
struct Wrapper<T> {

test/Macros/macro_expand_synthesized_members.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// FIXME: Swift parser is not enabled on Linux CI yet.
1010
// REQUIRES: OS=macosx
1111

12-
@attached(synthesizedMembers) macro addMembers() = #externalMacro(module: "MacroDefinition", type: "AddMembers")
12+
@attached(member) macro addMembers() = #externalMacro(module: "MacroDefinition", type: "AddMembers")
1313

1414
@addMembers
1515
struct S {

test/Serialization/Inputs/def_macros.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
@attached(accessor) public macro myWrapper() = #externalMacro(module: "MacroDefinition", type: "MyWrapperMacro")
66

7-
@attached(memberAttributes) public macro wrapAllProperties() = #externalMacro(module: "MacroDefinition", type: "WrapAllProperties")
7+
@attached(memberAttribute) public macro wrapAllProperties() = #externalMacro(module: "MacroDefinition", type: "WrapAllProperties")
88

99
// Make sure that macro custom attributes are not serialized.
1010
@wrapAllProperties

0 commit comments

Comments
 (0)