mirror of
https://github.com/apple/swift.git
synced 2026-10-14 15:51:20 +02:00
90 lines
3.1 KiB
Swift
90 lines
3.1 KiB
Swift
// RUN: %target-swift-frontend -typecheck -verify -enable-experimental-feature Embedded -parse-as-library -wmo -target %target-cpu-apple-macos14 %s
|
|
|
|
// REQUIRES: OS=macosx
|
|
// REQUIRES: swift_feature_Embedded
|
|
// REQUIRES: optimized_stdlib
|
|
|
|
// Distributed actors in Embedded Swift are gated behind the experimental
|
|
// feature `EmbeddedDistributed`.
|
|
|
|
import _Concurrency
|
|
import Distributed
|
|
|
|
public struct EmbeddedActorID: Sendable, Hashable {
|
|
public let id: UInt64
|
|
}
|
|
|
|
public protocol MySerializationRequirement {}
|
|
|
|
public struct MyEncoder: DistributedTargetInvocationEncoder {
|
|
public init() {}
|
|
public mutating func doneRecording() throws {}
|
|
}
|
|
extension MyEncoder {
|
|
public mutating func recordArgument<Value: MySerializationRequirement>(
|
|
_ argument: RemoteCallArgument<Value>) throws {}
|
|
}
|
|
|
|
public struct MyDecoder: DistributedTargetInvocationDecoder {
|
|
public init() {}
|
|
}
|
|
extension MyDecoder {
|
|
public mutating func decodeNextArgument<Argument: MySerializationRequirement>() throws -> Argument {
|
|
fatalError("stub")
|
|
}
|
|
}
|
|
|
|
public struct MyResultHandler: DistributedTargetInvocationResultHandler {
|
|
public init() {}
|
|
public func onReturnVoid() async throws {}
|
|
public func onThrow(error: any Error) async throws {}
|
|
}
|
|
extension MyResultHandler {
|
|
public func onReturn<Success: MySerializationRequirement>(value: Success) async throws {}
|
|
}
|
|
|
|
// expected-error@+1{{'distributed actor' in Embedded Swift requires '-enable-experimental-feature EmbeddedDistributed'}}
|
|
public final class MySystem: DistributedActorSystem, @unchecked Sendable {
|
|
public typealias ActorID = EmbeddedActorID
|
|
public typealias SerializationRequirement = MySerializationRequirement
|
|
public typealias InvocationEncoder = MyEncoder
|
|
public typealias InvocationDecoder = MyDecoder
|
|
public typealias ResultHandler = MyResultHandler
|
|
|
|
public init() {}
|
|
|
|
public func resolve<Act>(id: ActorID, as actorType: Act.Type) throws -> Act?
|
|
where Act: DistributedActor, Act.ID == ActorID { return nil }
|
|
public func assignID<Act>(_ actorType: Act.Type) -> ActorID
|
|
where Act: DistributedActor, Act.ID == ActorID { return ActorID(id: 0) }
|
|
public func actorReady<Act>(_ actor: Act)
|
|
where Act: DistributedActor, Act.ID == ActorID {}
|
|
public func resignID(_ id: ActorID) {}
|
|
|
|
public func makeInvocationEncoder() -> InvocationEncoder { .init() }
|
|
|
|
public func remoteCall<Act, Err, Res>(
|
|
on actor: Act,
|
|
target: RemoteCallTarget,
|
|
invocation: inout InvocationEncoder,
|
|
throwing: Err.Type,
|
|
returning: Res.Type
|
|
) async throws -> Res
|
|
where Act: DistributedActor, Act.ID == ActorID, Err: Error, Res: MySerializationRequirement { fatalError() }
|
|
|
|
public func remoteCallVoid<Act, Err>(
|
|
on actor: Act,
|
|
target: RemoteCallTarget,
|
|
invocation: inout InvocationEncoder,
|
|
throwing: Err.Type
|
|
) async throws
|
|
where Act: DistributedActor, Act.ID == ActorID, Err: Error { fatalError() }
|
|
}
|
|
|
|
typealias DefaultDistributedActorSystem = MySystem
|
|
|
|
// expected-error@+1{{'distributed actor' in Embedded Swift requires '-enable-experimental-feature EmbeddedDistributed'}}
|
|
distributed actor Greeter {
|
|
distributed func hello() {}
|
|
}
|