Skip to content

Commit 3263327

Browse files
committed
[Concurrency] Forego Sendable checking if conversion doesn't change the global actor
`FunctionConversionExpr` is allowed to modify different attributes of a type, sometimes it could strip `@Sendable` but keep the same global actor attribute in place, that needs to be handled explicitly before performing Sendable checking because in this case there is going to be no isolation context change for arguments or results. Resolves: rdar://153646123 (cherry picked from commit 053199e)
1 parent c1d96d6 commit 3263327

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2865,6 +2865,14 @@ namespace {
28652865
break;
28662866

28672867
case FunctionTypeIsolation::Kind::GlobalActor:
2868+
// If the isolation is the same it means that conversion
2869+
// covers loss of `@Sendable` or some other attribute and
2870+
// we don't need Sendable checking because there is no
2871+
// boundary crossing here.
2872+
if (fromIsolation.getGlobalActorType()->isEqual(
2873+
toIsolation.getGlobalActorType()))
2874+
break;
2875+
28682876
diagnoseNonSendableParametersAndResult(
28692877
toFnType, version::Version::getFutureMajorLanguageVersion());
28702878
break;

test/Concurrency/dynamic_checks_for_func_refs_in_preconcurrency_apis.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ public struct S<T> {
4242
}
4343
}
4444

45+
public class NS {}
46+
47+
public func testNoIsolation(_: @escaping (NS) -> Void) {}
48+
4549
//--- Client.swift
4650
import API
4751

@@ -164,3 +168,14 @@ func testMembers<X>(v: X, s: S<X>, fn: @escaping @MainActor (X) -> Int) {
164168
// CHECK-NEXT: [[EXEC:%.*]] = extract_executor [[MAIN_ACTOR_ACCESS]] : $MainActor
165169
// CHECK: [[CHECK_EXEC_REF:%.*]] = function_ref @$ss22_checkExpectedExecutor14_filenameStart01_D6Length01_D7IsASCII5_line9_executoryBp_BwBi1_BwBetF
166170
// CHECK-NEXT: {{.*}} = apply [[CHECK_EXEC_REF]]({{.*}}, [[EXEC]])
171+
172+
@MainActor
173+
class Test {
174+
@Sendable func compute(_: NS) {}
175+
// expected-warning@-1 {{main actor-isolated synchronous instance method 'compute' cannot be marked as '@Sendable'; this is an error in the Swift 6 language mode}}
176+
177+
func test() {
178+
// Triggers loss of @Sendable and actor isolation erasure at the same time
179+
testNoIsolation(compute)
180+
}
181+
}

0 commit comments

Comments
 (0)