-
Notifications
You must be signed in to change notification settings - Fork 10.5k
/
Copy pathdistributed_actor_isolation_and_tasks.swift
74 lines (60 loc) · 2.38 KB
/
distributed_actor_isolation_and_tasks.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend-emit-module -emit-module-path %t/FakeDistributedActorSystems.swiftmodule -module-name FakeDistributedActorSystems -target %target-swift-5.7-abi-triple %S/Inputs/FakeDistributedActorSystems.swift
// RUN: %target-swift-frontend -typecheck -verify -target %target-swift-5.7-abi-triple -I %t 2>&1 %s
// REQUIRES: concurrency
// REQUIRES: distributed
import Distributed
import FakeDistributedActorSystems
@available(SwiftStdlib 5.5, *)
typealias DefaultDistributedActorSystem = FakeActorSystem
struct SomeLogger {}
struct Logger {
let label: String
func info(_: String) {}
}
distributed actor Philosopher {
let log: Logger
// expected-note@-1{{access to property 'log' is only permitted within distributed actor 'Philosopher'}}
var variable = 12
var variable_fromDetach = 12
let INITIALIZED: Int
let outside: Int = 1
init(system: FakeActorSystem) {
self.log = Logger(label: "name")
self.INITIALIZED = 1
}
distributed func dist() -> Int {}
func test() {
_ = self.id
_ = self.actorSystem
Task {
_ = self.id
_ = self.actorSystem
self.log.info("READY!")
_ = self.variable
_ = self.dist()
}
Task.detached {
_ = self.id
_ = self.actorSystem
// This is an interesting case, since we have a real local `self` and
// yet are not isolated to the same actor in this detached task...
// the call to it is implicitly async, however it is NOT implicitly throwing
// because we KNOW this is a local call -- and there is no system in
// between that will throw.
_ = await self.dist() // notice lack of 'try' even though 'distributed func'
_ = self.variable_fromDetach // expected-error{{expression is 'async' but is not marked with 'await'}}
// expected-note@-1{{property access is 'async'}}
_ = await self.variable_fromDetach // okay, we know we're on the local node
}
}
}
func test_outside(system: FakeActorSystem) async throws {
_ = try await Philosopher(system: system).dist()
_ = Philosopher(system: system).log // expected-error{{distributed actor-isolated property 'log' can not be accessed from a nonisolated context}}
_ = Philosopher(system: system).id
_ = Philosopher(system: system).actorSystem
}
func test_outside_isolated(phil: isolated Philosopher) async throws {
phil.log.info("works on isolated")
}