Skip to content

Commit f50695b

Browse files
committed
[Concurrency] Account for explicit @concurrent on closures
If closure is stated as `@concurrent` is has to be treated as nonisolated. Resolves: rdar://150397825 (cherry picked from commit ef65f26)
1 parent 23e21ff commit f50695b

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4699,6 +4699,10 @@ ActorIsolation ActorIsolationChecker::determineClosureIsolation(
46994699
attr && ctx.LangOpts.hasFeature(Feature::ClosureIsolation)) {
47004700
return ActorIsolation::forNonisolated(attr->isUnsafe());
47014701
}
4702+
4703+
if (explicitClosure->getAttrs().hasAttribute<ConcurrentAttr>()) {
4704+
return ActorIsolation::forNonisolated(/*unsafe=*/false);
4705+
}
47024706
}
47034707

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

test/Concurrency/attr_execution/conversions_silgen.swift

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