Skip to content

Commit 11cf263

Browse files
authored
Merge pull request #81231 from xedin/rdar-150397825
[Concurrency] Account for explicit `@concurrent` on closures
2 parents 31ff9b4 + ef65f26 commit 11cf263

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

lib/Sema/TypeCheckConcurrency.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -4681,6 +4681,10 @@ ActorIsolation ActorIsolationChecker::determineClosureIsolation(
46814681
attr && ctx.LangOpts.hasFeature(Feature::ClosureIsolation)) {
46824682
return ActorIsolation::forNonisolated(attr->isUnsafe());
46834683
}
4684+
4685+
if (explicitClosure->getAttrs().hasAttribute<ConcurrentAttr>()) {
4686+
return ActorIsolation::forNonisolated(/*unsafe=*/false);
4687+
}
46844688
}
46854689

46864690
// `nonisolated(nonsending)` inferred from the context makes

test/Concurrency/attr_execution/conversions_silgen.swift

+12
Original file line numberDiff line numberDiff line change
@@ -456,3 +456,15 @@ func testThatClosuresAssumeIsolation(fn: inout nonisolated(nonsending) (Int) asy
456456
// CHECK: hop_to_executor [[GENERIC_EXECUTOR]]
457457
fn = { @concurrent _ in }
458458
}
459+
460+
@MainActor
461+
func testNoIsolationTransfer() {
462+
// CHECK: // Isolation: global_actor. type: MainActor
463+
// CHECK-LABEL: sil private [ossa] @$s21attr_execution_silgen23testNoIsolationTransferyyF0D7ErasureL_yyyyYaYAcF : $@convention(thin) (@guaranteed @isolated(any) @async @callee_guaranteed () -> ()) -> ()
464+
func testErasure(@_inheritActorContext _: @escaping @isolated(any) () async -> Void) {}
465+
466+
// CHECK-LABEL: sil private [ossa] @$s21attr_execution_silgen23testNoIsolationTransferyyFyyYacfU_ : $@convention(thin) @async (@guaranteed Optional<any Actor>) -> ()
467+
// CHECK: [[GENERIC_EXECUTOR:%.*]] = enum $Optional<Builtin.Executor>, #Optional.none!enumelt
468+
// CHECK: hop_to_executor [[GENERIC_EXECUTOR]]
469+
testErasure { @concurrent in }
470+
}

0 commit comments

Comments
 (0)