Skip to content

Commit 053199e

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
1 parent c0c7bf3 commit 053199e

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
@@ -2849,6 +2849,14 @@ namespace {
28492849
break;
28502850

28512851
case FunctionTypeIsolation::Kind::GlobalActor:
2852+
// If the isolation is the same it means that conversion
2853+
// covers loss of `@Sendable` or some other attribute and
2854+
// we don't need Sendable checking because there is no
2855+
// boundary crossing here.
2856+
if (fromIsolation.getGlobalActorType()->isEqual(
2857+
toIsolation.getGlobalActorType()))
2858+
break;
2859+
28522860
diagnoseNonSendableParametersAndResult(
28532861
toFnType, version::Version::getFutureMajorLanguageVersion());
28542862
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)