|
| 1 | +// RUN: %empty-directory(%t) |
| 2 | +// RUN: %target-swift-frontend-emit-module -emit-module-path %t/FakeDistributedActorSystems.swiftmodule \ |
| 3 | +// RUN: -module-name FakeDistributedActorSystems -target %target-swift-5.7-abi-triple \ |
| 4 | +// RUN: %S/../Inputs/FakeDistributedActorSystems.swift |
| 5 | + |
| 6 | +// RUN: %target-build-swift -module-name main -enable-upcoming-feature NonisolatedNonsendingByDefault \ |
| 7 | +// RUN: -target %target-swift-5.7-abi-triple -j2 -parse-as-library -I %t %s \ |
| 8 | +// RUN: %S/../Inputs/FakeDistributedActorSystems.swift -o %t/a.out |
| 9 | + |
| 10 | +// RUN: %target-codesign %t/a.out |
| 11 | +// RUN: %target-run %t/a.out | %FileCheck %s --enable-var-scope |
| 12 | + |
| 13 | +// REQUIRES: swift_feature_NonisolatedNonsendingByDefault |
| 14 | + |
| 15 | +// REQUIRES: executable_test |
| 16 | +// REQUIRES: concurrency |
| 17 | +// REQUIRES: distributed |
| 18 | + |
| 19 | +// rdar://76038845 |
| 20 | +// UNSUPPORTED: use_os_stdlib |
| 21 | +// UNSUPPORTED: back_deployment_runtime |
| 22 | + |
| 23 | +// FIXME(distributed): Distributed actors currently have some issues on windows, isRemote always returns false. rdar://82593574 |
| 24 | +// UNSUPPORTED: OS=windows-msvc |
| 25 | + |
| 26 | +import Distributed |
| 27 | +import FakeDistributedActorSystems |
| 28 | + |
| 29 | +typealias DefaultDistributedActorSystem = FakeRoundtripActorSystem |
| 30 | + |
| 31 | +distributed actor Greeter: CustomStringConvertible { |
| 32 | + distributed func echo(name: String) -> String { |
| 33 | + return "Echo: \(name) (impl on: \(self.id))" |
| 34 | + } |
| 35 | + |
| 36 | + nonisolated var description: String { |
| 37 | + "\(Self.self)(\(id))" |
| 38 | + } |
| 39 | +} |
| 40 | + |
| 41 | +extension Greeter { |
| 42 | + distributed func echoInExtension(name: String) -> String { |
| 43 | + return "Echo: \(name) (impl on: \(self.id))" |
| 44 | + } |
| 45 | +} |
| 46 | + |
| 47 | +nonisolated extension Greeter { |
| 48 | + distributed func echoInNonisolatedExtension(name: String) -> String { |
| 49 | + return "Echo: \(name) (impl on: \(self.id))" |
| 50 | + } |
| 51 | +} |
| 52 | + |
| 53 | +struct SomeError: Error {} |
| 54 | + |
| 55 | +// ==== Test ------------------------------------------------------------------- |
| 56 | + |
| 57 | +func test() async throws { |
| 58 | + let system = DefaultDistributedActorSystem() |
| 59 | + |
| 60 | + let local = Greeter(actorSystem: system) |
| 61 | + let ref = try Greeter.resolve(id: local.id, using: system) |
| 62 | + |
| 63 | + let reply = try await ref.echo(name: "Caplin") |
| 64 | + // CHECK: > encode argument name:name, value: Caplin |
| 65 | + // CHECK-NOT: > encode error type |
| 66 | + // CHECK: > encode return type: Swift.String |
| 67 | + // CHECK: > done recording |
| 68 | + // CHECK: >> remoteCall |
| 69 | + // CHECK: > decode return type: Swift.String |
| 70 | + // CHECK: > decode argument: Caplin |
| 71 | + // CHECK: << onReturn: Echo: Caplin (impl on: ActorAddress(address: "<unique-id>")) |
| 72 | + |
| 73 | + print("got: \(reply)") |
| 74 | + // CHECK: got: Echo: Caplin (impl on: ActorAddress(address: "<unique-id>")) |
| 75 | + |
| 76 | + // just double check there's no surprises with distributed thunks in extensions |
| 77 | + _ = try await ref.echoInExtension(name: "Bob") |
| 78 | + _ = try await ref.echoInNonisolatedExtension(name: "Alice") |
| 79 | + |
| 80 | + print("OK") // CHECK: OK |
| 81 | +} |
| 82 | + |
| 83 | +@main struct Main { |
| 84 | + static func main() async { |
| 85 | + try! await test() |
| 86 | + } |
| 87 | +} |
0 commit comments