|
| 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-build-swift -module-name main -Xfrontend -disable-availability-checking -j2 -parse-as-library -I %t %s %S/../Inputs/FakeDistributedActorSystems.swift -o %t/a.out |
| 4 | +// RUN: %target-codesign %t/a.out |
| 5 | +// RUN: %target-run %t/a.out | %FileCheck %s --color --dump-input=always |
| 6 | + |
| 7 | +// REQUIRES: executable_test |
| 8 | +// REQUIRES: concurrency |
| 9 | +// REQUIRES: distributed |
| 10 | + |
| 11 | +// UNSUPPORTED: use_os_stdlib |
| 12 | +// UNSUPPORTED: back_deployment_runtime |
| 13 | + |
| 14 | +import Distributed |
| 15 | +typealias DefaultDistributedActorSystem = FakeRoundtripActorSystem |
| 16 | + |
| 17 | +@propertyWrapper |
| 18 | +struct Validate { |
| 19 | + // TODO: we can't throw from here, but if we could, this would be ideal for throwing validation |
| 20 | + // Today we can fatalError here if we wanted to though. |
| 21 | + init(wrappedValue: Int, in range: ClosedRange<Int>) { |
| 22 | + //precondition(range.contains(wrappedValue), "Value [\(wrappedValue)] did not fit required range \(range)") |
| 23 | + if !range.contains(wrappedValue) { |
| 24 | + print("VALIDATION WARNING: Value [\(wrappedValue)] did not fit required range \(range)") |
| 25 | + } |
| 26 | + } |
| 27 | + |
| 28 | + var wrappedValue: Int { |
| 29 | + 12 |
| 30 | + } |
| 31 | +} |
| 32 | + |
| 33 | +distributed actor CheckTheNums { |
| 34 | + |
| 35 | + distributed func check(@Validate(in: 1...100) num: Int) { |
| 36 | + let i: Int = num |
| 37 | + _ = i |
| 38 | + } |
| 39 | +} |
| 40 | + |
| 41 | +// ==== Execute ---------------------------------------------------------------- |
| 42 | + |
| 43 | +func test() async throws { |
| 44 | + let system = DefaultDistributedActorSystem() |
| 45 | + |
| 46 | + let da = CheckTheNums(actorSystem: system) |
| 47 | +// try await da.check(num: 1000) |
| 48 | + |
| 49 | + let remote = try CheckTheNums.resolve(id: da.id, using: system) |
| 50 | + try await remote.check(num: 10000) |
| 51 | + |
| 52 | + // CHECK: > execute distributed target: main.CheckTheNums.check(num:) |
| 53 | + // CHECK: > decode argument: 10000 |
| 54 | + // CHECK: VALIDATION WARNING: Value [10000] did not fit required range 1...100 |
| 55 | + |
| 56 | + // CHECK: OK |
| 57 | + print("OK") |
| 58 | +} |
| 59 | + |
| 60 | +@main struct Main { |
| 61 | + static func main() async throws { |
| 62 | + try await test() |
| 63 | + } |
| 64 | +} |
0 commit comments