Skip to content

Commit b4eb81b

Browse files
committed
workaround for #59356 while still implementing the witness feature
1 parent e4332b7 commit b4eb81b

File tree

2 files changed

+86
-12
lines changed

2 files changed

+86
-12
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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 -enable-experimental-distributed -Xfrontend -disable-availability-checking -j2 -parse-as-library -I %t %s %S/../Inputs/FakeDistributedActorSystems.swift -o %t/a.out
4+
// RUN: %target-run %t/a.out | %FileCheck %s --color
5+
6+
// REQUIRES: executable_test
7+
// REQUIRES: concurrency
8+
// REQUIRES: distributed
9+
10+
// rdar://76038845
11+
// UNSUPPORTED: use_os_stdlib
12+
// UNSUPPORTED: back_deployment_runtime
13+
14+
// FIXME(distributed): Distributed actors currently have some issues on windows, isRemote always returns false. rdar://82593574
15+
// UNSUPPORTED: OS=windows-msvc
16+
17+
18+
import Distributed
19+
import FakeDistributedActorSystems
20+
21+
typealias DefaultDistributedActorSystem = FakeRoundtripActorSystem
22+
23+
protocol LifecycleWatch: DistributedActor where ActorSystem == FakeRoundtripActorSystem {
24+
func terminated(actor id: ID) async
25+
}
26+
27+
extension LifecycleWatch {
28+
func watch<T: Codable>(x: Int, _ y: T) async throws {
29+
// nothing here
30+
print("executed: \(#function) - x = \(x), y = \(y)")
31+
}
32+
33+
distributed func test<T: Codable & Sendable>(x: Int, _ y: T) async throws {
34+
print("executed: \(#function)")
35+
try await self.watch(x: x, y)
36+
print("done executed: \(#function)")
37+
}
38+
}
39+
40+
distributed actor Worker: LifecycleWatch {
41+
func terminated(actor id: ID) async {
42+
print("terminated (on \(self.id)): \(id)")
43+
}
44+
}
45+
46+
@main struct Main {
47+
static func main() async {
48+
let worker: any LifecycleWatch = Worker(actorSystem: DefaultDistributedActorSystem())
49+
try! await worker.test(x: 42, "on protocol")
50+
51+
// CHECK: executed: test(x:_:)
52+
// CHECK: executed: watch(x:_:) - x = 42, y = on protocol
53+
// CHECK: done executed: test(x:_:)
54+
55+
// FIXME: Actor isolation getting with generics is pending implementation #59356
56+
do {
57+
let terminatedID = Worker.ID(parse: "<terminated-id>")
58+
let __secretlyKnownToBeLocal = worker
59+
await __secretlyKnownToBeLocal.terminated(actor: terminatedID)
60+
61+
// FIXME: Once the above fixme is solved, use this real code instead:
62+
// _ = await worker.whenLocal { __secretlyKnownToBeLocal in
63+
// let terminatedID = Worker.ID(parse: "<terminated-id>")
64+
// return await __secretlyKnownToBeLocal.terminated(actor: terminatedID)
65+
// }
66+
}
67+
// CHECK: terminated (on ActorAddress(address: "<unique-id>")): ActorAddress(address: "<terminated-id>")
68+
69+
print("OK") // CHECK: OK
70+
}
71+
}

test/Distributed/distributed_protocol_isolation.swift

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,7 @@ protocol TerminationWatchingA {
178178
}
179179

180180
protocol TerminationWatchingDA: DistributedActor {
181-
func terminated(da: String) async
182-
// expected-note@-1{{distributed actor-isolated instance method 'terminated(da:)' declared here}}
183-
// expected-note@-2{{distributed actor-isolated instance method 'terminated(da:)' declared here}}
181+
func terminated(da: String) async // expected-note 3 {{distributed actor-isolated instance method 'terminated(da:)' declared here}}
184182
}
185183

186184
actor A_TerminationWatchingA: TerminationWatchingA {
@@ -212,21 +210,26 @@ func test_watchingDA<WDA: TerminationWatchingDA>(da: WDA) async throws {
212210
// expected-error@-1{{only 'distributed' instance methods can be called on a potentially remote distributed actor}}
213211
// expected-warning@-2{{no calls to throwing functions occur within 'try' expression}}
214212

215-
// // FIXME: pending fix of closure isolation checking with actors #59356
216-
// await da.whenLocal { __secretlyKnownToBeLocal in
217-
// await __secretlyKnownToBeLocal.terminated(da: "local calls are okey!") // OK
218-
// }
213+
let __secretlyKnownToBeLocal = da
214+
await __secretlyKnownToBeLocal.terminated(da: "local calls are okey!") // OK // FIXME(#59356): (the __secretlyKnown is a hack, but the whenLocal crashes now on pending isolation getting with generic actors for closures)
215+
// FIXME: pending fix of closure isolation checking with actors #59356
216+
// await da.whenLocal { __secretlyKnownToBeLocal in
217+
// await __secretlyKnownToBeLocal.terminated(da: "local calls are okey!") // OK
218+
// }
219219
}
220220

221221
func test_watchingDA_erased(da: DA_TerminationWatchingDA) async throws {
222-
let wda: TerminationWatchingDA = da
223-
try await wda.terminated(wda: "the terminated func is not distributed")
222+
let wda: any TerminationWatchingDA = da
223+
try await wda.terminated(da: "the terminated func is not distributed")
224224
// expected-error@-1{{only 'distributed' instance methods can be called on a potentially remote distributed actor}}
225225
// expected-warning@-2{{no calls to throwing functions occur within 'try' expression}}
226226

227-
await wda.whenLocal { __secretlyKnownToBeLocal in
228-
await __secretlyKnownToBeLocal.terminated(da: "local calls are okey!") // OK
229-
}
227+
let __secretlyKnownToBeLocal = wda
228+
await __secretlyKnownToBeLocal.terminated(da: "local calls are okey!") // OK // OK // FIXME(#59356): (the __secretlyKnown is a hack, but the whenLocal crashes now on pending isolation getting with generic actors for closures)
229+
// FIXME: pending fix of closure isolation checking with actors #59356
230+
// await wda.whenLocal { __secretlyKnownToBeLocal in
231+
// await __secretlyKnownToBeLocal.terminated(da: "local calls are okey!") // OK
232+
// }
230233
}
231234

232235
func test_watchingDA_any(da: any TerminationWatchingDA) async throws {

0 commit comments

Comments
 (0)