Skip to content

Commit a05bf1a

Browse files
authored
Merge pull request #60668 from DougGregor/witness-thunk-accessible-from-anywhere-5.7
Witness thunk does not need to hop when the witness decl is accessible from anywhere
2 parents e406af0 + df26552 commit a05bf1a

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3060,6 +3060,11 @@ Optional<ActorIsolation> ConformanceChecker::checkActorIsolation(
30603060
diagnoseNonSendableTypesInReference(
30613061
getConcreteWitness(), DC, loc, SendableCheckReason::Conformance);
30623062

3063+
// If the witness is accessible across actors, we don't need to consider it
3064+
// isolated.
3065+
if (isAccessibleAcrossActors(witness, refResult.isolation, DC))
3066+
return None;
3067+
30633068
if (refResult.isolation.isActorIsolated() && isAsyncDecl(requirement) &&
30643069
!isAsyncDecl(witness))
30653070
return refResult.isolation;

test/SILGen/async_conversion.swift

Lines changed: 12 additions & 0 deletions
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)