Skip to content

Commit 1880935

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. (cherry picked from commit 40c9674)
1 parent 4699419 commit 1880935

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
@@ -2797,16 +2797,13 @@ namespace {
27972797
diagnoseNonSendableParametersAndResult(toFnType);
27982798
break;
27992799

2800-
case FunctionTypeIsolation::Kind::Parameter:
2801-
llvm_unreachable("invalid conversion");
2802-
2800+
// @Sendable nonisolated(nonsending) -> nonisolated(nonsending)
2801+
// doesn't require Sendable checking.
28032802
case FunctionTypeIsolation::Kind::NonIsolatedCaller:
2804-
// Non isolated caller is always async. This can only occur if we
2805-
// are converting from an `@Sendable` representation to something
2806-
// else. So we need to just check that we diagnose non sendable
2807-
// parameters and results.
2808-
diagnoseNonSendableParametersAndResult(toFnType);
28092803
break;
2804+
2805+
case FunctionTypeIsolation::Kind::Parameter:
2806+
llvm_unreachable("invalid conversion");
28102807
}
28112808
break;
28122809
}

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)