1+ // RUN: %target-run-simple-swift( -Xfrontend -disable-availability-checking -Xfrontend -enable-experimental-distributed -parse-as-library) | %FileCheck %s --dump-input=always
2+
3+ // REQUIRES: executable_test
4+ // REQUIRES: concurrency
5+ // REQUIRES: distributed
6+
7+ // rdar://76038845
8+ // UNSUPPORTED: use_os_stdlib
9+ // UNSUPPORTED: back_deployment_runtime
10+
11+ // FIXME(distributed): Distributed actors currently have some issues on windows, isRemote always returns false. rdar://82593574
12+ // UNSUPPORTED: windows
13+
14+ import _Distributed
15+
16+ distributed actor Capybara {
17+ // only the local capybara can do this!
18+ func eat( ) -> String {
19+ " watermelon "
20+ }
21+ }
22+
23+
24+ // ==== Fake Transport ---------------------------------------------------------
25+ @available ( SwiftStdlib 5 . 5 , * )
26+ struct ActorAddress : ActorIdentity {
27+ let address : String
28+ init ( parse address: String ) {
29+ self . address = address
30+ }
31+ }
32+
33+ @available ( SwiftStdlib 5 . 5 , * )
34+ struct FakeTransport : ActorTransport {
35+ func decodeIdentity( from decoder: Decoder ) throws -> AnyActorIdentity {
36+ fatalError ( " not implemented: \( #function) " )
37+ }
38+
39+ func resolve< Act> ( _ identity: AnyActorIdentity , as actorType: Act . Type )
40+ throws -> Act ? where Act: DistributedActor {
41+ return nil
42+ }
43+
44+ func assignIdentity< Act> ( _ actorType: Act . Type ) -> AnyActorIdentity
45+ where Act: DistributedActor {
46+ let id = ActorAddress ( parse: " xxx " )
47+ return . init( id)
48+ }
49+
50+ func actorReady< Act> ( _ actor : Act ) where Act: DistributedActor {
51+ }
52+
53+ func resignIdentity( _ id: AnyActorIdentity ) {
54+ }
55+ }
56+
57+ func test( ) async throws {
58+ let transport = FakeTransport ( )
59+
60+ let local = Capybara ( transport: transport)
61+ // await local.eat() // SHOULD ERROR
62+ let valueWhenLocal : String ? = await local. whenLocal { __secretlyKnownToBeLocal in
63+ __secretlyKnownToBeLocal. eat ( )
64+ }
65+
66+ // CHECK: valueWhenLocal: watermelon
67+ print ( " valueWhenLocal: \( valueWhenLocal ?? " nil " ) " )
68+
69+ let remote = try Capybara . resolve ( local. id, using: transport)
70+ let valueWhenRemote : String ? = await remote. whenLocal { __secretlyKnownToBeLocal in
71+ __secretlyKnownToBeLocal. eat ( )
72+ }
73+
74+ // CHECK: valueWhenRemote: nil
75+ print ( " valueWhenRemote: \( valueWhenRemote ?? " nil " ) " )
76+ }
77+
78+ @available ( SwiftStdlib 5 . 5 , * )
79+ @main struct Main {
80+ static func main( ) async {
81+ try ! await test ( )
82+ }
83+ }
0 commit comments