Skip to content

Commit aae180e

Browse files
authored
Merge pull request #67424 from hborla/5.9-enable-extension-macros
[5.9][Macros] Remove the `ExtensionMacros` experimental feature flag.
2 parents 8db2e00 + 62819b1 commit aae180e

14 files changed

+31
-24
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7209,6 +7209,9 @@ ERROR(extension_macro_invalid_conformance,none,
72097209
ERROR(macro_attached_to_invalid_decl,none,
72107210
"'%0' macro cannot be attached to %1",
72117211
(StringRef, DescriptiveDeclKind))
7212+
ERROR(conformance_macro,none,
7213+
"conformance macros are replaced by extension macros",
7214+
())
72127215

72137216
ERROR(macro_resolve_circular_reference, none,
72147217
"circular reference resolving %select{freestanding|attached}0 macro %1",

include/swift/Basic/Features.def

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@ EXPERIMENTAL_FEATURE(CodeItemMacros, false)
122122
EXPERIMENTAL_FEATURE(TupleConformances, false)
123123
EXPERIMENTAL_FEATURE(InitAccessors, false)
124124

125-
EXPERIMENTAL_FEATURE(ExtensionMacros, true)
126125
SUPPRESSIBLE_LANGUAGE_FEATURE(ExtensionMacroAttr, 0, "@attached(extension)", true)
127126

128127
// FIXME: MoveOnlyClasses is not intended to be in production,

lib/AST/Decl.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10574,11 +10574,10 @@ bool swift::isMacroSupported(MacroRole role, ASTContext &ctx) {
1057410574
case MacroRole::Member:
1057510575
case MacroRole::Peer:
1057610576
case MacroRole::Conformance:
10577+
case MacroRole::Extension:
1057710578
return true;
1057810579
case MacroRole::CodeItem:
1057910580
return ctx.LangOpts.hasFeature(Feature::CodeItemMacros);
10580-
case MacroRole::Extension:
10581-
return ctx.LangOpts.hasFeature(Feature::ExtensionMacros);
1058210581
}
1058310582
}
1058410583

lib/Sema/TypeCheckAttr.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7122,9 +7122,9 @@ void AttributeChecker::visitMacroRoleAttr(MacroRoleAttr *attr) {
71227122
case MacroRole::Peer:
71237123
break;
71247124
case MacroRole::Conformance:
7125-
if (!attr->getNames().empty())
7126-
diagnoseAndRemoveAttr(attr, diag::macro_cannot_introduce_names,
7127-
getMacroRoleString(attr->getMacroRole()));
7125+
diagnoseAndRemoveAttr(attr, diag::conformance_macro)
7126+
.fixItReplace(attr->getRange(),
7127+
"@attached(extension, conformances: <#Protocol#>)");
71287128
break;
71297129
case MacroRole::Extension:
71307130
break;

test/IDE/complete_macro_attribute.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@ macro FreestandingMacro
1212
@attached(#^ATTACHED_ROLE^#)
1313
macro AttachedMacro
1414

15-
// ATTACHED_ROLE: Begin completions, 5 items
15+
// ATTACHED_ROLE: Begin completions, 6 items
1616
// ATTACHED_ROLE-DAG: Keyword/None: accessor; name=accessor
1717
// ATTACHED_ROLE-DAG: Keyword/None: memberAttribute; name=memberAttribute
1818
// ATTACHED_ROLE-DAG: Keyword/None: member; name=member
1919
// ATTACHED_ROLE-DAG: Keyword/None: peer; name=peer
2020
// ATTACHED_ROLE-DAG: Keyword/None: conformance; name=conformance
21+
// ATTACHED_ROLE-DAG: Keyword/None: extension; name=extension
2122

2223
@freestanding(declaration, #^NAMES_POSITION^#)
2324
macro FreestandingDeclarationMacro

test/IDE/complete_macros.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public macro AttachedMemberAttributeMacro()
5252
@attached(peer)
5353
public macro AttachedPeerMacro()
5454

55-
@attached(conformance)
55+
@attached(extension)
5656
public macro AttachedConformanceMacro()
5757

5858
@freestanding(expression)
@@ -61,7 +61,7 @@ public macro AttachedConformanceMacro()
6161
@attached(member)
6262
@attached(memberAttribute)
6363
@attached(peer)
64-
@attached(conformance)
64+
@attached(extension)
6565
public macro EverythingMacro()
6666

6767
//--- MacroUses.swift

test/IDE/complete_optionset.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func foo() {
1717
}
1818

1919
@attached(member, names: named(RawValue), named(rawValue), named(`init`), arbitrary)
20-
@attached(conformance)
20+
@attached(extension, conformances: OptionSet)
2121
public macro OptionSet<RawType>() =
2222
#externalMacro(module: "SwiftMacros", type: "OptionSetMacro")
2323

test/Index/index_macros.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ macro freestandingDecl<T>(arg: T) = #externalMacro(module: "IndexMacros", type:
2626
macro Accessor() = #externalMacro(module: "IndexMacros", type: "SomeAccessorMacro")
2727
// CHECK: [[@LINE-1]]:7 | macro/Swift | Accessor() | [[ACCESSOR_USR:.*]] | Def
2828

29-
@attached(conformance)
29+
@attached(extension, conformances: TestProto)
3030
macro Conformance() = #externalMacro(module: "IndexMacros", type: "SomeConformanceMacro")
3131
// CHECK: [[@LINE-1]]:7 | macro/Swift | Conformance() | [[CONFORMANCE_USR:.*]] | Def
3232

test/Macros/macro_expand_conformances.swift

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,15 @@
1414
// RUN: %target-codesign %t/main
1515
// RUN: %target-run %t/main | %FileCheck %s
1616

17-
@attached(conformance)
17+
#if TEST_DIAGNOSTICS
18+
@attached(conformance) // expected-error{{conformance macros are replaced by extension macros}}
19+
macro InvalidEquatable() = #externalMacro(module: "MacroDefinition", type: "EquatableMacro")
20+
#endif
21+
22+
@attached(extension, conformances: Equatable)
1823
macro Equatable() = #externalMacro(module: "MacroDefinition", type: "EquatableMacro")
1924

20-
@attached(conformance)
25+
@attached(extension, conformances: Hashable)
2126
macro Hashable() = #externalMacro(module: "MacroDefinition", type: "HashableMacro")
2227

2328
#if MODULE_EXPORTING_TYPE
@@ -52,7 +57,7 @@ enum E {
5257
@Equatable struct Nested {}
5358
}
5459

55-
// CHECK-DUMP: @__swiftmacro_25macro_expand_conformances1S9EquatablefMc_.swift
60+
// CHECK-DUMP: @__swiftmacro_25macro_expand_conformances1S9EquatablefMe_.swift
5661
// CHECK-DUMP: extension S: Equatable {
5762
// CHECK-DUMP: }
5863

@@ -77,7 +82,7 @@ requireHashable(PublicEquatable())
7782
//expected-error@-1{{global function 'requireHashable' requires that 'PublicEquatable' conform to 'Hashable'}}
7883
#endif
7984

80-
@attached(conformance)
85+
@attached(extension, conformances: P)
8186
@attached(member, names: named(requirement))
8287
macro DelegatedConformance() = #externalMacro(module: "MacroDefinition", type: "DelegatedConformanceMacro")
8388

@@ -94,7 +99,7 @@ struct Wrapped: P {
9499
@DelegatedConformance
95100
struct Generic<Element> {}
96101

97-
// CHECK-DUMP: @__swiftmacro_25macro_expand_conformances7Generic20DelegatedConformancefMc_.swift
102+
// CHECK-DUMP: @__swiftmacro_25macro_expand_conformances7Generic20DelegatedConformancefMe_.swift
98103
// CHECK-DUMP: extension Generic: P where Element: P {
99104
// CHECK-DUMP: }
100105

test/Macros/option_set.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import Swift
66

77
@attached(member, names: named(RawValue), named(rawValue), named(`init`), arbitrary)
8-
@attached(conformance)
8+
@attached(extension, conformances: OptionSet)
99
public macro OptionSet<RawType>() =
1010
#externalMacro(module: "SwiftMacros", type: "OptionSetMacro")
1111

test/Macros/top_level_freestanding.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ macro Empty<T>(_ closure: () -> T) = #externalMacro(module: "MacroDefinition", t
117117
S(a: 10, b: 10)
118118
}
119119

120-
@attached(conformance)
120+
@attached(extension, conformances: Initializable)
121121
@attached(member, names: named(init))
122122
macro Initializable() = #externalMacro(module: "MacroDefinition", type: "InitializableMacro")
123123

test/ModuleInterface/macros.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@
5050
@attached(accessor, names: named(init)) public macro AccessorInitFunc() = #externalMacro(module: "SomeModule", type: "AccessorInitFuncMacro")
5151

5252
// CHECK: #if compiler(>=5.3) && $Macros && $AttachedMacros
53-
// CHECK: @attached(extension, conformances: Swift.Sendable) @attached(conformance) public macro AddSendable() = #externalMacro(module: "SomeModule", type: "SendableExtensionMacro")
53+
// CHECK: @attached(extension, conformances: Swift.Sendable) @attached(member) public macro AddSendable() = #externalMacro(module: "SomeModule", type: "SendableExtensionMacro")
5454
// CHECK-NEXT: #else
55-
// CHECK: @attached(conformance) public macro AddSendable() = #externalMacro(module: "SomeModule", type: "SendableExtensionMacro")
55+
// CHECK: @attached(member) public macro AddSendable() = #externalMacro(module: "SomeModule", type: "SendableExtensionMacro")
5656
// CHECK-NEXT: #endif
57-
@attached(extension, conformances: Sendable) @attached(conformance) public macro AddSendable() = #externalMacro(module: "SomeModule", type: "SendableExtensionMacro")
57+
@attached(extension, conformances: Sendable) @attached(member) public macro AddSendable() = #externalMacro(module: "SomeModule", type: "SendableExtensionMacro")
5858

5959
// CHECK-NOT: internalStringify
6060
@freestanding(expression) macro internalStringify<T>(_ value: T) -> (T, String) = #externalMacro(module: "SomeModule", type: "StringifyMacro")

test/SourceKit/Macros/macro_basic.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ struct S3 {
4545
}
4646
}
4747

48-
@attached(conformance)
48+
@attached(extension, conformances: Hashable)
4949
macro Hashable() = #externalMacro(module: "MacroDefinition", type: "HashableMacro")
5050

5151
@Hashable
@@ -263,7 +263,7 @@ macro anonymousTypes(_: () -> String) = #externalMacro(module: "MacroDefinition"
263263
//##-- Expansion on a conformance macro.
264264
// RUN: %sourcekitd-test -req=refactoring.expand.macro -pos=51:5 %s -- ${COMPILER_ARGS[@]} | %FileCheck -check-prefix=CONFORMANCE_EXPAND %s
265265
// CONFORMANCE_EXPAND: source.edit.kind.active:
266-
// CONFORMANCE_EXPAND-NEXT: 52:14-52:14 (@__swiftmacro_9MacroUser2S48HashablefMc_.swift) "extension S4: Hashable {
266+
// CONFORMANCE_EXPAND-NEXT: 52:14-52:14 (@__swiftmacro_9MacroUser2S48HashablefMe_.swift) "extension S4: Hashable {
267267
// CONFORMANCE_EXPAND-NEXT: }"
268268
// CONFORMANCE_EXPAND-NEXT: source.edit.kind.active:
269269
// CONFORMANCE_EXPAND-NEXT: 51:1-51:10 ""

test/SourceKit/Macros/macro_option_set.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func test(opts: ShippingOptions) {
1717
}
1818

1919
@attached(member, names: named(RawValue), named(rawValue), named(`init`), arbitrary)
20-
@attached(conformance)
20+
@attached(extension, conformances: OptionSet)
2121
public macro OptionSet<RawType>() =
2222
#externalMacro(module: "SwiftMacros", type: "OptionSetMacro")
2323

0 commit comments

Comments
 (0)