-
Notifications
You must be signed in to change notification settings - Fork 10.5k
/
Copy pathdistributed_actor_to_actor.swift
57 lines (47 loc) · 2.98 KB
/
distributed_actor_to_actor.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
// RUN: %target-swift-frontend -target %target-swift-5.7-abi-triple %s -parse-as-library -parse-stdlib -Xllvm -sil-print-types -emit-sil -o - | %FileCheck %s -check-prefix=CHECK-SIL
// RUN: %target-swift-frontend -target %target-swift-5.7-abi-triple %s -parse-as-library -parse-stdlib -emit-ir -o - | %FileCheck %s -check-prefix=CHECK-IR
// UNSUPPORTED: back_deploy_concurrency
// REQUIRES: concurrency
// REQUIRES: distributed
import Swift
import _Concurrency
import Distributed
// Protocol conformance descriptor:
// - extension of DistributedActor
// - flags, which includes a specific bit + conditional conformance
// - witness for unownedExecutor
// CHECK-IR: @"$sxScA11DistributedMc" = linkonce_odr hidden constant
// CHECK-IR-SAME: $s11Distributed0A5ActorPAAEMXE
// CHECK-IR-SAME: i32 459080
// CHECK-IR-SAME: $sxScA11DistributedScA15unownedExecutorScevgTW
// Make sure there is no runtime record of the protocol descriptor.
// CHECK-IR-NOT: $sxScA11DistributedHc
// CHECK-SIL-LABEL: sil hidden @$s021distributed_actor_to_B011getAnyActor0aF0ScA_pxYi_t11Distributed0gF0RzlF : $@convention(thin) <τ_0_0 where τ_0_0 : DistributedActor> (@sil_isolated @guaranteed τ_0_0) -> @owned any Actor
func getAnyActor(distributedActor: isolated some DistributedActor) -> any Actor {
// CHECK-SIL: [[EXISTENTIAL:%.*]] = init_existential_ref %0 : $τ_0_0 : $τ_0_0, $any Actor
// CHECK-SIL-NEXT: strong_retain [[EXISTENTIAL]] : $any Actor
// CHECK-SIL-NEXT: return [[EXISTENTIAL]] : $any Actor
return Builtin.distributedActorAsAnyActor(distributedActor)
}
// CHECK-IR-LABEL: define {{.*}} @"$s021distributed_actor_to_B011getAnyActor0aF0ScA_pxYi_t11Distributed0gF0RzlF
// CHECK-IR: %conditional.requirement.buffer = alloca [1 x ptr]
// CHECK-IR: [[CONDITIONAL_REQ_GEP:%[0-9]+]] = getelementptr inbounds [1 x ptr], ptr %conditional.requirement.buffer, i32 0, i32 0
// CHECK-IR-NEXT: [[SELF_DA_REQ:%.*]] = getelementptr inbounds ptr, ptr [[CONDITIONAL_REQ_GEP]], i32 0
// CHECK-IR-NEXT: store ptr %"some DistributedActor.DistributedActor", ptr [[SELF_DA_REQ]]
// CHECK-IR-NEXT: call ptr @swift_getWitnessTable(ptr @"$sxScA11DistributedMc{{(.ptrauth)?}}", ptr %"some DistributedActor", ptr [[CONDITIONAL_REQ_GEP]])
distributed actor WorkerPool<Worker, ActorSystem: DistributedActorSystem>: AsyncSequence, AsyncIteratorProtocol {
var level: Int
public init(actorSystem system: ActorSystem) async throws {
self.actorSystem = system
self.level = 0
// CHECK-SIL: sil private @$s021distributed_actor_to_B010WorkerPoolC0B6SystemACyxq_Gq__tYaKcfcyyYacfU_ : $@convention(thin) @Sendable @async <Worker, ActorSystem where ActorSystem : DistributedActorSystem> (@guaranteed Optional<any Actor>, @sil_isolated @guaranteed WorkerPool<Worker, ActorSystem>) -> @out () {
// CHECK-SIL: hop_to_executor {{%.*}} : $WorkerPool<Worker, ActorSystem>
_ = Task {
for await x in self {
print(x)
}
}
}
nonisolated func makeAsyncIterator() -> WorkerPool { self }
nonisolated func next() async -> Int? { nil }
}