@@ -47,10 +47,15 @@ distributed actor Greeter {
47
47
. init( q: " question " , a: 42 , b: 1 , c: 2.0 , d: " Lorum ipsum " )
48
48
}
49
49
50
+ distributed func echo( name: String ) -> String {
51
+ return " Echo: \( name) "
52
+ }
53
+
50
54
distributed func enumResult( ) -> E {
51
55
. bar
52
56
}
53
57
58
+
54
59
distributed func test( i: Int , s: String ) -> String {
55
60
return s
56
61
}
@@ -142,25 +147,47 @@ struct FakeInvocation: DistributedTargetInvocation {
142
147
typealias ArgumentDecoder = FakeArgumentDecoder
143
148
typealias SerializationRequirement = Codable
144
149
150
+ var arguments : [ Any ] = [ ]
151
+
145
152
mutating func recordGenericSubstitution< T> ( _ type: T . Type ) throws { }
146
- mutating func recordArgument< Argument: SerializationRequirement > ( argument: Argument ) throws { }
153
+ mutating func recordArgument< Argument: SerializationRequirement > ( argument: Argument ) throws {
154
+ arguments. append ( argument)
155
+ }
147
156
mutating func recordReturnType< R: SerializationRequirement > ( _ type: R . Type ) throws { }
148
157
mutating func recordErrorType< E: Error > ( _ type: E . Type ) throws { }
149
158
mutating func doneRecording( ) throws { }
150
159
151
160
// === Receiving / decoding -------------------------------------------------
152
161
153
162
mutating func decodeGenericSubstitutions( ) throws -> [ Any . Type ] { [ ] }
154
- func makeArgumentDecoder( ) -> FakeArgumentDecoder { . init( ) }
163
+ func makeArgumentDecoder( ) -> FakeArgumentDecoder {
164
+ . init( invocation: self )
165
+ }
155
166
mutating func decodeReturnType( ) throws -> Any . Type ? { nil }
156
167
mutating func decodeErrorType( ) throws -> Any . Type ? { nil }
157
168
158
169
struct FakeArgumentDecoder : DistributedTargetInvocationArgumentDecoder {
159
170
typealias SerializationRequirement = Codable
171
+ let invocation : FakeInvocation
172
+ var index : Int = 0
173
+
160
174
mutating func decodeNext< Argument> (
161
175
_ argumentType: Argument . Type ,
162
176
into pointer: UnsafeMutablePointer < Argument >
163
- ) throws { }
177
+ ) throws {
178
+ guard index < invocation. arguments. count else {
179
+ fatalError ( " Attempted to decode more arguments than stored! Index: \( index) , args: \( invocation. arguments) " )
180
+ }
181
+
182
+ let anyArgument = invocation. arguments [ index]
183
+ guard let argument = anyArgument as? Argument else {
184
+ fatalError ( " Cannot cast argument \( anyArgument) to expected \( Argument . self) " )
185
+ }
186
+
187
+ print ( " > argument: \( argument) " )
188
+ pointer. pointee = argument
189
+ index += 1
190
+ }
164
191
}
165
192
}
166
193
@@ -184,7 +211,9 @@ let emptyName = "$s4main7GreeterC5emptyyyFTE"
184
211
let helloName = " $s4main7GreeterC5helloSSyFTE "
185
212
let answerName = " $s4main7GreeterC6answerSiyFTE "
186
213
let largeResultName = " $s4main7GreeterC11largeResultAA11LargeStructVyFTE "
187
- let enumResult = " $s4main7GreeterC10enumResultAA1EOyFTE "
214
+ let enumResultName = " $s4main7GreeterC10enumResultAA1EOyFTE "
215
+
216
+ let echoName = " $s4main7GreeterC4echo4nameS2S_tFTE "
188
217
189
218
func test( ) async throws {
190
219
let system = FakeActorSystem ( )
@@ -200,7 +229,6 @@ func test() async throws {
200
229
invocation: & invocation,
201
230
handler: FakeResultHandler ( )
202
231
)
203
-
204
232
// CHECK: RETURN: ()
205
233
206
234
try await system. executeDistributedTarget (
@@ -209,7 +237,6 @@ func test() async throws {
209
237
invocation: & invocation,
210
238
handler: FakeResultHandler ( )
211
239
)
212
-
213
240
// CHECK: RETURN: Hello, World!
214
241
215
242
try await system. executeDistributedTarget (
@@ -218,7 +245,6 @@ func test() async throws {
218
245
invocation: & invocation,
219
246
handler: FakeResultHandler ( )
220
247
)
221
-
222
248
// CHECK: RETURN: 42
223
249
224
250
try await system. executeDistributedTarget (
@@ -227,17 +253,27 @@ func test() async throws {
227
253
invocation: & invocation,
228
254
handler: FakeResultHandler ( )
229
255
)
230
-
231
256
// CHECK: RETURN: LargeStruct(q: "question", a: 42, b: 1, c: 2.0, d: "Lorum ipsum")
232
257
233
258
try await system. executeDistributedTarget (
234
259
on: local,
235
- mangledTargetName: enumResult ,
260
+ mangledTargetName: enumResultName ,
236
261
invocation: & invocation,
237
262
handler: FakeResultHandler ( )
238
263
)
239
264
// CHECK: RETURN: bar
240
265
266
+ var echoInvocation = system. makeInvocation ( )
267
+ try echoInvocation. recordArgument ( argument: " Caplin " )
268
+ try echoInvocation. doneRecording ( )
269
+ try await system. executeDistributedTarget (
270
+ on: local,
271
+ mangledTargetName: echoName,
272
+ invocation: & echoInvocation,
273
+ handler: FakeResultHandler ( )
274
+ )
275
+ // CHECK: RETURN: Echo: Caplin
276
+
241
277
// CHECK-NEXT: done
242
278
print ( " done " )
243
279
}
0 commit comments