Skip to content

Commit f6e0218

Browse files
committed
[Concurrency] Synchronous witness of an async isolated requirement should hop
The witness thunk is async which means that it needs a hop to the expected concurrency domain imposed by the requirement otherwise it says in the caller's domain. Resolves: swiftlang#62394 Resolves: rdar://121415906
1 parent b98d7a5 commit f6e0218

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3126,6 +3126,12 @@ ConformanceChecker::checkActorIsolation(ValueDecl *requirement,
31263126
break;
31273127
}
31283128

3129+
// Witnessing `async` requirement with an isolated synchronous
3130+
// declaration is done via async witness thunk which requires
3131+
// a hop to the expected concurrency domain.
3132+
if (isAsyncDecl(requirement) && !isAsyncDecl(witness))
3133+
return refResult.isolation;
3134+
31293135
// Otherwise, we're done.
31303136
return llvm::None;
31313137

test/Concurrency/issue62394.swift

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// RUN: %target-swift-frontend -disable-availability-checking -emit-silgen -verify %s | %FileCheck %s
2+
// RUN: %target-swift-frontend -disable-availability-checking -emit-silgen -verify -strict-concurrency=complete %s | %FileCheck %s
3+
4+
// REQUIRES: objc_interop
5+
// REQUIRES: concurrency
6+
7+
@MainActor
8+
protocol P {
9+
func test() async
10+
}
11+
12+
struct S : P {
13+
func test() {}
14+
}
15+
16+
// CHECK-LABEL: sil private [transparent] [thunk] [ossa] @$s10issue623941SVAA1PA2aDP4testyyYaFTW : $@convention(witness_method: P) @async (@in_guaranteed S) -> ()
17+
// CHECK: [[MAIN_ACTOR:%.*]] = begin_borrow {{.*}} : $MainActor
18+
// CHECK-NEXT: hop_to_executor [[MAIN_ACTOR]] : $MainActor
19+
// CHECK: [[SELF:%.*]] = load [trivial] %0 : $*S
20+
// CHECK: [[TEST_FN:%.*]] = function_ref @$s10issue623941SV4testyyF : $@convention(method) (S) -> ()
21+
// CHECK-NEXT: {{.*}} = apply [[TEST_FN]]([[SELF]]) : $@convention(method) (S) -> ()

0 commit comments

Comments
 (0)