@@ -172,23 +172,18 @@ extension DistributedActorSystem {
172
172
/// latency sensitive-use-cases.
173
173
public func executeDistributedTarget< Act, ResultHandler> (
174
174
on actor : Act ,
175
- mangledTargetName : String ,
175
+ target : RemoteCallTarget ,
176
176
invocationDecoder: inout InvocationDecoder ,
177
177
handler: ResultHandler
178
178
) async throws where Act: DistributedActor ,
179
179
// Act.ID == ActorID, // FIXME(distributed): can we bring this back?
180
180
ResultHandler: DistributedTargetInvocationResultHandler {
181
- // NOTE: this implementation is not the most efficient, nor final, version of this func
182
- // we end up demangling the name multiple times, perform more heap allocations than
183
- // we truly need to etc. We'll eventually move this implementation to a specialized one
184
- // avoiding these issues.
185
- guard mangledTargetName. count > 0 && mangledTargetName. first == " $ " else {
181
+ // Get the expected parameter count of the func
182
+ guard let targetName = target. identifier else {
186
183
throw ExecuteDistributedTargetError (
187
- message: " Illegal mangledTargetName detected, must start with '$' " )
184
+ message: " Unable to extract target identifier from remote call target: \( target ) " )
188
185
}
189
-
190
- // Get the expected parameter count of the func
191
- let nameUTF8 = Array ( mangledTargetName. utf8)
186
+ let nameUTF8 = Array ( targetName. utf8)
192
187
193
188
// Gen the generic environment (if any) associated with the target.
194
189
let genericEnv = nameUTF8. withUnsafeBufferPointer { nameUTF8 in
@@ -207,7 +202,9 @@ extension DistributedActorSystem {
207
202
208
203
if let genericEnv = genericEnv {
209
204
let subs = try invocationDecoder. decodeGenericSubstitutions ( )
210
-
205
+ for item in subs {
206
+ print ( " SUB: \( item) " )
207
+ }
211
208
if subs. isEmpty {
212
209
throw ExecuteDistributedTargetError (
213
210
message: " Cannot call generic method without generic argument substitutions " )
@@ -224,7 +221,7 @@ extension DistributedActorSystem {
224
221
genericArguments: substitutionsBuffer!)
225
222
if numWitnessTables < 0 {
226
223
throw ExecuteDistributedTargetError (
227
- message: " Generic substitutions \( subs) do not satisfy generic requirements of \( mangledTargetName ) " )
224
+ message: " Generic substitutions \( subs) do not satisfy generic requirements of \( target ) ( \( targetName ) ) " )
228
225
}
229
226
}
230
227
@@ -237,7 +234,7 @@ extension DistributedActorSystem {
237
234
message: """
238
235
Failed to decode distributed invocation target expected parameter count,
239
236
error code: \( paramCount)
240
- mangled name: \( mangledTargetName )
237
+ mangled name: \( targetName )
241
238
""" )
242
239
}
243
240
@@ -262,7 +259,7 @@ extension DistributedActorSystem {
262
259
message: """
263
260
Failed to decode the expected number of params of distributed invocation target, error code: \( decodedNum)
264
261
(decoded: \( decodedNum) , expected params: \( paramCount)
265
- mangled name: \( mangledTargetName )
262
+ mangled name: \( targetName )
266
263
""" )
267
264
}
268
265
@@ -280,7 +277,7 @@ extension DistributedActorSystem {
280
277
return UnsafeRawPointer ( UnsafeMutablePointer< R> . allocate( capacity: 1 ) )
281
278
}
282
279
283
- guard let returnTypeFromTypeInfo: Any . Type = _getReturnTypeInfo ( mangledMethodName: mangledTargetName ,
280
+ guard let returnTypeFromTypeInfo: Any . Type = _getReturnTypeInfo ( mangledMethodName: targetName ,
284
281
genericEnv: genericEnv,
285
282
genericArguments: substitutionsBuffer) else {
286
283
throw ExecuteDistributedTargetError (
@@ -307,7 +304,7 @@ extension DistributedActorSystem {
307
304
// Execute the target!
308
305
try await _executeDistributedTarget (
309
306
on: actor ,
310
- mangledTargetName , UInt ( mangledTargetName . count) ,
307
+ targetName , UInt ( targetName . count) ,
311
308
argumentDecoder: & invocationDecoder,
312
309
argumentTypes: argumentTypesBuffer. baseAddress!. _rawValue,
313
310
resultBuffer: resultBuffer. _rawValue,
@@ -326,6 +323,52 @@ extension DistributedActorSystem {
326
323
}
327
324
}
328
325
326
+ /// Represents a 'target' of a distributed call, such as a `distributed func` or
327
+ /// `distributed` computed property. Identification schemes may vary between
328
+ /// systems, and are subject to evolution.
329
+ ///
330
+ /// Actor systems generally should treat the `identifier` as an opaque string,
331
+ /// and pass it along to the remote system for in their `remoteCall`
332
+ /// implementation. Alternative approaches are possible, where the identifiers
333
+ /// are either compressed, cached, or represented in other ways, as long as the
334
+ /// recipient system is able to determine which target was intended to be
335
+ /// invoked.
336
+ ///
337
+ /// The string representation will attempt to pretty print the target identifier,
338
+ /// however its exact format is not specified and may change in future versions.
339
+ @available ( SwiftStdlib 5 . 7 , * )
340
+ public struct RemoteCallTarget : CustomStringConvertible {
341
+ private let _storage : _Storage
342
+ private enum _Storage {
343
+ case mangledName( String )
344
+ }
345
+
346
+ // Only intended to be created by the _Distributed library.
347
+ // TODO(distributed): make this internal and only allow calling by the synthesized code?
348
+ public init ( _mangledName: String ) {
349
+ self . _storage = . mangledName( _mangledName)
350
+ }
351
+
352
+ /// The underlying identifier of the target, returned as-is.
353
+ public var identifier : String ? {
354
+ switch self . _storage {
355
+ case . mangledName( let name) :
356
+ return name
357
+ }
358
+ }
359
+
360
+ public var description : String {
361
+ switch self . _storage {
362
+ case . mangledName( let mangledName) :
363
+ if let name = _getFunctionFullNameFromMangledName ( mangledName: mangledName) {
364
+ return name
365
+ } else {
366
+ return " \( mangledName) "
367
+ }
368
+ }
369
+ }
370
+ }
371
+
329
372
@available ( SwiftStdlib 5 . 7 , * )
330
373
@_silgen_name ( " swift_distributed_execute_target " )
331
374
func _executeDistributedTarget< D: DistributedTargetInvocationDecoder > (
@@ -339,29 +382,6 @@ func _executeDistributedTarget<D: DistributedTargetInvocationDecoder>(
339
382
numWitnessTables: UInt
340
383
) async throws
341
384
342
- // ==== ----------------------------------------------------------------------------------------------------------------
343
- // MARK: Support types
344
- /// A distributed 'target' can be a `distributed func` or `distributed` computed property.
345
- @available( SwiftStdlib 5.7 , * )
346
- public struct RemoteCallTarget { // TODO: ship this around always; make printing nice
347
- let _mangledName : String // TODO: StaticString would be better here; no arc, codesize of cleanups
348
-
349
- // Only intended to be created by the _Distributed library.
350
- // TODO(distributed): make this internal and only allow calling by the synthesized code?
351
- public init( _mangledName: String) {
352
- self . _mangledName = _mangledName
353
- }
354
-
355
- public var mangledName : String {
356
- _mangledName
357
- }
358
-
359
- // <module>.Base.hello(hi:)
360
- public var fullName : String { // TODO: make description
361
- fatalError ( " NOT IMPLEMENTED YET: \( #function) " )
362
- }
363
- }
364
-
365
385
/// Used to encode an invocation of a distributed target (method or computed property).
366
386
///
367
387
/// ## Forming an invocation
0 commit comments