|
| 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 -parse-as-library -swift-version 6 -target %target-swift-abi-5.9-triple -I %t %s %S/../Inputs/FakeDistributedActorSystems.swift %S/../Inputs/CustomSerialExecutorAvailability.swift -o %t/a.out |
| 4 | +// RUN: %target-codesign %t/a.out |
| 5 | +// RUN: %target-run %t/a.out |
| 6 | + |
| 7 | +// REQUIRES: executable_test |
| 8 | +// REQUIRES: concurrency |
| 9 | +// REQUIRES: distributed |
| 10 | +// REQUIRES: concurrency_runtime |
| 11 | +// UNSUPPORTED: back_deployment_runtime |
| 12 | + |
| 13 | +// UNSUPPORTED: back_deploy_concurrency |
| 14 | +// UNSUPPORTED: use_os_stdlib |
| 15 | +// UNSUPPORTED: freestanding |
| 16 | + |
| 17 | +//import StdlibUnittest |
| 18 | +import Distributed |
| 19 | + |
| 20 | +@available(SwiftStdlib 5.9, *) |
| 21 | +distributed |
| 22 | + actor Tester { |
| 23 | + |
| 24 | + typealias ActorSystem = LocalTestingDistributedActorSystem |
| 25 | + |
| 26 | + distributed |
| 27 | + func check() async { |
| 28 | + pass() |
| 29 | + passOptional() // should work, but fails to infer that #isolation is the same as "self" |
| 30 | + |
| 31 | + pass(isolatedToActor: self.asLocalActor) |
| 32 | + passOptional(isolatedToActor: self.asLocalActor) |
| 33 | + |
| 34 | + // Not supported: the parameter must be exactly the 'self.asLocalActor' |
| 35 | + // as otherwise we don't know where the value came from and if it's really |
| 36 | + // self we're calling from; We'd need more sophisticated analysis to make it work. |
| 37 | + // let myself = self.asLocalActor |
| 38 | + // pass(isolatedToActor: myself) // same |
| 39 | + } |
| 40 | +} |
| 41 | + |
| 42 | +@available(SwiftStdlib 5.9, *) |
| 43 | +func passOptional(isolatedToActor: isolated (any Actor)? = #isolation) { |
| 44 | + isolatedToActor!.preconditionIsolated("Expected to be executing on actor \(isolatedToActor!)") |
| 45 | +} |
| 46 | + |
| 47 | +@available(SwiftStdlib 5.9, *) |
| 48 | +func pass(isolatedToActor: isolated (any Actor) = #isolation) { |
| 49 | + isolatedToActor.preconditionIsolated("Expected to be executing on actor \(isolatedToActor)") |
| 50 | +} |
| 51 | + |
| 52 | +@main struct Main { |
| 53 | + static func main() async { |
| 54 | + if #available(SwiftStdlib 5.9, *) { |
| 55 | + let system = LocalTestingDistributedActorSystem() |
| 56 | + let tester = Tester(actorSystem: system) |
| 57 | + |
| 58 | + try! await tester.check() |
| 59 | + } |
| 60 | + } |
| 61 | +} |
0 commit comments