@@ -172,58 +172,6 @@ import _Concurrency
172
172
/// `remoteCall(on:target:invocation:returning:throwing:)` (or `remoteCallVoid(on:target:invocation:throwing:)` for Void returning methods).
173
173
///
174
174
/// 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
- /// ```
227
175
///
228
176
/// Implementations of remote calls generally will serialize `actor.id`, `target` and `invocation`
229
177
/// 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 {
379
327
///
380
328
/// This method should perform the actual remote function call, and await for its response.
381
329
///
330
+ /// ## Serialization Requirement
331
+ /// Implementations of this method must ensure that the `Argument` type parameter conforms
332
+ /// to the types' `SerializationRequirement`.
333
+ ///
382
334
/// ## Errors
383
335
/// This method is allowed to throw because of underlying transport or serialization errors,
384
336
/// 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 {
405
357
/// ## Errors
406
358
/// This method is allowed to throw because of underlying transport or serialization errors,
407
359
/// as well as by re-throwing the error received from the remote callee (if able to).
360
+ @available ( SwiftStdlib 6 . 0 , * )
408
361
func remoteCallVoid< Act, Err> (
409
362
on actor : Act ,
410
363
target: RemoteCallTarget ,
@@ -713,32 +666,6 @@ func _executeDistributedTarget<D: DistributedTargetInvocationDecoder>(
713
666
/// Once encoded, the system should use some underlying transport mechanism to send the
714
667
/// bytes serialized by the invocation to the remote peer.
715
668
///
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
- ///
742
669
/// ## Decoding an invocation
743
670
/// Since every actor system is going to deal with a concrete invocation type, they may
744
671
/// implement decoding them whichever way is most optimal for the given system.
@@ -762,6 +689,10 @@ public protocol DistributedTargetInvocationEncoder<SerializationRequirement> {
762
689
763
690
/// Record an argument of `Argument` type.
764
691
/// 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`.
765
696
@available ( SwiftStdlib 6 . 0 , * )
766
697
mutating func recordArgument< Value/*: SerializationRequirement*/> (
767
698
_ argument: RemoteCallArgument < Value >
@@ -775,6 +706,10 @@ public protocol DistributedTargetInvocationEncoder<SerializationRequirement> {
775
706
776
707
/// Record the return type of the distributed method.
777
708
/// 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`.
778
713
@available ( SwiftStdlib 6 . 0 , * )
779
714
mutating func recordReturnType< R/*: SerializationRequirement*/> ( _ type: R . Type ) throws
780
715
@@ -839,35 +774,6 @@ public struct RemoteCallArgument<Value> {
839
774
/// Decoder that must be provided to `executeDistributedTarget` and is used
840
775
/// by the Swift runtime to decode arguments of the invocation.
841
776
///
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
- ///
871
777
/// ### Decoding DistributedActor arguments using Codable
872
778
/// When using an actor system where ``ActorID`` is ``Codable``, every distributed actor using that system
873
779
/// is also implicitly ``Codable`` (see ``DistributedActorSystem``). Such distributed actors are encoded
@@ -914,6 +820,10 @@ public protocol DistributedTargetInvocationDecoder<SerializationRequirement> {
914
820
/// buffer for all the arguments and their expected types. The 'pointer' passed here is a pointer
915
821
/// to a "slot" in that pre-allocated buffer. That buffer will then be passed to a thunk that
916
822
/// 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`.
917
827
@available ( SwiftStdlib 6 . 0 , * )
918
828
mutating func decodeNextArgument< Argument /*: SerializationRequirement*/> ( ) throws -> Argument
919
829
@@ -936,33 +846,17 @@ public protocol DistributedTargetInvocationDecoder<SerializationRequirement> {
936
846
/// ``executeDistributedTarget(on:target:invocationDecoder:handler:)`` while handling an incoming distributed call.
937
847
///
938
848
/// 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
- /// ```
959
849
@available ( SwiftStdlib 5 . 7 , * )
960
850
public protocol DistributedTargetInvocationResultHandler< SerializationRequirement > {
961
851
/// The serialization requirement that the value passed to `onReturn` is required to conform to.
962
852
associatedtype SerializationRequirement
963
853
964
854
/// Invoked when the distributed target execution returns successfully.
965
855
/// 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`.
966
860
@available ( SwiftStdlib 6 . 0 , * )
967
861
func onReturn< Success/*: SerializationRequirement*/> ( value: Success ) async throws
968
862
0 commit comments