File: distributed_serializationRequirement_must_be_protocol.swift

package info (click to toggle)
swiftlang 6.1.3-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,791,644 kB
  • sloc: cpp: 9,901,738; ansic: 2,201,433; asm: 1,091,827; python: 308,252; objc: 82,166; f90: 80,126; lisp: 38,358; pascal: 25,559; sh: 20,429; ml: 5,058; perl: 4,745; makefile: 4,484; awk: 3,535; javascript: 3,018; xml: 918; fortran: 664; cs: 573; ruby: 396
file content (132 lines) | stat: -rw-r--r-- 5,786 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend-emit-module -emit-module-path %t/FakeDistributedActorSystems.swiftmodule -module-name FakeDistributedActorSystems -target %target-swift-5.7-abi-triple %S/Inputs/FakeDistributedActorSystems.swift
// RUN: %target-swift-frontend -typecheck -verify -verify-ignore-unknown -target %target-swift-5.7-abi-triple -I %t 2>&1 %s
// REQUIRES: concurrency
// REQUIRES: distributed

import Distributed
import FakeDistributedActorSystems

final class SomeClazz: Sendable {}
final class SomeStruct: Sendable {}
final class SomeEnum: Sendable {}

// TODO(distributed): improve to diagnose ON the typealias rather than on the system
// expected-error@+1{{'SerializationRequirement' type witness 'System.SerializationRequirement' (aka 'SomeClazz') must be a protocol type}}
final class System: DistributedActorSystem {
  // ignore those since they all fail with the SerializationRequirement being invalid:
  // expected-error@-2{{type 'System' does not conform to protocol 'DistributedActorSystem'}}
  // expected-note@-3{{add stubs for conformance}}
  // expected-error@-4{{class 'System' is missing witness for protocol requirement 'remoteCall'}}
  // expected-note@-5{{add stubs for conformance}}
  // expected-error@-6{{class 'System' is missing witness for protocol requirement 'remoteCallVoid'}}
  // expected-note@-7{{add stubs for conformance}}
  typealias ActorID = String
  typealias InvocationEncoder = ClassInvocationEncoder
  typealias InvocationDecoder = ClassInvocationDecoder

  typealias ResultHandler = DistributedTargetInvocationResultHandler
  // expected-note@-1{{possibly intended match 'System.ResultHandler' (aka 'DistributedTargetInvocationResultHandler') does not conform to 'DistributedTargetInvocationResultHandler'}}

  typealias SerializationRequirement = SomeClazz

  func resolve<Act>(id: ActorID, as actorType: Act.Type)
    throws -> Act? where Act: DistributedActor {
    fatalError()
  }

  func assignID<Act>(_ actorType: Act.Type) -> ActorID
    where Act: DistributedActor {
    fatalError()
  }

  func actorReady<Act>(_ actor: Act)
    where Act: DistributedActor,
    Act.ID == ActorID {
    fatalError()
  }

  func resignID(_ id: ActorID) {
    fatalError()
  }

  func makeInvocationEncoder() -> InvocationEncoder {
    fatalError()
  }

  // expected-note@+1 {{candidate has non-matching type '<Act, Err, Res> (on: Act, target: RemoteCallTarget, invocation: inout System.InvocationEncoder, throwing: Err.Type, returning: Res.Type) async throws -> Res' (aka '<Act, Err, Res> (on: Act, target: RemoteCallTarget, invocation: inout ClassInvocationEncoder, throwing: Err.Type, returning: Res.Type) async throws -> Res') [with ResultHandler = <<error type>>]}}
  func remoteCall<Act, Err, Res>(
    on actor: Act,
    target: RemoteCallTarget,
    invocation: inout InvocationEncoder,
    throwing errorType: Err.Type,
    returning returnType: Res.Type
  ) async throws -> Res
    where Act: DistributedActor,
    Act.ID == ActorID,
    Err: Error,
    Res: SerializationRequirement {
    fatalError()
  }

  func remoteCallVoid<Act, Err>(
    on actor: Act,
    target: RemoteCallTarget,
    invocation: inout InvocationEncoder,
    throwing errorType: Err.Type
  ) async throws
    where Act: DistributedActor,
    Act.ID == ActorID,
    Err: Error {
    fatalError()
  }
}

struct ClassInvocationEncoder: DistributedTargetInvocationEncoder { // expected-error {{type 'ClassInvocationEncoder' does not conform to protocol 'DistributedTargetInvocationEncoder'}}
  // expected-note@-1{{add stubs for conformance}}
  // expected-error@-2{{struct 'ClassInvocationEncoder' is missing witness for protocol requirement 'recordArgument'}}
  // expected-note@-3{{add stubs for conformance}}
  // expected-error@-4{{struct 'ClassInvocationEncoder' is missing witness for protocol requirement 'recordReturnType'}}
  // expected-note@-5{{add stubs for conformance}}
  typealias SerializationRequirement = SomeClazz

  public mutating func recordGenericSubstitution<T>(_ type: T.Type) throws {}
  // expected-note@+1 {{candidate has non-matching type '<Value> (RemoteCallArgument<Value>) throws -> ()'}}
  public mutating func recordArgument<Value: SerializationRequirement>(
    _ argument: RemoteCallArgument<Value>) throws {}
  public mutating func recordErrorType<E: Error>(_ type: E.Type) throws {}
  // expected-note@+1 {{candidate has non-matching type '<R> (R.Type) throws -> ()'}}
  public mutating func recordReturnType<R: SerializationRequirement>(_ type: R.Type) throws {}
  public mutating func doneRecording() throws {}
}

final class ClassInvocationDecoder: DistributedTargetInvocationDecoder { // expected-error {{type 'ClassInvocationDecoder' does not conform to protocol 'DistributedTargetInvocationDecoder'}}
  // expected-note@-1{{add stubs for conformance}}
  // expected-error@-2{{class 'ClassInvocationDecoder' is missing witness for protocol requirement 'decodeNextArgument'}}
  // expected-note@-3{{add stubs for conformance}}
  typealias SerializationRequirement = SomeClazz

  public func decodeGenericSubstitutions() throws -> [Any.Type] {
    fatalError()
  }

  // expected-note@+1 {{candidate has non-matching type '<Argument> () throws -> Argument'}}
  public func decodeNextArgument<Argument: SerializationRequirement>() throws -> Argument {
    fatalError()
  }

  public func decodeErrorType() throws -> Any.Type? {
    fatalError()
  }

  public func decodeReturnType() throws -> Any.Type? {
    fatalError()
  }
}

struct DistributedTargetInvocationResultHandler {
  typealias SerializationRequirement = SomeClazz
  func onReturn<Success: SomeClazz>(value: Success) async throws {}
  func onReturnVoid() async throws {}
  func onThrow<Err: Error>(error: Err) async throws {}
}