Skip to content

Commit d081251

Browse files
committed
Witness thunk does not need to hop when the witness decl is acessible from anywhere
Fixes rdar://96906314.
1 parent c0e652b commit d081251

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

lib/Sema/TypeCheckProtocol.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -3083,6 +3083,11 @@ Optional<ActorIsolation> ConformanceChecker::checkActorIsolation(
30833083
diagnoseNonSendableTypesInReference(
30843084
getConcreteWitness(), DC, loc, SendableCheckReason::Conformance);
30853085

3086+
// If the witness is accessible across actors, we don't need to consider it
3087+
// isolated.
3088+
if (isAccessibleAcrossActors(witness, refResult.isolation, DC))
3089+
return None;
3090+
30863091
if (refResult.isolation.isActorIsolated() && isAsyncDecl(requirement) &&
30873092
!isAsyncDecl(witness))
30883093
return refResult.isolation;

test/SILGen/async_conversion.swift

+12
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,15 @@ struct X: P {
2121
// CHECK: function_ref @$s4test1XV1fySSSgSi_SStF : $@convention(method) (Int, @guaranteed String, X) -> @owned Optional<String>
2222
func f(_: Int, _: String) -> String? { nil }
2323
}
24+
25+
protocol P2 {
26+
init() async
27+
}
28+
29+
actor A: P2 {
30+
// CHECK-LABEL: sil private [transparent] [thunk] [ossa] @$s4test1ACAA2P2A2aDPxyYacfCTW
31+
// CHECK-NOT: hop_to_executor
32+
// CHECK: function_ref @$s4test1ACACycfC : $@convention(method) (@thick A.Type) -> @owned A // user: %3
33+
// CHECK-NEXT: apply
34+
// CHECK: return
35+
}

0 commit comments

Comments
 (0)