Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions lib/Sema/TypeCheckConcurrency.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}();

Expand Down
2 changes: 1 addition & 1 deletion test/Concurrency/actor_inout_isolation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
Copy link
Contributor

@jamieQ jamieQ Sep 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

out of curiosity, why were the adjustments to these existing tests necessary (here & below)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mentioned that in the description:

The change pushes isIsolationInferenceBoundaryClosure check down with added benefit of getting preconcurrency context from the parent.

The check was preventing from preferring "preconcurrency" from parent context.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for elaborating!

}

// attempt to pass global state owned by the global actor to another async function
Expand Down
8 changes: 8 additions & 0 deletions test/Concurrency/attr_execution/conversions_silgen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<any Actor>, Int) -> ()
// CHECK: bb0([[EXECUTOR:%.*]] : @guaranteed $Optional<any Actor>, %1 : $Int):
// CHECK: hop_to_executor [[EXECUTOR]]
// CHECK: // end sil function '$s21attr_execution_silgen49testSendableClosureNonisolatedNonSendingInferenceyyFySiYaYbYCcfU_'
let _: nonisolated(nonsending) @Sendable (Int) async -> Void = { _ in }
}
2 changes: 1 addition & 1 deletion test/Concurrency/sendable_checking_captures_swift5.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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'}}
}