@@ -172,23 +172,21 @@ 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 {
186
- throw ExecuteDistributedTargetError (
187
- message: " Illegal mangledTargetName detected, must start with '$' " )
188
- }
181
+ // NOTE: Implementation could be made more efficient because we still risk
182
+ // demangling a RemoteCallTarget identity (if it is a mangled name) multiple
183
+ // times. We would prefer to store if it is a mangled name, demangle, and
184
+ // always refer to that demangled repr perhaps? We do cache the resulting
185
+ // pretty formatted name of the call target, but perhaps we can do better.
189
186
190
187
// Get the expected parameter count of the func
191
- let nameUTF8 = Array ( mangledTargetName. utf8)
188
+ let targetName = target. identifier
189
+ let nameUTF8 = Array ( targetName. utf8)
192
190
193
191
// Gen the generic environment (if any) associated with the target.
194
192
let genericEnv = nameUTF8. withUnsafeBufferPointer { nameUTF8 in
@@ -207,7 +205,9 @@ extension DistributedActorSystem {
207
205
208
206
if let genericEnv = genericEnv {
209
207
let subs = try invocationDecoder. decodeGenericSubstitutions ( )
210
-
208
+ for item in subs {
209
+ print ( " SUB: \( item) " )
210
+ }
211
211
if subs. isEmpty {
212
212
throw ExecuteDistributedTargetError (
213
213
message: " Cannot call generic method without generic argument substitutions " )
@@ -224,7 +224,7 @@ extension DistributedActorSystem {
224
224
genericArguments: substitutionsBuffer!)
225
225
if numWitnessTables < 0 {
226
226
throw ExecuteDistributedTargetError (
227
- message: " Generic substitutions \( subs) do not satisfy generic requirements of \( mangledTargetName ) " )
227
+ message: " Generic substitutions \( subs) do not satisfy generic requirements of \( target ) ( \( targetName ) ) " )
228
228
}
229
229
}
230
230
@@ -237,7 +237,7 @@ extension DistributedActorSystem {
237
237
message: """
238
238
Failed to decode distributed invocation target expected parameter count,
239
239
error code: \( paramCount)
240
- mangled name: \( mangledTargetName )
240
+ mangled name: \( targetName )
241
241
""" )
242
242
}
243
243
@@ -262,7 +262,7 @@ extension DistributedActorSystem {
262
262
message: """
263
263
Failed to decode the expected number of params of distributed invocation target, error code: \( decodedNum)
264
264
(decoded: \( decodedNum) , expected params: \( paramCount)
265
- mangled name: \( mangledTargetName )
265
+ mangled name: \( targetName )
266
266
""" )
267
267
}
268
268
@@ -280,7 +280,7 @@ extension DistributedActorSystem {
280
280
return UnsafeRawPointer ( UnsafeMutablePointer< R> . allocate( capacity: 1 ) )
281
281
}
282
282
283
- guard let returnTypeFromTypeInfo: Any . Type = _getReturnTypeInfo ( mangledMethodName: mangledTargetName ,
283
+ guard let returnTypeFromTypeInfo: Any . Type = _getReturnTypeInfo ( mangledMethodName: targetName ,
284
284
genericEnv: genericEnv,
285
285
genericArguments: substitutionsBuffer) else {
286
286
throw ExecuteDistributedTargetError (
@@ -307,7 +307,7 @@ extension DistributedActorSystem {
307
307
// Execute the target!
308
308
try await _executeDistributedTarget (
309
309
on: actor ,
310
- mangledTargetName , UInt ( mangledTargetName . count) ,
310
+ targetName , UInt ( targetName . count) ,
311
311
argumentDecoder: & invocationDecoder,
312
312
argumentTypes: argumentTypesBuffer. baseAddress!. _rawValue,
313
313
resultBuffer: resultBuffer. _rawValue,
@@ -326,6 +326,43 @@ extension DistributedActorSystem {
326
326
}
327
327
}
328
328
329
+ /// Represents a 'target' of a distributed call, such as a `distributed func` or
330
+ /// `distributed` computed property. Identification schemes may vary between
331
+ /// systems, and are subject to evolution.
332
+ ///
333
+ /// Actor systems generally should treat the `identifier` as an opaque string,
334
+ /// and pass it along to the remote system for in their `remoteCall`
335
+ /// implementation. Alternative approaches are possible, where the identifiers
336
+ /// are either compressed, cached, or represented in other ways, as long as the
337
+ /// recipient system is able to determine which target was intended to be
338
+ /// invoked.
339
+ ///
340
+ /// The string representation will attempt to pretty print the target identifier,
341
+ /// however its exact format is not specified and may change in future versions.
342
+ @available ( SwiftStdlib 5 . 7 , * )
343
+ public struct RemoteCallTarget : CustomStringConvertible {
344
+ private let _identifier : String
345
+
346
+ public init ( _ identifier: String ) {
347
+ self . _identifier = identifier
348
+ }
349
+
350
+ /// The underlying identifier of the target, returned as-is.
351
+ public var identifier : String {
352
+ return _identifier
353
+ }
354
+
355
+ /// Attempts to pretty format the underlying target identifier.
356
+ /// If unable to, returns the raw underlying identifier.
357
+ public var description : String {
358
+ if let name = _getFunctionFullNameFromMangledName ( mangledName: _identifier) {
359
+ return name
360
+ } else {
361
+ return " \( _identifier) "
362
+ }
363
+ }
364
+ }
365
+
329
366
@available ( SwiftStdlib 5 . 7 , * )
330
367
@_silgen_name ( " swift_distributed_execute_target " )
331
368
func _executeDistributedTarget< D: DistributedTargetInvocationDecoder > (
@@ -339,29 +376,6 @@ func _executeDistributedTarget<D: DistributedTargetInvocationDecoder>(
339
376
numWitnessTables: UInt
340
377
) async throws
341
378
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
379
/// Used to encode an invocation of a distributed target (method or computed property).
366
380
///
367
381
/// ## Forming an invocation
@@ -407,11 +421,9 @@ public protocol DistributedTargetInvocationEncoder {
407
421
// mutating func recordArgument<Argument: SerializationRequirement>(_ argument: Argument) throws
408
422
// TODO(distributed): offer recordArgument(label:type:)
409
423
410
- // /// Ad-hoc requirement
411
- // ///
412
- // /// Record the error type of the distributed method.
413
- // /// This method will not be invoked if the target is not throwing.
414
- // mutating func recordErrorType<E: Error>(_ type: E.Type) throws // TODO: make not adhoc
424
+ /// Record the error type of the distributed method.
425
+ /// This method will not be invoked if the target is not throwing.
426
+ mutating func recordErrorType< E: Error > ( _ type: E . Type ) throws
415
427
416
428
// /// Ad-hoc requirement
417
429
// ///
0 commit comments