Skip to content

Commit 7718448

Browse files
committed
[Distributed] Simplify repr of RemoteCallTarget
1 parent 4fa0855 commit 7718448

File tree

1 file changed

+16
-19
lines changed

1 file changed

+16
-19
lines changed

stdlib/public/Distributed/DistributedActorSystem.swift

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,12 @@ extension DistributedActorSystem {
178178
) async throws where Act: DistributedActor,
179179
// Act.ID == ActorID, // FIXME(distributed): can we bring this back?
180180
ResultHandler: DistributedTargetInvocationResultHandler {
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.
186+
181187
// Get the expected parameter count of the func
182188
guard let targetName = target.identifier else {
183189
throw ExecuteDistributedTargetError(
@@ -338,33 +344,24 @@ extension DistributedActorSystem {
338344
/// however its exact format is not specified and may change in future versions.
339345
@available(SwiftStdlib 5.7, *)
340346
public struct RemoteCallTarget: CustomStringConvertible {
341-
private let _storage: _Storage
342-
private enum _Storage {
343-
case mangledName(String)
344-
}
347+
private let _identifier: String
345348

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)
349+
public init(_ identifier: String) {
350+
self._identifier = identifier
350351
}
351352

352353
/// The underlying identifier of the target, returned as-is.
353354
public var identifier: String? {
354-
switch self._storage {
355-
case .mangledName(let name):
356-
return name
357-
}
355+
return _identifier
358356
}
359357

358+
/// Attempts to pretty format the underlying target identifier.
359+
/// If unable to, returns the raw underlying identifier.
360360
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-
}
361+
if let name = _getFunctionFullNameFromMangledName(mangledName: _identifier) {
362+
return name
363+
} else {
364+
return "\(_identifier)"
368365
}
369366
}
370367
}

0 commit comments

Comments
 (0)