Skip to content

Commit 7bd3046

Browse files
authored
[6.0][Distributed] Fix availability of DAS requirements and always emit into client whenLocal with typed throws (#74408)
1 parent 47c7c2d commit 7bd3046

File tree

4 files changed

+22
-139
lines changed

4 files changed

+22
-139
lines changed

stdlib/public/Distributed/DistributedActor.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,7 @@ extension DistributedActor {
362362
/// state.
363363
///
364364
/// When the actor is remote, the closure won't be executed and this function will return nil.
365+
@_alwaysEmitIntoClient
365366
public nonisolated func whenLocal<T: Sendable, E>(
366367
_ body: @Sendable (isolated Self) async throws(E) -> T
367368
) async throws(E) -> T? {

stdlib/public/Distributed/DistributedActorSystem.swift

Lines changed: 21 additions & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -172,58 +172,6 @@ import _Concurrency
172172
/// `remoteCall(on:target:invocation:returning:throwing:)` (or `remoteCallVoid(on:target:invocation:throwing:)` for Void returning methods).
173173
///
174174
/// Implementing the remote calls correctly and efficiently is the important task for a distributed actor system library.
175-
/// Since those methods are not currently expressible as protocol requirements due to advanced use of generics
176-
/// combined with associated types, they will not appear in the protocol's documentation as explicit requirements.
177-
/// Instead, we present their signatures that a conforming type has to implement here:
178-
///
179-
/// > Note: Although the `remoteCall` methods are not expressed as protocol requirements in source,
180-
/// > the compiler will provide the same errors as-if it was declared explicitly in this protocol.
181-
///
182-
/// ```swift
183-
/// /// Invoked by the Swift runtime when making a remote call.
184-
/// ///
185-
/// /// The `arguments` are the arguments container that was previously created
186-
/// /// by `makeInvocationEncoder` and has been populated with all arguments.
187-
/// ///
188-
/// /// This method should perform the actual remote function call, and await for its response.
189-
/// ///
190-
/// /// ## Errors
191-
/// /// This method is allowed to throw because of underlying transport or serialization errors,
192-
/// /// as well as by re-throwing the error received from the remote callee (if able to).
193-
/// func remoteCall<Act, Err, Res>(
194-
/// on actor: Act,
195-
/// target: RemoteCallTarget,
196-
/// invocation: inout InvocationEncoder,
197-
/// throwing: Err.Type,
198-
/// returning: Res.Type
199-
/// ) async throws -> Res
200-
/// where Act: DistributedActor,
201-
/// Act.ID == ActorID,
202-
/// Err: Error,
203-
/// Res: SerializationRequirement
204-
/// ```
205-
///
206-
/// ```swift
207-
/// /// Invoked by the Swift runtime when making a `Void`-returning remote call.
208-
/// ///
209-
/// /// The `arguments` are the arguments container that was previously created
210-
/// /// by `makeInvocationEncoder` and has been populated with all arguments.
211-
/// ///
212-
/// /// This method should perform the actual remote function call, and await for its response.
213-
/// ///
214-
/// /// ## Errors
215-
/// /// This method is allowed to throw because of underlying transport or serialization errors,
216-
/// /// as well as by re-throwing the error received from the remote callee (if able to).
217-
/// func remoteCallVoid<Act, Err>(
218-
/// on actor: Act,
219-
/// target: RemoteCallTarget,
220-
/// invocation: inout InvocationEncoder,
221-
/// throwing: Err.Type
222-
/// ) async throws -> Res
223-
/// where Act: DistributedActor,
224-
/// Act.ID == ActorID,
225-
/// Err: Error
226-
/// ```
227175
///
228176
/// Implementations of remote calls generally will serialize `actor.id`, `target` and `invocation`
229177
/// into some form of wire envelope, and send it over the network (or process boundary) using some
@@ -379,6 +327,10 @@ public protocol DistributedActorSystem<SerializationRequirement>: Sendable {
379327
///
380328
/// This method should perform the actual remote function call, and await for its response.
381329
///
330+
/// ## Serialization Requirement
331+
/// Implementations of this method must ensure that the `Argument` type parameter conforms
332+
/// to the types' `SerializationRequirement`.
333+
///
382334
/// ## Errors
383335
/// This method is allowed to throw because of underlying transport or serialization errors,
384336
/// as well as by re-throwing the error received from the remote callee (if able to).
@@ -405,6 +357,7 @@ public protocol DistributedActorSystem<SerializationRequirement>: Sendable {
405357
/// ## Errors
406358
/// This method is allowed to throw because of underlying transport or serialization errors,
407359
/// as well as by re-throwing the error received from the remote callee (if able to).
360+
@available(SwiftStdlib 6.0, *)
408361
func remoteCallVoid<Act, Err>(
409362
on actor: Act,
410363
target: RemoteCallTarget,
@@ -713,32 +666,6 @@ func _executeDistributedTarget<D: DistributedTargetInvocationDecoder>(
713666
/// Once encoded, the system should use some underlying transport mechanism to send the
714667
/// bytes serialized by the invocation to the remote peer.
715668
///
716-
/// ### Protocol requirements
717-
/// Similar to the ``DistributedActorSystem`` and its `remoteCall` and `remoteCallVoid` protocol requirements,
718-
/// the `DistributedTargetInvocationEncoder` contains a few methods which are not possible to express in source due to
719-
/// advanced use of generics combined with associated types. Specifically, the `recordArgument` and `recordReturnType`
720-
/// methods are not expressed in source as protocol requirements, but will be treated by the compiler as-if they were.
721-
///
722-
/// > Note: Although the `recordArgument` method is not expressed as protocol requirement in source,
723-
/// > the compiler will provide the same errors as-if it was declared explicitly in this protocol.
724-
///
725-
/// In addition to the compiler offering compile errors if those witnesses are missing in an adopting type,
726-
/// we present their signatures here for reference:
727-
///
728-
/// ```swift
729-
/// /// Record an argument of `Argument` type.
730-
/// /// This will be invoked for every argument of the target, in declaration order.
731-
/// mutating func recordArgument<Value: SerializationRequirement>(
732-
/// _ argument: DistributedTargetArgument<Value>
733-
/// ) throws
734-
///
735-
/// /// Ad-hoc requirement
736-
/// ///
737-
/// /// Record the return type of the distributed method.
738-
/// /// This method will not be invoked if the target is returning `Void`.
739-
/// mutating func recordReturnType<R: SerializationRequirement>(_ type: R.Type) throws
740-
/// ```
741-
///
742669
/// ## Decoding an invocation
743670
/// Since every actor system is going to deal with a concrete invocation type, they may
744671
/// implement decoding them whichever way is most optimal for the given system.
@@ -762,6 +689,10 @@ public protocol DistributedTargetInvocationEncoder<SerializationRequirement> {
762689

763690
/// Record an argument of `Argument` type.
764691
/// This will be invoked for every argument of the target, in declaration order.
692+
///
693+
/// ### Serialization Requirement
694+
/// Implementations of this method must ensure that the `Value` type parameter conforms
695+
/// to the types' `SerializationRequirement`.
765696
@available(SwiftStdlib 6.0, *)
766697
mutating func recordArgument<Value/*: SerializationRequirement*/>(
767698
_ argument: RemoteCallArgument<Value>
@@ -775,6 +706,10 @@ public protocol DistributedTargetInvocationEncoder<SerializationRequirement> {
775706

776707
/// Record the return type of the distributed method.
777708
/// This method will not be invoked if the target is returning `Void`.
709+
///
710+
/// ### Serialization Requirement
711+
/// Implementations of this method must ensure that the `R` type parameter conforms
712+
/// to the types' `SerializationRequirement`.
778713
@available(SwiftStdlib 6.0, *)
779714
mutating func recordReturnType<R/*: SerializationRequirement*/>(_ type: R.Type) throws
780715

@@ -839,35 +774,6 @@ public struct RemoteCallArgument<Value> {
839774
/// Decoder that must be provided to `executeDistributedTarget` and is used
840775
/// by the Swift runtime to decode arguments of the invocation.
841776
///
842-
/// ### Protocol requirements
843-
/// Similar to the ``DistributedTargetInvocationEncoder`` and its `recordArgument` and `recordReturnType` protocol requirements,
844-
/// the `DistributedTargetInvocationDecoder` contains a method which is not possible to express in source due to
845-
/// advanced use of generics combined with associated types. Specifically, the `decodeNextArgument`
846-
/// method is not expressed in source as protocol requirement, but will be treated by the compiler as-if it was.
847-
///
848-
/// > Note: Although the `decodeNextArgument` method is not expressed as protocol requirement in source,
849-
/// > the compiler will provide the same errors as-if it was declared explicitly in this protocol.
850-
///
851-
/// In addition to the compiler offering compile errors if this witness is missing in an adopting type,
852-
/// we present its signature here for reference:
853-
///
854-
/// ```swift
855-
/// /// Ad-hoc protocol requirement
856-
/// ///
857-
/// /// Attempt to decode the next argument from the underlying buffers into pre-allocated storage
858-
/// /// pointed at by 'pointer'.
859-
/// ///
860-
/// /// This method should throw if it has no more arguments available, if decoding the argument failed,
861-
/// /// or, optionally, if the argument type we're trying to decode does not match the stored type.
862-
/// ///
863-
/// /// The result of the decoding operation must be stored into the provided 'pointer' rather than
864-
/// /// returning a value. This pattern allows the runtime to use a heavily optimized, pre-allocated
865-
/// /// buffer for all the arguments and their expected types. The 'pointer' passed here is a pointer
866-
/// /// to a "slot" in that pre-allocated buffer. That buffer will then be passed to a thunk that
867-
/// /// performs the actual distributed (local) instance method invocation.
868-
/// mutating func decodeNextArgument<Argument: SerializationRequirement>() throws -> Argument
869-
/// ```
870-
///
871777
/// ### Decoding DistributedActor arguments using Codable
872778
/// When using an actor system where ``ActorID`` is ``Codable``, every distributed actor using that system
873779
/// is also implicitly ``Codable`` (see ``DistributedActorSystem``). Such distributed actors are encoded
@@ -914,6 +820,10 @@ public protocol DistributedTargetInvocationDecoder<SerializationRequirement> {
914820
/// buffer for all the arguments and their expected types. The 'pointer' passed here is a pointer
915821
/// to a "slot" in that pre-allocated buffer. That buffer will then be passed to a thunk that
916822
/// performs the actual distributed (local) instance method invocation.
823+
///
824+
/// ### Serialization Requirement
825+
/// Implementations of this method must ensure that the `Argument` type parameter conforms
826+
/// to the types' `SerializationRequirement`.
917827
@available(SwiftStdlib 6.0, *)
918828
mutating func decodeNextArgument<Argument/*: SerializationRequirement*/>() throws -> Argument
919829

@@ -936,33 +846,17 @@ public protocol DistributedTargetInvocationDecoder<SerializationRequirement> {
936846
/// ``executeDistributedTarget(on:target:invocationDecoder:handler:)`` while handling an incoming distributed call.
937847
///
938848
/// The handler will then be invoked with the return value (or error) that the invoked target returned (or threw).
939-
///
940-
/// ### Protocol requirements
941-
/// Similar to the ``DistributedActorSystem`` and its `remoteCall` and `remoteCallVoid` protocol requirements,
942-
/// the `DistributedTargetInvocationResultHandler` contains a method which is not possible to express in source due to
943-
/// advanced use of generics combined with associated types. Specifically, the `onReturn` method is not expressed in
944-
/// source as protocol requirement, but will be treated by the compiler as-if they were.
945-
///
946-
/// > Note: Although the `onReturn` method is not expressed as protocol requirement in source,
947-
/// > the compiler will provide the same errors as-if it was declared explicitly in this protocol.
948-
///
949-
/// In addition to the compiler offering compile errors if this witnesses is missing in an adopting type,
950-
/// we present its signature here for reference:
951-
///
952-
/// ```swift
953-
/// /// Ad-hoc protocol requirement
954-
/// ///
955-
/// /// Invoked when the distributed target execution returns successfully.
956-
/// /// The `value` is the return value of the executed distributed invocation target.
957-
/// func onReturn<Success: SerializationRequirement>(value: Success) async throws
958-
/// ```
959849
@available(SwiftStdlib 5.7, *)
960850
public protocol DistributedTargetInvocationResultHandler<SerializationRequirement> {
961851
/// The serialization requirement that the value passed to `onReturn` is required to conform to.
962852
associatedtype SerializationRequirement
963853

964854
/// Invoked when the distributed target execution returns successfully.
965855
/// The `value` is the return value of the executed distributed invocation target.
856+
///
857+
/// ### Serialization Requirement
858+
/// Implementations of this method must ensure that the `Success` type parameter conforms
859+
/// to the types' `SerializationRequirement`.
966860
@available(SwiftStdlib 6.0, *)
967861
func onReturn<Success/*: SerializationRequirement*/>(value: Success) async throws
968862

test/abi/macOS/arm64/distributed.swift

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,5 @@ Added: _$s11Distributed0A5ActorPAAE07asLocalB0ScA_pvpMV
102102
// property descriptor for (extension in Distributed):Distributed.DistributedActor.__actorUnownedExecutor : Swift.UnownedSerialExecutor
103103
Added: _$s11Distributed0A5ActorPAAE22__actorUnownedExecutorScevpMV
104104

105-
// (extension in Distributed):Distributed.DistributedActor.whenLocal<A, B where A1: Swift.Sendable, B1: Swift.Error>(@Sendable (isolated A) async throws(B1) -> A1) async throws(B1) -> A1?
106-
Added: _$s11Distributed0A5ActorPAAE9whenLocalyqd__Sgqd__xYiYaYbqd_0_YKXEYaqd_0_YKs8SendableRd__s5ErrorRd_0_r0_lF
107-
108-
// async function pointer to (extension in Distributed):Distributed.DistributedActor.whenLocal<A, B where A1: Swift.Sendable, B1: Swift.Error>(@Sendable (isolated A) async throws(B1) -> A1) async throws(B1) -> A1?
109-
Added: _$s11Distributed0A5ActorPAAE9whenLocalyqd__Sgqd__xYiYaYbqd_0_YKXEYaqd_0_YKs8SendableRd__s5ErrorRd_0_r0_lFTu
110-
111105
// Distributed._distributedStubFatalError(function: Swift.String) -> Swift.Never
112106
Added: _$s11Distributed26_distributedStubFatalError8functions5NeverOSS_tF

test/abi/macOS/x86_64/distributed.swift

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,5 @@ Added: _$s11Distributed0A5ActorPAAE07asLocalB0ScA_pvpMV
102102
// property descriptor for (extension in Distributed):Distributed.DistributedActor.__actorUnownedExecutor : Swift.UnownedSerialExecutor
103103
Added: _$s11Distributed0A5ActorPAAE22__actorUnownedExecutorScevpMV
104104

105-
// (extension in Distributed):Distributed.DistributedActor.whenLocal<A, B where A1: Swift.Sendable, B1: Swift.Error>(@Sendable (isolated A) async throws(B1) -> A1) async throws(B1) -> A1?
106-
Added: _$s11Distributed0A5ActorPAAE9whenLocalyqd__Sgqd__xYiYaYbqd_0_YKXEYaqd_0_YKs8SendableRd__s5ErrorRd_0_r0_lF
107-
108-
// async function pointer to (extension in Distributed):Distributed.DistributedActor.whenLocal<A, B where A1: Swift.Sendable, B1: Swift.Error>(@Sendable (isolated A) async throws(B1) -> A1) async throws(B1) -> A1?
109-
Added: _$s11Distributed0A5ActorPAAE9whenLocalyqd__Sgqd__xYiYaYbqd_0_YKXEYaqd_0_YKs8SendableRd__s5ErrorRd_0_r0_lFTu
110-
111105
// Distributed._distributedStubFatalError(function: Swift.String) -> Swift.Never
112106
Added: _$s11Distributed26_distributedStubFatalError8functions5NeverOSS_tF

0 commit comments

Comments
 (0)