@@ -172,23 +172,18 @@ extension DistributedActorSystem {
172172 /// latency sensitive-use-cases.
173173 public func executeDistributedTarget< Act, ResultHandler> (
174174 on actor : Act ,
175- mangledTargetName : String ,
175+ target : RemoteCallTarget ,
176176 invocationDecoder: inout InvocationDecoder ,
177177 handler: ResultHandler
178178 ) async throws where Act: DistributedActor ,
179179 // Act.ID == ActorID, // FIXME(distributed): can we bring this back?
180180 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 {
186183 throw ExecuteDistributedTargetError (
187- message: " Illegal mangledTargetName detected, must start with '$' " )
184+ message: " Unable to extract target identifier from remote call target: \( target ) " )
188185 }
189-
190- // Get the expected parameter count of the func
191- let nameUTF8 = Array ( mangledTargetName. utf8)
186+ let nameUTF8 = Array ( targetName. utf8)
192187
193188 // Gen the generic environment (if any) associated with the target.
194189 let genericEnv = nameUTF8. withUnsafeBufferPointer { nameUTF8 in
@@ -207,7 +202,9 @@ extension DistributedActorSystem {
207202
208203 if let genericEnv = genericEnv {
209204 let subs = try invocationDecoder. decodeGenericSubstitutions ( )
210-
205+ for item in subs {
206+ print ( " SUB: \( item) " )
207+ }
211208 if subs. isEmpty {
212209 throw ExecuteDistributedTargetError (
213210 message: " Cannot call generic method without generic argument substitutions " )
@@ -224,7 +221,7 @@ extension DistributedActorSystem {
224221 genericArguments: substitutionsBuffer!)
225222 if numWitnessTables < 0 {
226223 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 ) ) " )
228225 }
229226 }
230227
@@ -237,7 +234,7 @@ extension DistributedActorSystem {
237234 message: """
238235 Failed to decode distributed invocation target expected parameter count,
239236 error code: \( paramCount)
240- mangled name: \( mangledTargetName )
237+ mangled name: \( targetName )
241238 """ )
242239 }
243240
@@ -262,7 +259,7 @@ extension DistributedActorSystem {
262259 message: """
263260 Failed to decode the expected number of params of distributed invocation target, error code: \( decodedNum)
264261 (decoded: \( decodedNum) , expected params: \( paramCount)
265- mangled name: \( mangledTargetName )
262+ mangled name: \( targetName )
266263 """ )
267264 }
268265
@@ -280,7 +277,7 @@ extension DistributedActorSystem {
280277 return UnsafeRawPointer ( UnsafeMutablePointer< R> . allocate( capacity: 1 ) )
281278 }
282279
283- guard let returnTypeFromTypeInfo: Any . Type = _getReturnTypeInfo ( mangledMethodName: mangledTargetName ,
280+ guard let returnTypeFromTypeInfo: Any . Type = _getReturnTypeInfo ( mangledMethodName: targetName ,
284281 genericEnv: genericEnv,
285282 genericArguments: substitutionsBuffer) else {
286283 throw ExecuteDistributedTargetError (
@@ -307,7 +304,7 @@ extension DistributedActorSystem {
307304 // Execute the target!
308305 try await _executeDistributedTarget (
309306 on: actor ,
310- mangledTargetName , UInt ( mangledTargetName . count) ,
307+ targetName , UInt ( targetName . count) ,
311308 argumentDecoder: & invocationDecoder,
312309 argumentTypes: argumentTypesBuffer. baseAddress!. _rawValue,
313310 resultBuffer: resultBuffer. _rawValue,
@@ -326,6 +323,52 @@ extension DistributedActorSystem {
326323 }
327324}
328325
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+
329372@available ( SwiftStdlib 5 . 7 , * )
330373@_silgen_name ( " swift_distributed_execute_target " )
331374func _executeDistributedTarget< D: DistributedTargetInvocationDecoder > (
@@ -339,29 +382,6 @@ func _executeDistributedTarget<D: DistributedTargetInvocationDecoder>(
339382 numWitnessTables: UInt
340383) async throws
341384
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-
365385/// Used to encode an invocation of a distributed target (method or computed property).
366386///
367387/// ## Forming an invocation
0 commit comments