File: distributed_actor_protocol_call_resilient_lib.swift

package info (click to toggle)
swiftlang 6.1.3-4
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • 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 (128 lines) | stat: -rw-r--r-- 5,537 bytes parent folder | download | duplicates (2)
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
// RUN: %empty-directory(%t/src)
// RUN: split-file %s %t/src

/// Build the fake actor systems lib
// RUN: %target-build-swift                                                    \
// RUN:     -target %target-swift-5.7-abi-triple                               \
// RUN:     -parse-as-library -emit-library                                    \
// RUN:     -emit-module-path %t/FakeDistributedActorSystems.swiftmodule       \
// RUN:     -module-name FakeDistributedActorSystems                           \
// RUN:      %S/../Inputs/FakeDistributedActorSystems.swift                    \
// RUN:     -enable-library-evolution                                          \
// RUN:     -o %t/%target-library-name(FakeDistributedActorSystems)

/// Build the Lib
// RUN: %target-build-swift                                                    \
// RUN:     -target %target-swift-5.7-abi-triple                               \
// RUN:     -parse-as-library -emit-library                                    \
// RUN:     -emit-module-path %t/ResilientLib.swiftmodule                      \
// RUN:     -module-name ResilientLib                                          \
// RUN:     -I %t                                                              \
// RUN:     -L %t                                                              \
// RUN:     %t/src/ResilientLib.swift                                          \
// RUN:     -enable-library-evolution                                          \
// RUN:     -o %t/%target-library-name(ResilientLib)

/// Build the ActorLib
// RUN: %target-build-swift                                                    \
// RUN:     -target %target-swift-5.7-abi-triple                               \
// RUN:     -parse-as-library -emit-library                                    \
// RUN:     -emit-module-path %t/ResilientActorLib.swiftmodule                 \
// RUN:     -module-name ResilientActorLib                                     \
// RUN:     -I %t                                                              \
// RUN:     -L %t                                                              \
// RUN:     %t/src/ResilientActorLib.swift                                     \
// RUN:     -lFakeDistributedActorSystems                                      \
// RUN:     -lResilientLib                                                     \
// RUN:     -enable-library-evolution                                          \
// RUN:     -o %t/%target-library-name(ResilientActorLib)

/// Build the client
// RUN: %target-build-swift                                                    \
// RUN:     -target %target-swift-5.7-abi-triple                               \
// RUN:     -parse-as-library                                                  \
// RUN:     -lFakeDistributedActorSystems                                      \
// RUN:     -lResilientLib                                                     \
// RUN:     -lResilientActorLib                                                \
// RUN:     -module-name main                                                  \
// RUN:     -I %t                                                              \
// RUN:     -L %t                                                              \
// RUN:     %s                                                                 \
// RUN:     -enable-library-evolution                                          \
// RUN:     -o %t/a.out

// Sign the main binary and all libraries
// RUN: %target-codesign %t/a.out
// RUN: %target-codesign %t/%target-library-name(FakeDistributedActorSystems)
// RUN: %target-codesign %t/%target-library-name(ResilientActorLib)
// RUN: %target-codesign %t/%target-library-name(ResilientLib)

// Run and verify output
// RUN: %target-run %t/a.out                                                   \
// RUN:     %t/%target-library-name(FakeDistributedActorSystems)               \
// RUN:     %t/%target-library-name(ResilientActorLib)                         \
// RUN:     %t/%target-library-name(ResilientLib)                              \
// RUN:     | %FileCheck %s

// REQUIRES: executable_test
// REQUIRES: concurrency
// REQUIRES: distributed

// Locating the built libraries failed on Linux (construction of test case),
// but we primarily care about macOS in this test
// UNSUPPORTED: OS=linux-gnu

// UNSUPPORTED: use_os_stdlib
// UNSUPPORTED: back_deployment_runtime
// UNSUPPORTED: remote_run || device_run

//--- ResilientLib.swift

import Distributed

public protocol SomeProtocol {
  func function() async throws -> String
}

//--- ResilientActorLib.swift

import ResilientLib

import Distributed
import FakeDistributedActorSystems

public distributed actor Impl: SomeProtocol {
  public typealias ActorSystem = FakeRoundtripActorSystem

  public distributed func function() async throws -> String {
    "Success!"
  }
}

//--- Main.swift

import ResilientLib
import ResilientActorLib

import Distributed
import FakeDistributedActorSystems

@main struct Main {
  static func main() async {
    let system = FakeRoundtripActorSystem()

    print("start")

    let impl = Impl(actorSystem: system)

    let anyAct: any SomeProtocol = impl
    let anyReply = try! await anyAct.function()
    print("any reply = \(anyReply)") // CHECK: any reply = Success!

    let proxy: any SomeProtocol = try! Impl.resolve(id: impl.id, using: system)
    let proxyReply = try! await proxy.function()
    print("proxy reply = \(proxyReply)") // CHECK: proxy reply = Success!

    print("done")
  }
}