Skip to content

Commit 911b42f

Browse files
committed
workaround for swiftlang#59356 while still implementing the witness feature
1 parent bd052ee commit 911b42f

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
@@ -179,9 +179,7 @@ protocol TerminationWatchingA {
179179
}
180180

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

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

216-
// // FIXME: pending fix of closure isolation checking with actors #59356
217-
// await da.whenLocal { __secretlyKnownToBeLocal in
218-
// await __secretlyKnownToBeLocal.terminated(da: "local calls are okey!") // OK
219-
// }
214+
let __secretlyKnownToBeLocal = da
215+
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)
216+
// FIXME: pending fix of closure isolation checking with actors #59356
217+
// await da.whenLocal { __secretlyKnownToBeLocal in
218+
// await __secretlyKnownToBeLocal.terminated(da: "local calls are okey!") // OK
219+
// }
220220
}
221221

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

228-
await wda.whenLocal { __secretlyKnownToBeLocal in
229-
await __secretlyKnownToBeLocal.terminated(da: "local calls are okey!") // OK
230-
}
228+
let __secretlyKnownToBeLocal = wda
229+
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)
230+
// FIXME: pending fix of closure isolation checking with actors #59356
231+
// await wda.whenLocal { __secretlyKnownToBeLocal in
232+
// await __secretlyKnownToBeLocal.terminated(da: "local calls are okey!") // OK
233+
// }
231234
}
232235

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

0 commit comments

Comments
 (0)