Skip to content

Commit 2c66b20

Browse files
committed
[Distributed] NFC: Add a test-case for different async let configurations
1 parent 115af99 commit 2c66b20

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
// RUN: %target-typecheck-verify-swift -enable-experimental-distributed -disable-availability-checking
2+
3+
// UNSUPPORTED: back_deploy_concurrency
4+
// REQUIRES: concurrency
5+
// REQUIRES: distributed
6+
7+
import _Distributed
8+
9+
distributed actor Philosopher {
10+
let philosophy: String
11+
12+
typealias Transport = AnyActorTransport
13+
14+
init(transport: AnyActorTransport) {
15+
philosophy = "Epistemology"
16+
}
17+
18+
distributed func hi() -> String { "Hi!" }
19+
20+
func test(other: Philosopher) async throws {
21+
// self --------------------------------------------------------------------
22+
async let alet = self.hi() // none
23+
_ = await alet // Ok - `self.hi()` isn't throwing
24+
25+
Task {
26+
_ = self.hi() // none
27+
}
28+
29+
Task.detached {
30+
_ = await self.hi() // async
31+
}
32+
33+
// other -------------------------------------------------------------------
34+
35+
async let otherLet = other.hi() // hi = async throws because of `other`
36+
_ = try await otherLet
37+
38+
Task {
39+
_ = try await other.hi() // hi = async throws
40+
}
41+
42+
Task.detached {
43+
_ = try await other.hi() // hi = async throws
44+
}
45+
46+
// known to be local -------------------------------------------------------
47+
48+
// FIXME(distributed): relies on the "secretly known to be local" hack in typechecking
49+
let _: String? = await other.whenLocal { __secretlyKnownToBeLocal in
50+
// we're able to get state of what would otherwise be distributed-isolated:
51+
__secretlyKnownToBeLocal.philosophy
52+
}
53+
}
54+
55+
static func test(iso: isolated Philosopher) async throws {
56+
_ = iso.hi() // we're "in the actor" already, since isolated
57+
58+
// isolated parameter ------------------------------------------------------
59+
async let otherLet = iso.hi() // async
60+
_ = await otherLet
61+
62+
Task {
63+
_ = await iso.hi() // none
64+
}
65+
66+
Task.detached {
67+
_ = await iso.hi() // async
68+
}
69+
}
70+
}

0 commit comments

Comments
 (0)