Skip to content

Commit 44aba81

Browse files
authored
Merge pull request #1560 from xedin/se-0344-rename-result-and-error-params
[SE-0344] Rename Error, Result generic parameters to Failure, Success
2 parents fc61adc + 2117f09 commit 44aba81

File tree

1 file changed

+33
-33
lines changed

1 file changed

+33
-33
lines changed

proposals/0344-distributed-actor-runtime.md

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -296,17 +296,17 @@ protocol DistributedActorSystem: Sendable {
296296
/// as well as by re-throwing the error received from the remote callee (if able to).
297297
//
298298
// Ad-hoc protocol requirement
299-
func remoteCall<Actor, Error, Result>(
299+
func remoteCall<Actor, Failure, Success>(
300300
on actor: Actor,
301301
target: RemoteCallTarget,
302302
invocation: InvocationEncoder,
303-
throwing: Error.Type,
304-
returning: Result.Type
305-
) async throws -> Result
303+
throwing: Failure.Type,
304+
returning: Success.Type
305+
) async throws -> Success
306306
where Actor: DistributedActor,
307307
Actor.ID == ActorID,
308-
Error: Swift.Error,
309-
Result: Self.SerializationRequirement
308+
Failure: Error,
309+
Success: Self.SerializationRequirement
310310

311311
/// Invoked by the Swift runtime when making a remote call to a 'Void' returning function.
312312
///
@@ -317,11 +317,11 @@ protocol DistributedActorSystem: Sendable {
317317
on actor: Actor,
318318
target: RemoteCallTarget,
319319
invocation: InvocationEncoder,
320-
throwing: Error.Type
320+
throwing: Failure.Type
321321
) async throws
322322
where Actor: DistributedActor,
323323
Actor.ID == ActorID,
324-
Error: Swift.Error
324+
Failure: Error
325325
}
326326

