Skip to content

Commit 9eb6dd3

Browse files
authored
Merge pull request #60480 from apple/wip-dont-hang-bad-target-call
2 parents cb0721f + 25e1793 commit 9eb6dd3

File tree

2 files changed

+34
-10
lines changed

2 files changed

+34
-10
lines changed

stdlib/public/Distributed/DistributedActor.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,7 @@ static void swift_distributed_execute_target_resume(
109109
return resumeInParent(parentCtx, error);
110110
}
111111

112-
SWIFT_CC(swift)
113-
SWIFT_EXPORT_FROM(swiftDistributed)
112+
SWIFT_CC(swift) SWIFT_RUNTIME_STDLIB_INTERNAL
114113
SwiftError* swift_distributed_makeDistributedTargetAccessorNotFoundError(
115114
const char *targetNameStart, size_t targetNameLength);
116115

stdlib/public/Distributed/DistributedActorSystem.swift

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,8 @@ extension DistributedActorSystem {
251251
let subs = try invocationDecoder.decodeGenericSubstitutions()
252252
if subs.isEmpty {
253253
throw ExecuteDistributedTargetError(
254-
message: "Cannot call generic method without generic argument substitutions")
254+
message: "Cannot call generic method without generic argument substitutions",
255+
errorCode: .missingGenericSubstitutions)
255256
}
256257

257258
substitutionsBuffer = .allocate(capacity: subs.count)
@@ -265,7 +266,8 @@ extension DistributedActorSystem {
265266
genericArguments: substitutionsBuffer!)
266267
if numWitnessTables < 0 {
267268
throw ExecuteDistributedTargetError(
268-
message: "Generic substitutions \(subs) do not satisfy generic requirements of \(target) (\(targetName))")
269+
message: "Generic substitutions \(subs) do not satisfy generic requirements of \(target) (\(targetName))",
270+
errorCode: .invalidGenericSubstitutions)
269271
}
270272
}
271273

@@ -279,7 +281,8 @@ extension DistributedActorSystem {
279281
Failed to decode distributed invocation target expected parameter count,
280282
error code: \(paramCount)
281283
mangled name: \(targetName)
282-
""")
284+
""",
285+
errorCode: .invalidParameterCount)
283286
}
284287

285288
// Prepare buffer for the parameter types to be decoded into:
@@ -304,7 +307,8 @@ extension DistributedActorSystem {
304307
Failed to decode the expected number of params of distributed invocation target, error code: \(decodedNum)
305308
(decoded: \(decodedNum), expected params: \(paramCount)
306309
mangled name: \(targetName)
307-
""")
310+
""",
311+
errorCode: .invalidParameterCount)
308312
}
309313

310314
// Copy the types from the buffer into a Swift Array
@@ -325,12 +329,14 @@ extension DistributedActorSystem {
325329
genericEnv: genericEnv,
326330
genericArguments: substitutionsBuffer) else {
327331
throw ExecuteDistributedTargetError(
328-
message: "Failed to decode distributed target return type")
332+
message: "Failed to decode distributed target return type",
333+
errorCode: .typeDeserializationFailure)
329334
}
330335

331336
guard let resultBuffer = _openExistential(returnTypeFromTypeInfo, do: allocateReturnTypeBuffer) else {
332337
throw ExecuteDistributedTargetError(
333-
message: "Failed to allocate buffer for distributed target return type")
338+
message: "Failed to allocate buffer for distributed target return type",
339+
errorCode: .typeDeserializationFailure)
334340
}
335341

336342
func destroyReturnTypeBuffer<R>(_: R.Type) {
@@ -576,19 +582,38 @@ public protocol DistributedTargetInvocationResultHandler {
576582
@available(SwiftStdlib 5.7, *)
577583
public protocol DistributedActorSystemError: Error {}
578584

585+
/// Error thrown by ``DistributedActorSystem/executeDistributedTarget(on:target:invocationDecoder:handler:)``.
586+
///
587+
/// Inspect the ``errorCode`` for details about the underlying reason this error was thrown.
579588
@available(SwiftStdlib 5.7, *)
580589
public struct ExecuteDistributedTargetError: DistributedActorSystemError {
581590
public let errorCode: ErrorCode
582591
public let message: String
583592

584593
public enum ErrorCode {
585-
/// Thrown when unable to resolve the target identifier to a function accessor.
594+
/// Unable to resolve the target identifier to a function accessor.
586595
/// This can happen when the identifier is corrupt, illegal, or wrong in the
587596
/// sense that the caller and callee do not have the called function recorded
588597
/// using the same identifier.
589598
case targetAccessorNotFound
590599

591-
/// A general issue during the execution of the distributed call target ocurred.
600+
/// Call target has different number of parameters than arguments
601+
/// provided by the invocation decoder.
602+
case invalidParameterCount
603+
604+
/// Target expects generic environment information, but invocation decoder
605+
/// provided no generic substitutions.
606+
case missingGenericSubstitutions
607+
608+
/// Generic substitutions provided by invocation decoder are incompatible
609+
/// with target of the call. E.g. the generic requirements on the actual
610+
/// target could not be fulfilled by the obtained generic substitutions.
611+
case invalidGenericSubstitutions
612+
613+
// Failed to deserialize type or obtain type information for call.
614+
case typeDeserializationFailure
615+
616+
/// A general issue during the execution of the distributed call target occurred.
592617
case other
593618
}
594619

0 commit comments

Comments
 (0)