|
| 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 -verify-ignore-unknown -disable-availability-checking -I %t 2>&1 %s |
| 4 | +// REQUIRES: concurrency |
| 5 | +// REQUIRES: distributed |
| 6 | + |
| 7 | +import Distributed |
| 8 | +import FakeDistributedActorSystems |
| 9 | + |
| 10 | +final class SomeClazz: Sendable {} |
| 11 | +final class SomeStruct: Sendable {} |
| 12 | +final class SomeEnum: Sendable {} |
| 13 | + |
| 14 | +// TODO(distributed): improve to diagnose ON the typealias rather than on the system |
| 15 | +// expected-error@+1{{'SerializationRequirement' type witness 'System.SerializationRequirement' (aka 'SomeClazz') must be a protocol type}} |
| 16 | +final class System: DistributedActorSystem { |
| 17 | + // ignore those since they all fail with the SerializationRequirement being invalid: |
| 18 | + // expected-error@-2{{type 'System' does not conform to protocol 'DistributedActorSystem'}} |
| 19 | + // expected-note@-3{{protocol 'System' requires function 'remoteCallVoid'}} |
| 20 | + // expected-error@-4{{class 'System' is missing witness for protocol requirement 'remoteCall'}} |
| 21 | + // expected-note@-5{{protocol 'System' requires function 'remoteCall' with signature:}} |
| 22 | + // expected-error@-6{{class 'System' is missing witness for protocol requirement 'remoteCallVoid'}} |
| 23 | + typealias ActorID = String |
| 24 | + typealias InvocationEncoder = ClassInvocationEncoder |
| 25 | + typealias InvocationDecoder = ClassInvocationDecoder |
| 26 | + |
| 27 | + typealias ResultHandler = DistributedTargetInvocationResultHandler |
| 28 | + // expected-note@-1{{possibly intended match 'System.ResultHandler' (aka 'DistributedTargetInvocationResultHandler') does not conform to 'DistributedTargetInvocationResultHandler'}} |
| 29 | + |
| 30 | + typealias SerializationRequirement = SomeClazz |
| 31 | + |
| 32 | + func resolve<Act>(id: ActorID, as actorType: Act.Type) |
| 33 | + throws -> Act? where Act: DistributedActor { |
| 34 | + fatalError() |
| 35 | + } |
| 36 | + |
| 37 | + func assignID<Act>(_ actorType: Act.Type) -> ActorID |
| 38 | + where Act: DistributedActor { |
| 39 | + fatalError() |
| 40 | + } |
| 41 | + |
| 42 | + func actorReady<Act>(_ actor: Act) |
| 43 | + where Act: DistributedActor, |
| 44 | + Act.ID == ActorID { |
| 45 | + fatalError() |
| 46 | + } |
| 47 | + |
| 48 | + func resignID(_ id: ActorID) { |
| 49 | + fatalError() |
| 50 | + } |
| 51 | + |
| 52 | + func makeInvocationEncoder() -> InvocationEncoder { |
| 53 | + fatalError() |
| 54 | + } |
| 55 | + |
| 56 | + func remoteCall<Act, Err, Res>( |
| 57 | + on actor: Act, |
| 58 | + target: RemoteCallTarget, |
| 59 | + invocation: inout InvocationEncoder, |
| 60 | + throwing errorType: Err.Type, |
| 61 | + returning returnType: Res.Type |
| 62 | + ) async throws -> Res |
| 63 | + where Act: DistributedActor, |
| 64 | + Act.ID == ActorID, |
| 65 | + Err: Error, |
| 66 | + Res: SerializationRequirement { |
| 67 | + fatalError() |
| 68 | + } |
| 69 | + |
| 70 | + func remoteCallVoid<Act, Err>( |
| 71 | + on actor: Act, |
| 72 | + target: RemoteCallTarget, |
| 73 | + invocation: inout InvocationEncoder, |
| 74 | + throwing errorType: Err.Type |
| 75 | + ) async throws |
| 76 | + where Act: DistributedActor, |
| 77 | + Act.ID == ActorID, |
| 78 | + Err: Error { |
| 79 | + fatalError() |
| 80 | + } |
| 81 | +} |
| 82 | + |
| 83 | +struct ClassInvocationEncoder: DistributedTargetInvocationEncoder { |
| 84 | + // expected-note@-1{{protocol 'ClassInvocationEncoder' requires function 'recordArgument' with signature:}} |
| 85 | + // expected-error@-2{{struct 'ClassInvocationEncoder' is missing witness for protocol requirement 'recordArgument'}} |
| 86 | + // expected-note@-3{{protocol 'ClassInvocationEncoder' requires function 'recordReturnType' with signature:}} |
| 87 | + // expected-error@-4{{struct 'ClassInvocationEncoder' is missing witness for protocol requirement 'recordReturnType'}} |
| 88 | + typealias SerializationRequirement = SomeClazz |
| 89 | + |
| 90 | + public mutating func recordGenericSubstitution<T>(_ type: T.Type) throws {} |
| 91 | + public mutating func recordArgument<Value: SerializationRequirement>( |
| 92 | + _ argument: RemoteCallArgument<Value>) throws {} |
| 93 | + public mutating func recordErrorType<E: Error>(_ type: E.Type) throws {} |
| 94 | + public mutating func recordReturnType<R: SerializationRequirement>(_ type: R.Type) throws {} |
| 95 | + public mutating func doneRecording() throws {} |
| 96 | +} |
| 97 | + |
| 98 | +final class ClassInvocationDecoder: DistributedTargetInvocationDecoder { |
| 99 | + // expected-error@-1{{class 'ClassInvocationDecoder' is missing witness for protocol requirement 'decodeNextArgument'}} |
| 100 | + // expected-note@-2{{protocol 'ClassInvocationDecoder' requires function 'decodeNextArgument'}} |
| 101 | + typealias SerializationRequirement = SomeClazz |
| 102 | + |
| 103 | + public func decodeGenericSubstitutions() throws -> [Any.Type] { |
| 104 | + fatalError() |
| 105 | + } |
| 106 | + |
| 107 | + public func decodeNextArgument<Argument: SerializationRequirement>() throws -> Argument { |
| 108 | + fatalError() |
| 109 | + } |
| 110 | + |
| 111 | + public func decodeErrorType() throws -> Any.Type? { |
| 112 | + fatalError() |
| 113 | + } |
| 114 | + |
| 115 | + public func decodeReturnType() throws -> Any.Type? { |
| 116 | + fatalError() |
| 117 | + } |
| 118 | +} |
| 119 | + |
| 120 | +struct DistributedTargetInvocationResultHandler { |
| 121 | + typealias SerializationRequirement = SomeClazz |
| 122 | + func onReturn<Success: SomeClazz>(value: Success) async throws {} |
| 123 | + func onReturnVoid() async throws {} |
| 124 | + func onThrow<Err: Error>(error: Err) async throws {} |
| 125 | +} |
0 commit comments