327327
/// A distributed 'target' can be a `distributed func` or `distributed` computed property.
@@ -1161,17 +1161,17 @@ Once that is complete, the runtime will pass the constructed `InvocationEncoder`
11611161
// remoteCall is not a protocol requirement, however its signature is well known to the compiler,
11621162
// and it will invoke the method. We also are guaranteed that the 'Res: Codable' requirement is correct,
11631163
// since the type-system will enforce this conformance thanks to the type-level checks on distributed funcs.
1164-
func remoteCall<Actor, Error, Result>(
1164+
func remoteCall<Actor, Failure, Success>(
11651165
on actor: Actor,
11661166
target: RemoteCallTarget,
11671167
invocation: Self.InvocationEncoder,
1168-
throwing: Error.Type,
1169-
returning: Result.Type
1170-
) async throws -> Result
1168+
throwing: Failure.Type,
1169+
returning: Success.Type
1170+
) async throws -> Success
11711171
where Actor: DistributedActor,
11721172
Actor.ID == ActorID.
1173-
Error: Swift.Error,
1174-
Result: Self.SerializationRequirement {
1173+
Failure: Error,
1174+
Success: Self.SerializationRequirement {
11751175
var envelope = invocation.envelope
11761176

11771177
// [1] the recipient is transferred over the wire as its id
@@ -1378,10 +1378,10 @@ The `DistributedTargetInvocationResultHandler` is defined as follows:
13781378
protocol DistributedTargetInvocationResultHandler {
13791379
associatedtype SerializationRequirement
13801380

1381-
func onReturn<Result>(value: Result) async throws
1382-
where Result: SerializationRequirement
1381+
func onReturn<Success>(value: Success) async throws
1382+
where Success: SerializationRequirement
13831383
func onThrow<Error>(error: Error) async throws
1384-
where Error: Swift.Error
1384+
where Failure: Error
13851385
}
13861386
```
13871387

@@ -1680,21 +1680,21 @@ This section summarizes various points in the design space for this proposal tha
16801680
The proposal includes the fairly special `remoteCall` method that is expected to be present on a distributed actor system, however is not part of the protocol requirements because it cannot be nicely expressed in today's Swift, and it suffers from the lack of variadic generics (which are being worked on, see: [Pitching The Start of Variadic Generics](https://forums.swift.org/t/pitching-the-start-of-variadic-generics/51467)), however until they are complete, expressing `remoteCall` in the type-system is fairly painful, and we resort to providing multiple overloads of the method:
16811681

16821682
```swift
1683-
func remoteCall<Actor, P1, Error, Result>(
1683+
func remoteCall<Actor, P1, Failure, Success>(
16841684
on recipient: Actor,
16851685
method: DistributedMethodName,
16861686
_ arg1: P1,
1687-
throwing errorType: Error.Type,
1688-
returning returnType: Result.Type
1689-
) async throws -> Result where Actor: DistributedActor, Actor.ID = ActorID { ... }
1687+
throwing errorType: Failure.Type,
1688+
returning returnType: Success.Type
1689+
) async throws -> Success where Actor: DistributedActor, Actor.ID = ActorID { ... }
16901690

1691-
func remoteCall<Actor, P1, P2, Error, Result>(
1691+
func remoteCall<Actor, P1, P2, Failure, Success>(
16921692
on recipient: Actor,
16931693
method: DistributedMethodName,
16941694
_ arg1: P1, _ arg2: P2,
1695-
throwing errorType: Error.Type,
1696-
returning returnType: Result.Type
1697-
) async throws -> Result where Actor: DistributedActor, Actor.ID = ActorID { ... }
1695+
throwing errorType: Failure.Type,
1696+
returning returnType: Success.Type
1697+
) async throws -> Success where Actor: DistributedActor, Actor.ID = ActorID { ... }
16981698

16991699
// ...
17001700
```
@@ -1704,13 +1704,13 @@ This is annoying for the few distributed actor system developers, however it all
17041704
We are also able to avoid any heap allocations during the `remoteCall` thanks to this approach, as we do not have to construct type erased `arguments: [Any]` which would have been the alternative:
17051705

17061706
```swift
1707-
func remoteCall<Actor, Error, Result>(
1707+
func remoteCall<Actor, Failure, Success>(
17081708
on recipient: Actor,
17091709
method: DistributedMethodIdentifier,
17101710
_ args: [Any], // BAD
1711-
throwing errorType: Error.Type,
1712-
returning returnType: Result.Type
1713-
) async throws -> Result where Actor: DistributedActor, Actor.ID = ActorID { ... }
1711+
throwing errorType: Failure.Type,
1712+
returning returnType: Success.Type
1713+
) async throws -> Success where Actor: DistributedActor, Actor.ID = ActorID { ... }
17141714
```
17151715

17161716
Not only that, but passing arguments as `[Any]` would force developers into using internal machinery to open the existentials (the not officially supported `_openExistential` feature), in order to obtain their specific types, and e.g. use `Codable` with them.
@@ -1720,13 +1720,13 @@ Not only that, but passing arguments as `[Any]` would force developers into usin
17201720
Looking at the signature, one might be tempted to also include a `where` clause to statically enforce that all parameters and return type, conform to the `Self.SerializationRequirement`, like so:
17211721

17221722
```swift
1723-
func remoteCall<Actor, P1, Error, Result>(
1723+
func remoteCall<Actor, P1, Failure, Success>(
17241724
on recipient: Actor,
17251725
method: DistributedMethodName,
17261726
_ arg1: P1,
1727-
throwing errorType: Error.Type,
1728-
returning returnType: Result.Type
1729-
) async throws -> Result where Actor: DistributedActor,
1727+
throwing errorType: Failure.Type,
1728+
returning returnType: Success.Type
1729+
) async throws -> Success where Actor: DistributedActor,
17301730
Actor.ID = ActorID,
17311731
P1: SerializationRequirement { ... }
17321732
// ❌ error: type 'P1' constrained to non-protocol, non-class type 'Self.R'

0 commit comments

Comments
 (0)