File tree Expand file tree Collapse file tree 3 files changed +37
-2
lines changed
Sources/SwiftCompilerPlugin Expand file tree Collapse file tree 3 files changed +37
-2
lines changed Original file line number Diff line number Diff line change @@ -206,6 +206,40 @@ extension CompilerPlugin {
206
206
expanded =
207
207
peers
208
208
. map { $0. trimmedDescription }
209
+
210
+ case ( let attachedMacro as ConformanceMacro . Type , . conformance) :
211
+ guard
212
+ let declGroup = declarationNode. asProtocol ( DeclGroupSyntax . self) ,
213
+ let identified = declarationNode. asProtocol ( IdentifiedDeclSyntax . self)
214
+ else {
215
+ fatalError ( " type mismatch " )
216
+ }
217
+
218
+ // Local function to expand a conformance macro once we've opened up
219
+ // the existential.
220
+ func expandConformanceMacro< Node: DeclGroupSyntax > (
221
+ _ node: Node
222
+ ) throws -> [ ( TypeSyntax , GenericWhereClauseSyntax ? ) ] {
223
+ return try attachedMacro. expansion (
224
+ of: customAttributeNode,
225
+ providingConformancesOf: node,
226
+ in: context
227
+ )
228
+ }
229
+
230
+ let conformances = try _openExistential (
231
+ declGroup,
232
+ do: expandConformanceMacro
233
+ )
234
+
235
+ // Form a buffer of extension declarations to return to the caller.
236
+ expanded = conformances. map { typeSyntax, whereClause in
237
+ let typeName = identified. identifier. trimmedDescription
238
+ let protocolName = typeSyntax. trimmedDescription
239
+ let whereClause = whereClause? . trimmedDescription ?? " "
240
+ return " extension \( typeName) : \( protocolName) \( whereClause) {} "
241
+ }
242
+
209
243
default :
210
244
fatalError ( " \( macroDefinition) does not conform to any known attached macro protocol " )
211
245
}
Original file line number Diff line number Diff line change @@ -47,7 +47,7 @@ internal enum PluginToHostMessage: Codable {
47
47
}
48
48
49
49
/*namespace*/ internal enum PluginMessage {
50
- static var PROTOCOL_VERSION_NUMBER : Int { 1 }
50
+ static var PROTOCOL_VERSION_NUMBER : Int { 2 } // Added 'MacroRole.conformance'
51
51
52
52
struct PluginCapability : Codable {
53
53
var protocolVersion : Int
@@ -72,6 +72,7 @@ internal enum PluginToHostMessage: Codable {
72
72
case memberAttribute
73
73
case member
74
74
case peer
75
+ case conformance
75
76
}
76
77
77
78
struct SourceLocation : Codable {
Original file line number Diff line number Diff line change 7
7
// RUN: -dump-macro-expansions \
8
8
// RUN: -load-plugin-executable %examples_bin_path/ExamplePlugin#ExamplePlugin \
9
9
// RUN -module-name MyApp \
10
- // RUN: %s > %t/expansions-dump.txt 2>&1
10
+ // RUN: %s 2>&1 | tee %t/expansions-dump.txt
11
11
//
12
12
// RUN: %FileCheck %s < %t/expansions-dump.txt
13
13
You can’t perform that action at this time.
0 commit comments