Skip to content

Commit 298346f

Browse files
authored
Merge pull request #72575 from DougGregor/capture-isolation-in-context
Ensure that we map the capture isolation into context
2 parents 327b07b + 14fc015 commit 298346f

File tree

3 files changed

+52
-2
lines changed

3 files changed

+52
-2
lines changed

lib/SILGen/SILGenConcurrency.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -463,8 +463,8 @@ static ManagedValue emitLoadOfCaptureIsolation(SILGenFunction &SGF,
463463
auto &TC = SGF.SGM.Types;
464464
auto captureInfo = TC.getLoweredLocalCaptures(constant);
465465

466-
auto isolatedVarType =
467-
isolatedCapture->getInterfaceType()->getCanonicalType();
466+
auto isolatedVarType = SGF.F.mapTypeIntoContext(
467+
isolatedCapture->getInterfaceType())->getCanonicalType();
468468

469469
// Capture arguments are 1-1 with the lowered capture info.
470470
auto captures = captureInfo.getCaptures();

test/Distributed/distributed_actor_to_actor.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
// rdar://123970272
1010
// UNSUPPORTED: CPU=arm64e
1111

12+
import Swift
1213
import _Concurrency
1314
import Distributed
1415

@@ -39,6 +40,25 @@ func getAnyActor(distributedActor: isolated some DistributedActor) -> any Actor
3940
// CHECK-IR-NEXT: store ptr %"some DistributedActor.DistributedActor", ptr [[SELF_DA_REQ]]
4041
// CHECK-IR-NEXT: call ptr @swift_getWitnessTable(ptr @"$sxScA11DistributedMc", ptr %"some DistributedActor", ptr [[CONDITIONAL_REQ_GEP]])
4142

43+
distributed actor WorkerPool<Worker, ActorSystem: DistributedActorSystem>: AsyncSequence, AsyncIteratorProtocol {
44+
var level: Int
45+
public init(actorSystem system: ActorSystem) async throws {
46+
self.actorSystem = system
47+
self.level = 0
48+
49+
// CHECK-SIL: sil private @$s021distributed_actor_to_B010WorkerPoolC0B6SystemACyxq_Gq__tYaKcfcyyYaYbcfU_ : $@convention(thin) @Sendable @async <Worker, ActorSystem where ActorSystem : DistributedActorSystem> (@guaranteed Optional<any Actor>, @sil_isolated @guaranteed WorkerPool<Worker, ActorSystem>) -> @out
50+
// CHECK-SIL: hop_to_executor {{%.*}} : $WorkerPool<Worker, ActorSystem>
51+
_ = Task {
52+
for await x in self {
53+
print(x)
54+
}
55+
}
56+
}
57+
58+
nonisolated func makeAsyncIterator() -> WorkerPool { self }
59+
nonisolated func next() async -> Int? { nil }
60+
}
61+
4262
// CHECK-SIL-LABEL: sil_witness_table shared <Self where Self : DistributedActor> T: Actor module Distributed {
4363
// CHECK-SIL-NEXT: method #Actor.unownedExecutor!getter: <Self where Self : Actor> (Self) -> () -> UnownedSerialExecutor : @$sxScA11DistributedScA15unownedExecutorScevgTW
4464
// CHECK-SIL-NEXT: conditional_conformance (Self: DistributedActor): dependent

test/decl/protocol/req/associated_type_typealias_implements.swift

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,33 @@ struct Y3: Q { // expected-error{{type 'Y3' does not conform to protocol 'Q'}}
3636
typealias T = XT
3737
// FIXME: More detail from diagnostic.
3838
}
39+
40+
41+
protocol A1 {
42+
associatedtype T
43+
}
44+
protocol A2 {
45+
associatedtype T
46+
}
47+
48+
struct BothA1_and_A2: A1, A2 {
49+
@_implements(A1, T)
50+
typealias X = Int
51+
52+
@_implements(A2, T)
53+
typealias Y = String
54+
}
55+
56+
typealias A1_T<U: A1> = U.T
57+
typealias A2_T<U: A2> = U.T
58+
59+
struct RequireSame<T, U> { }
60+
61+
extension RequireSame where T == U {
62+
init(same: Bool) { }
63+
}
64+
65+
func testImplements() {
66+
_ = RequireSame<A1_T<BothA1_and_A2>, Int>(same: true)
67+
_ = RequireSame<A2_T<BothA1_and_A2>, String>(same: true)
68+
}

0 commit comments

Comments
 (0)