Skip to content

Commit 40c9674

Browse files
committed
[Concurrency] Avoid Sendable checking for conversions that strip @Sendable from nonisolated(nonsending) function type
The isolation doesn't change in this cause and making function type non-Sendable means that it woun't be able to leave the current concurrency domain and the compiler won't generate a thunk.
1 parent 61fbaa7 commit 40c9674

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2780,16 +2780,13 @@ namespace {
27802780
diagnoseNonSendableParametersAndResult(toFnType);
27812781
break;
27822782

2783-
case FunctionTypeIsolation::Kind::Parameter:
2784-
llvm_unreachable("invalid conversion");
2785-
2783+
// @Sendable nonisolated(nonsending) -> nonisolated(nonsending)
2784+
// doesn't require Sendable checking.
27862785
case FunctionTypeIsolation::Kind::NonIsolatedNonsending:
2787-
// Non isolated caller is always async. This can only occur if we
2788-
// are converting from an `@Sendable` representation to something
2789-
// else. So we need to just check that we diagnose non sendable
2790-
// parameters and results.
2791-
diagnoseNonSendableParametersAndResult(toFnType);
27922786
break;
2787+
2788+
case FunctionTypeIsolation::Kind::Parameter:
2789+
llvm_unreachable("invalid conversion");
27932790
}
27942791
break;
27952792
}

test/Concurrency/attr_execution/conversions_silgen.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,4 +620,12 @@ func testSendableClosureNonisolatedNonSendingInference() {
620620
// CHECK: hop_to_executor [[EXECUTOR]]
621621
// CHECK: // end sil function '$s21attr_execution_silgen49testSendableClosureNonisolatedNonSendingInferenceyyFySiYaYbYCcfU_'
622622
let _: nonisolated(nonsending) @Sendable (Int) async -> Void = { _ in }
623+
624+
// CHECK-LABEL: sil private [ossa] @$s21attr_execution_silgen49testSendableClosureNonisolatedNonSendingInferenceyyFyS2SYaKYCcYaYbYCcfU0_ : $@convention(thin) @Sendable @async (@sil_isolated @sil_implicit_leading_param @guaranteed Optional<any Actor>, @guaranteed @async @callee_guaranteed (@sil_isolated @sil_implicit_leading_param @guaranteed Optional<any Actor>, @guaranteed String) -> (@owned String, @error any Error)) -> @error any Error
625+
// CHECK: bb0([[EXECUTOR:%.*]] : @guaranteed $Optional<any Actor>, %1 : @guaranteed $@async @callee_guaranteed (@sil_isolated @sil_implicit_leading_param @guaranteed Optional<any Actor>, @guaranteed String) -> (@owned String, @error any Error)):
626+
// CHECK: hop_to_executor [[EXECUTOR]]
627+
// CHECK: // end sil function '$s21attr_execution_silgen49testSendableClosureNonisolatedNonSendingInferenceyyFyS2SYaKYCcYaYbYCcfU0_'
628+
let _: nonisolated(nonsending) @Sendable (
629+
nonisolated(nonsending) @escaping (String) async throws -> String
630+
) async throws -> Void = { _ in }
623631
}

0 commit comments

Comments
 (0)