1- // RUN: %target-run-simple-swift(-Xfrontend -enable-experimental-distributed -parse-as-library) | %FileCheck %s --dump-input=always
1+ // RUN: %target-run-simple-swift(-Xfrontend -disable-availability-checking -Xfrontend - enable-experimental-distributed -parse-as-library) | %FileCheck %s --dump-input=always
22
33// REQUIRES: executable_test
44// REQUIRES: concurrency
@@ -41,6 +41,31 @@ distributed actor SomeSpecificDistributedActor {
4141 " local( \( #function) ) "
4242 }
4343
44+ distributed func callTaskSelf_inner( ) async throws -> String {
45+ " local( \( #function) ) "
46+ }
47+ distributed func callTaskSelf( ) async -> String {
48+ do {
49+ return try await Task {
50+ let called = try await callTaskSelf_inner ( ) // shouldn't use the distributed thunk!
51+ return " local( \( #function) ) -> \( called) "
52+ } . value
53+ } catch {
54+ return " WRONG local( \( #function) ) thrown( \( error) ) "
55+ }
56+ }
57+
58+ distributed func callDetachedSelf( ) async -> String {
59+ do {
60+ return try await Task . detached {
61+ let called = try await self . callTaskSelf_inner ( ) // shouldn't use the distributed thunk!
62+ return " local( \( #function) ) -> \( called) "
63+ } . value
64+ } catch {
65+ return " WRONG local( \( #function) ) thrown( \( error) ) "
66+ }
67+ }
68+
4469 // === errors
4570
4671 distributed func helloThrowsImplBoom( ) throws -> String {
@@ -74,6 +99,21 @@ extension SomeSpecificDistributedActor {
7499 " remote( \( #function) ) "
75100 }
76101
102+ @_dynamicReplacement ( for: _remote_callTaskSelf ( ) )
103+ nonisolated func _remote_impl_callTaskSelf( ) async throws -> String {
104+ " remote( \( #function) ) "
105+ }
106+
107+ @_dynamicReplacement ( for: _remote_callDetachedSelf ( ) )
108+ nonisolated func _remote_impl_callDetachedSelf( ) async throws -> String {
109+ " remote( \( #function) ) "
110+ }
111+
112+ @_dynamicReplacement ( for: _remote_callTaskSelf_inner ( ) )
113+ nonisolated func _remote_impl_callTaskSelf_inner( ) async throws -> String {
114+ " remote( \( #function) ) "
115+ }
116+
77117 // === errors
78118
79119 @_dynamicReplacement ( for: _remote_helloThrowsImplBoom ( ) )
@@ -101,9 +141,6 @@ func __isLocalActor(_ actor: AnyObject) -> Bool {
101141@available ( SwiftStdlib 5 . 5 , * )
102142struct ActorAddress : ActorIdentity {
103143 let address : String
104- init ( parse address : String ) {
105- self . address = address
106- }
107144}
108145
109146@available ( SwiftStdlib 5 . 5 , * )
@@ -120,7 +157,7 @@ struct FakeTransport: ActorTransport {
120157
121158 func assignIdentity< Act> ( _ actorType: Act . Type ) -> AnyActorIdentity
122159 where Act: DistributedActor {
123- . init( ActorAddress ( parse : " " ) )
160+ . init( ActorAddress ( address : " " ) )
124161 }
125162
126163 func actorReady< Act> ( _ actor : Act ) where Act: DistributedActor {
@@ -149,6 +186,12 @@ func test_remote_invoke(address: ActorAddress, transport: ActorTransport) async
149186 let h4 = try ! await actor . hello ( )
150187 print ( " \( personality) - hello: \( h4) " )
151188
189+ let h5 = try ! await actor . callTaskSelf ( )
190+ print ( " \( personality) - callTaskSelf: \( h5) " )
191+
192+ let h6 = try ! await actor . callDetachedSelf ( )
193+ print ( " \( personality) - callDetachedSelf: \( h6) " )
194+
152195 // error throws
153196 if __isRemoteActor ( actor ) {
154197 do {
@@ -180,6 +223,8 @@ func test_remote_invoke(address: ActorAddress, transport: ActorTransport) async
180223 // CHECK: local - helloAsync: local(helloAsync())
181224 // CHECK: local - helloThrows: local(helloThrows())
182225 // CHECK: local - hello: local(hello())
226+ // CHECK: local - callTaskSelf: local(callTaskSelf()) -> local(callTaskSelf_inner())
227+ // CHECK: local - callDetachedSelf: local(callDetachedSelf()) -> local(callTaskSelf_inner())
183228 // CHECK: local - helloThrowsImplBoom: Boom(whoFailed: "impl")
184229
185230 print ( " remote isRemote: \( __isRemoteActor ( remote) ) " )
@@ -189,6 +234,8 @@ func test_remote_invoke(address: ActorAddress, transport: ActorTransport) async
189234 // CHECK: remote - helloAsync: remote(_remote_impl_helloAsync())
190235 // CHECK: remote - helloThrows: remote(_remote_impl_helloThrows())
191236 // CHECK: remote - hello: remote(_remote_impl_hello())
237+ // CHECK: remote - callTaskSelf: remote(_remote_impl_callTaskSelf())
238+ // CHECK: remote - callDetachedSelf: remote(_remote_impl_callDetachedSelf())
192239 // CHECK: remote - helloThrowsTransportBoom: Boom(whoFailed: "transport")
193240
194241 print ( local)
@@ -198,7 +245,7 @@ func test_remote_invoke(address: ActorAddress, transport: ActorTransport) async
198245@available ( SwiftStdlib 5 . 5 , * )
199246@main struct Main {
200247 static func main( ) async {
201- let address = ActorAddress ( parse : " " )
248+ let address = ActorAddress ( address : " " )
202249 let transport = FakeTransport ( )
203250
204251 await test_remote_invoke ( address: address, transport: transport)
0 commit comments