mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[Distributed] Implement RemoteCallArgument
This commit is contained in:
@@ -420,7 +420,9 @@ public protocol DistributedTargetInvocationEncoder {
|
||||
// ///
|
||||
// /// Record an argument of `Argument` type.
|
||||
// /// This will be invoked for every argument of the target, in declaration order.
|
||||
// mutating func recordArgument<Argument: SerializationRequirement>(_ argument: Argument) throws
|
||||
// mutating func recordArgument<Value: SerializationRequirement>(
|
||||
// _ argument: DistributedTargetArgument<Value>
|
||||
// ) throws
|
||||
|
||||
/// Record the error type of the distributed method.
|
||||
/// This method will not be invoked if the target is not throwing.
|
||||
@@ -435,8 +437,47 @@ public protocol DistributedTargetInvocationEncoder {
|
||||
mutating func doneRecording() throws
|
||||
}
|
||||
|
||||
/// Represents an argument passed to a distributed call target.
|
||||
@available(SwiftStdlib 5.7, *)
|
||||
public
|
||||
public struct RemoteCallArgument<Value> {
|
||||
/// The "argument label" of the argument.
|
||||
/// The label is the name visible name used in external calls made to this
|
||||
/// target, e.g. for `func hello(label name: String)` it is `label`.
|
||||
///
|
||||
/// If no label is specified (i.e. `func hi(name: String)`), the `label`,
|
||||
/// value is empty, however `effectiveLabel` is equal to the `name`.
|
||||
///
|
||||
/// In most situations, using `effectiveLabel` is more useful to identify
|
||||
/// the user-visible name of this argument.
|
||||
public let label: String?
|
||||
|
||||
/// The effective label of this argument, i.e. if no explicit `label` was set
|
||||
/// this defaults to the `name`. This reflects the semantics of call sites of
|
||||
/// function declarations without explicit label definitions in Swift.
|
||||
public var effectiveLabel: String {
|
||||
return label ?? name
|
||||
}
|
||||
|
||||
/// The internal name of parameter this argument is accessible as in the
|
||||
/// function body. It is not part of the functions API and may change without
|
||||
/// breaking the target identifier.
|
||||
///
|
||||
/// If the method did not declare an explicit `label`, it is used as the
|
||||
/// `effectiveLabel`.
|
||||
public let name: String
|
||||
|
||||
/// The value of the argument being passed to the call.
|
||||
/// As `RemoteCallArgument` is always used in conjunction with
|
||||
/// `recordArgument` and populated by the compiler, this Value will generally
|
||||
/// conform to a distributed actor system's `SerializationRequirement`.
|
||||
public let value: Value
|
||||
|
||||
public init(label: String?, name: String, value: Value) {
|
||||
self.label = label
|
||||
self.name = name
|
||||
self.value = value
|
||||
}
|
||||
}
|
||||
|
||||
/// Decoder that must be provided to `executeDistributedTarget` and is used
|
||||
/// by the Swift runtime to decode arguments of the invocation.
|
||||
|
||||
Reference in New Issue
Block a user