diff --git a/lib/Sema/TypeCheckConcurrency.cpp b/lib/Sema/TypeCheckConcurrency.cpp index dd59321e7c7cc..b6f168a55b248 100644 --- a/lib/Sema/TypeCheckConcurrency.cpp +++ b/lib/Sema/TypeCheckConcurrency.cpp @@ -4988,16 +4988,6 @@ ActorIsolation ActorIsolationChecker::determineClosureIsolation( return ActorIsolation::forActorInstanceCapture(param); } - // If we have a closure that acts as an isolation inference boundary, then - // we return that it is non-isolated. - // - // NOTE: Since we already checked for global actor isolated things, we - // know that all Sendable closures must be nonisolated. That is why it is - // safe to rely on this path to handle Sendable closures. - if (isIsolationInferenceBoundaryClosure(closure, - /*canInheritActorContext=*/true)) - return ActorIsolation::forNonisolated(/*unsafe=*/false); - // A non-Sendable closure gets its isolation from its context. auto parentIsolation = getActorIsolationOfContext( closure->getParent(), getClosureActorIsolation); @@ -5029,6 +5019,16 @@ ActorIsolation ActorIsolationChecker::determineClosureIsolation( } } + // If we have a closure that acts as an isolation inference boundary, then + // we return that it is non-isolated. + // + // NOTE: Since we already checked for global actor isolated things, we + // know that all Sendable closures must be nonisolated. That is why it is + // safe to rely on this path to handle Sendable closures. + if (isIsolationInferenceBoundaryClosure(closure, + /*canInheritActorContext=*/true)) + return ActorIsolation::forNonisolated(/*unsafe=*/false); + return normalIsolation; }(); diff --git a/test/Concurrency/actor_inout_isolation.swift b/test/Concurrency/actor_inout_isolation.swift index f4ae9daaeccc7..20ef27f4c3aed 100644 --- a/test/Concurrency/actor_inout_isolation.swift +++ b/test/Concurrency/actor_inout_isolation.swift @@ -220,7 +220,7 @@ if #available(SwiftStdlib 5.1, *) { let _ = Task.detached { await { (_ foo: inout Int) async in foo += 1 }(&number) } // expected-error @-1 {{actor-isolated var 'number' cannot be passed 'inout' to 'async' function call}} // expected-minimal-error @-2 {{global actor 'MyGlobalActor'-isolated var 'number' can not be used 'inout' from a nonisolated context}} - // expected-complete-error @-3 {{main actor-isolated var 'number' can not be used 'inout' from a nonisolated context}} + // expected-complete-warning @-3 {{main actor-isolated var 'number' can not be used 'inout' from a nonisolated context}} } // attempt to pass global state owned by the global actor to another async function diff --git a/test/Concurrency/attr_execution/conversions_silgen.swift b/test/Concurrency/attr_execution/conversions_silgen.swift index 0ecacaa916f91..65b012fbb2edd 100644 --- a/test/Concurrency/attr_execution/conversions_silgen.swift +++ b/test/Concurrency/attr_execution/conversions_silgen.swift @@ -613,3 +613,11 @@ func testConvertToThrowing(isolation: isolated (any Actor)? = #isolation) async observe() } } + +func testSendableClosureNonisolatedNonSendingInference() { + // CHECK-LABEL: sil private [ossa] @$s21attr_execution_silgen49testSendableClosureNonisolatedNonSendingInferenceyyFySiYaYbYCcfU_ : $@convention(thin) @Sendable @async (@sil_isolated @sil_implicit_leading_param @guaranteed Optional, Int) -> () + // CHECK: bb0([[EXECUTOR:%.*]] : @guaranteed $Optional, %1 : $Int): + // CHECK: hop_to_executor [[EXECUTOR]] + // CHECK: // end sil function '$s21attr_execution_silgen49testSendableClosureNonisolatedNonSendingInferenceyyFySiYaYbYCcfU_' + let _: nonisolated(nonsending) @Sendable (Int) async -> Void = { _ in } +} diff --git a/test/Concurrency/sendable_checking_captures_swift5.swift b/test/Concurrency/sendable_checking_captures_swift5.swift index 2346d64079ec3..470b40607e2f9 100644 --- a/test/Concurrency/sendable_checking_captures_swift5.swift +++ b/test/Concurrency/sendable_checking_captures_swift5.swift @@ -92,5 +92,5 @@ do { let c: Class test(c) - // expected-complete-warning@-1:8 {{implicit capture of 'c' requires that 'Class' conforms to 'Sendable'; this is an error in the Swift 6 language mode}} + // expected-complete-warning@-1:8 {{implicit capture of 'c' requires that 'Class' conforms to 'Sendable'}} }