Skip to content

Commit 3b95855

Browse files
committed
[Distributed] Reword docs since we no longer have ad-hoc requirements
1 parent b5dc349 commit 3b95855

File tree

1 file changed

+20
-127
lines changed

1 file changed

+20
-127
lines changed

stdlib/public/Distributed/DistributedActorSystem.swift

Lines changed: 20 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).
@@ -713,32 +665,6 @@ func _executeDistributedTarget<D: DistributedTargetInvocationDecoder>(
713665
/// Once encoded, the system should use some underlying transport mechanism to send the
714666
/// bytes serialized by the invocation to the remote peer.
715667
///
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-
///
742668
/// ## Decoding an invocation
743669
/// Since every actor system is going to deal with a concrete invocation type, they may
744670
/// implement decoding them whichever way is most optimal for the given system.
@@ -762,6 +688,10 @@ public protocol DistributedTargetInvocationEncoder<SerializationRequirement> {
762688

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

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

@@ -839,35 +773,6 @@ public struct RemoteCallArgument<Value> {
839773
/// Decoder that must be provided to `executeDistributedTarget` and is used
840774
/// by the Swift runtime to decode arguments of the invocation.
841775
///
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-
///
871776
/// ### Decoding DistributedActor arguments using Codable
872777
/// When using an actor system where ``ActorID`` is ``Codable``, every distributed actor using that system
873778
/// is also implicitly ``Codable`` (see ``DistributedActorSystem``). Such distributed actors are encoded
@@ -914,6 +819,10 @@ public protocol DistributedTargetInvocationDecoder<SerializationRequirement> {
914819
/// buffer for all the arguments and their expected types. The 'pointer' passed here is a pointer
915820
/// to a "slot" in that pre-allocated buffer. That buffer will then be passed to a thunk that
916821
/// performs the actual distributed (local) instance method invocation.
822+
///
823+
/// ### Serialization Requirement
824+
/// Implementations of this method must ensure that the `Argument` type parameter conforms
825+
/// to the types' `SerializationRequirement`.
917826
@available(SwiftStdlib 6.0, *)
918827
mutating func decodeNextArgument<Argument/*: SerializationRequirement*/>() throws -> Argument
919828

@@ -936,33 +845,17 @@ public protocol DistributedTargetInvocationDecoder<SerializationRequirement> {
936845
/// ``executeDistributedTarget(on:target:invocationDecoder:handler:)`` while handling an incoming distributed call.
937846
///
938847
/// 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-
/// ```
959848
@available(SwiftStdlib 5.7, *)
960849
public protocol DistributedTargetInvocationResultHandler<SerializationRequirement> {
961850
/// The serialization requirement that the value passed to `onReturn` is required to conform to.
962851
associatedtype SerializationRequirement
963852

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

0 commit comments

Comments
 (0)