|
| 1 | +// RUN: %empty-directory(%t) |
| 2 | +// RUN: %target-swift-frontend-emit-module -emit-module-path %t/FakeDistributedActorSystems.swiftmodule -module-name FakeDistributedActorSystems -disable-availability-checking %S/Inputs/FakeDistributedActorSystems.swift |
| 3 | +// RUN: %target-swift-frontend -typecheck -verify -disable-availability-checking -I %t 2>&1 %s |
| 4 | +// REQUIRES: concurrency |
| 5 | +// REQUIRES: distributed |
| 6 | + |
| 7 | +import Distributed |
| 8 | +import FakeDistributedActorSystems |
| 9 | + |
| 10 | +distributed actor YesVeryMuchSo { |
| 11 | + typealias ActorSystem = FakeRoundtripActorSystem |
| 12 | +} |
| 13 | +func test_YesVeryMuchSo(_ actor: YesVeryMuchSo) { |
| 14 | + let _: any Codable = actor // implicit conformance, ID was Codable |
| 15 | + |
| 16 | + // unrelated protocol |
| 17 | + let _: any CustomSerializationProtocol = actor // expected-error{{value of type 'YesVeryMuchSo' does not conform to specified type 'CustomSerializationProtocol'}} |
| 18 | +} |
| 19 | + |
| 20 | +// ==== ------------------------------------------------------------------------ |
| 21 | + |
| 22 | +distributed actor SerReqNotCodable { |
| 23 | + typealias ActorSystem = FakeCustomSerializationRoundtripActorSystem |
| 24 | +} |
| 25 | +func test_NotAtAll_NoImplicit(_ actor: SerReqNotCodable) { |
| 26 | + let _: any Codable = actor // OK, the ID was Codable, even though SerializationRequirement was something else |
| 27 | + |
| 28 | + // no implicit conformance |
| 29 | + let _: any CustomSerializationProtocol = actor // expected-error{{value of type 'SerReqNotCodable' does not conform to specified type 'CustomSerializationProtocol'}} |
| 30 | +} |
| 31 | + |
| 32 | +// ==== ------------------------------------------------------------------------ |
| 33 | + |
| 34 | +distributed actor NotAtAll_NothingCodable { |
| 35 | + typealias ActorSystem = FakeIdIsNotCodableActorSystem |
| 36 | +} |
| 37 | +func test_NotAtAll_NoImplicit(_ actor: NotAtAll_NothingCodable) { |
| 38 | + let _: any Codable = actor // expected-error{{value of type 'NotAtAll_NothingCodable' does not conform to specified type 'Decodable'}} |
| 39 | + |
| 40 | + // no implicit conformance |
| 41 | + let _: any CustomSerializationProtocol = actor // expected-error{{value of type 'NotAtAll_NothingCodable' does not conform to specified type 'CustomSerializationProtocol'}} |
| 42 | +} |
| 43 | + |
| 44 | +public struct NotCodableID: Sendable, Hashable {} |
| 45 | + |
| 46 | +@available(SwiftStdlib 5.7, *) |
| 47 | +public struct FakeIdIsNotCodableActorSystem: DistributedActorSystem, CustomStringConvertible { |
| 48 | + public typealias ActorID = NotCodableID |
| 49 | + public typealias InvocationDecoder = FakeInvocationDecoder |
| 50 | + public typealias InvocationEncoder = FakeInvocationEncoder |
| 51 | + public typealias SerializationRequirement = Codable |
| 52 | + public typealias ResultHandler = FakeRoundtripResultHandler |
| 53 | + |
| 54 | + // just so that the struct does not become "trivial" |
| 55 | + let someValue: String = "" |
| 56 | + let someValue2: String = "" |
| 57 | + let someValue3: String = "" |
| 58 | + let someValue4: String = "" |
| 59 | + |
| 60 | + public init() { |
| 61 | + } |
| 62 | + |
| 63 | + public func resolve<Act>(id: ActorID, as actorType: Act.Type) throws -> Act? |
| 64 | + where Act: DistributedActor, |
| 65 | + Act.ID == ActorID { |
| 66 | + nil |
| 67 | + } |
| 68 | + |
| 69 | + public func assignID<Act>(_ actorType: Act.Type) -> ActorID |
| 70 | + where Act: DistributedActor, |
| 71 | + Act.ID == ActorID { |
| 72 | + .init() |
| 73 | + } |
| 74 | + |
| 75 | + public func actorReady<Act>(_ actor: Act) |
| 76 | + where Act: DistributedActor, |
| 77 | + Act.ID == ActorID { |
| 78 | + } |
| 79 | + |
| 80 | + public func resignID(_ id: ActorID) { |
| 81 | + } |
| 82 | + |
| 83 | + public func makeInvocationEncoder() -> InvocationEncoder { |
| 84 | + .init() |
| 85 | + } |
| 86 | + |
| 87 | + public func remoteCall<Act, Err, Res>( |
| 88 | + on actor: Act, |
| 89 | + target: RemoteCallTarget, |
| 90 | + invocation invocationEncoder: inout InvocationEncoder, |
| 91 | + throwing: Err.Type, |
| 92 | + returning: Res.Type |
| 93 | + ) async throws -> Res |
| 94 | + where Act: DistributedActor, |
| 95 | + Act.ID == ActorID, |
| 96 | + Err: Error, |
| 97 | + Res: SerializationRequirement { |
| 98 | + throw ExecuteDistributedTargetError(message: "\(#function) not implemented.") |
| 99 | + } |
| 100 | + |
| 101 | + public func remoteCallVoid<Act, Err>( |
| 102 | + on actor: Act, |
| 103 | + target: RemoteCallTarget, |
| 104 | + invocation invocationEncoder: inout InvocationEncoder, |
| 105 | + throwing: Err.Type |
| 106 | + ) async throws |
| 107 | + where Act: DistributedActor, |
| 108 | + Act.ID == ActorID, |
| 109 | + Err: Error { |
| 110 | + throw ExecuteDistributedTargetError(message: "\(#function) not implemented.") |
| 111 | + } |
| 112 | + |
| 113 | + public nonisolated var description: Swift.String { |
| 114 | + "\(Self.self)()" |
| 115 | + } |
| 116 | +} |
0 commit comments