File tree Expand file tree Collapse file tree 3 files changed +49
-3
lines changed Expand file tree Collapse file tree 3 files changed +49
-3
lines changed Original file line number Diff line number Diff line change @@ -1081,12 +1081,13 @@ void writeProperties(llvm::json::OStream &JSON,
1081
1081
void writeConformances (llvm::json::OStream &JSON,
1082
1082
const NominalTypeDecl &NomTypeDecl) {
1083
1083
JSON.attributeArray (" conformances" , [&] {
1084
- for (auto *Protocol : NomTypeDecl.getAllProtocols ()) {
1084
+ for (auto *Conformance : NomTypeDecl.getAllConformances ()) {
1085
+ auto Proto = Conformance->getProtocol ();
1085
1086
// FIXME(noncopyable_generics): Should these be included?
1086
- if (Protocol ->getInvertibleProtocolKind ())
1087
+ if (Proto ->getInvertibleProtocolKind ())
1087
1088
continue ;
1088
1089
1089
- JSON.value (toFullyQualifiedProtocolNameString (*Protocol ));
1090
+ JSON.value (toFullyQualifiedProtocolNameString (*Proto ));
1090
1091
}
1091
1092
});
1092
1093
}
Original file line number Diff line number Diff line change
1
+ // REQUIRES: swift_swift_parser
2
+ // RUN: %empty-directory(%t)
3
+ // RUN: echo "[MyProto]" > %t/protocols.json
4
+
5
+ // RUN: %host-build-swift -swift-version 5 -emit-library -o %t/%target-library-name(MacroDefinition) -module-name=MacroDefinition %S/Inputs/Macros.swift -g -no-toolchain-stdlib-rpath
6
+
7
+ // RUN: %target-swift-frontend -typecheck -emit-const-values-path %t/ExtractFromMacroExpansion.swiftconstvalues -const-gather-protocols-file %t/protocols.json -primary-file %s -load-plugin-library %t/%target-library-name(MacroDefinition)
8
+ // RUN: cat %t/ExtractFromMacroExpansion.swiftconstvalues 2>&1 | %FileCheck %s
9
+
10
+ protocol MyProto { }
11
+ protocol MyExtraProto { }
12
+
13
+ @attached ( extension, conformances: MyProto, MyExtraProto)
14
+ macro specificExtensionMacro( ) = #externalMacro( module: " MacroDefinition " , type: " AddSpecificExtensionMacro " )
15
+
16
+ @specificExtensionMacro
17
+ struct MyStruct {
18
+ struct Inner { }
19
+ }
20
+
21
+ // CHECK: "typeName": "ExtractMacroExpandedConformances.MyStruct",
22
+ // CHECK: "mangledTypeName": "32ExtractMacroExpandedConformances8MyStructV",
23
+ // CHECK: "kind": "struct",
24
+ // CHECK: "conformances": [
25
+ // CHECK-DAG: "Swift.Sendable",
26
+ // CHECK-DAG: "Swift.BitwiseCopyable",
27
+ // CHECK-DAG: "ExtractMacroExpandedConformances.MyProto"
28
+ // CHECK-NOT: "ExtractMacroExpandedConformances.MyExtraProto"
Original file line number Diff line number Diff line change @@ -61,6 +61,23 @@ public struct AddExtensionMacro: ExtensionMacro {
61
61
}
62
62
}
63
63
64
+ public struct AddSpecificExtensionMacro : ExtensionMacro {
65
+ public static func expansion(
66
+ of node: AttributeSyntax ,
67
+ attachedTo declaration: some DeclGroupSyntax ,
68
+ providingExtensionsOf type: some TypeSyntaxProtocol ,
69
+ conformingTo protocols: [ TypeSyntax ] ,
70
+ in context: some MacroExpansionContext
71
+ ) throws -> [ ExtensionDeclSyntax ] {
72
+ var extensions = [ ExtensionDeclSyntax] ( )
73
+ let protocolNames = Set ( protocols. compactMap { $0. as ( IdentifierTypeSyntax . self) ? . name. text } )
74
+ if protocolNames. contains ( " MyProto " ) {
75
+ extensions. append ( try ExtensionDeclSyntax ( " extension \( type. trimmed) : MyProto " ) { } )
76
+ }
77
+ return extensions
78
+ }
79
+ }
80
+
64
81
public struct AddPeerVarMacro : PeerMacro {
65
82
public static func expansion(
66
83
of node: AttributeSyntax ,
You can’t perform that action at this time.
0 commit comments