Skip to content

Commit 387580c

Browse files
authored
Merge pull request #73605 from gottesmm/rdar118244451_125200006
[concurrency] Make GlobalActorIsolatedTypesUsability an upcoming swift 6 feature and fix a region isolation issue that prevented us from enabling it
2 parents e7b9fbc + de85b79 commit 387580c

22 files changed

+69
-57
lines changed

include/swift/Basic/Features.def

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ UPCOMING_FEATURE(ImplicitOpenExistentials, 352, 6)
196196
UPCOMING_FEATURE(RegionBasedIsolation, 414, 6)
197197
UPCOMING_FEATURE(DynamicActorIsolation, 423, 6)
198198
UPCOMING_FEATURE(NonfrozenEnumExhaustivity, 192, 6)
199+
UPCOMING_FEATURE(GlobalActorIsolatedTypesUsability, 0434, 6)
199200

200201
// Swift 7
201202
UPCOMING_FEATURE(ExistentialAny, 335, 7)
@@ -368,9 +369,6 @@ EXPERIMENTAL_FEATURE_EXCLUDED_FROM_MODULE_INTERFACE(MemberImportVisibility, true
368369
// Alias for IsolatedAny
369370
EXPERIMENTAL_FEATURE(IsolatedAny2, true)
370371

371-
// Enable usability improvements for global-actor-isolated types.
372-
EXPERIMENTAL_FEATURE(GlobalActorIsolatedTypesUsability, true)
373-
374372
// Enable @implementation on extensions of ObjC classes.
375373
EXPERIMENTAL_FEATURE(ObjCImplementation, true)
376374

lib/SILOptimizer/Analysis/RegionAnalysis.cpp

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1718,30 +1718,32 @@ class PartitionOpTranslator {
17181718
}
17191719

17201720
// Now that we have transferred everything into the partial_apply, perform
1721-
// an assign fresh for the partial_apply. If we use any of the transferred
1722-
// values later, we will error, so it is safe to just create a new value.
1721+
// an assign fresh for the partial_apply if it is non-Sendable. If we use
1722+
// any of the transferred values later, we will error, so it is safe to just
1723+
// create a new value.
1724+
if (pai->getFunctionType()->isSendable())
1725+
return;
1726+
17231727
auto paiValue = tryToTrackValue(pai).value();
17241728
SILValue rep = paiValue.getRepresentative().getValue();
17251729
mergeIsolationRegionInfo(rep, actorIsolation);
17261730
translateSILAssignFresh(rep);
17271731
}
17281732

17291733
void translateSILPartialApply(PartialApplyInst *pai) {
1730-
// First check if our partial apply is Sendable. In such a case, we will
1731-
// have emitted an earlier warning in Sema.
1732-
//
1733-
// DISCUSSION: The reason why we can treat values passed into an async let
1734-
// as transferring safely but it is unsafe to do this for arbitrary Sendable
1735-
// closures is that we do not know how many times the Sendable closure will
1736-
// be executed. It is possible to have different invocations of the Sendable
1737-
// closure to cause races with the captured non-Sendable value. In contrast
1738-
// since we know an async let runs exactly once, we do not need to worry
1739-
// about such a possibility. If we had the ability in the language to
1740-
// specify that a closure is run at most once or that it is always run
1741-
// serially, we could lift this restriction... so for now we leave in the
1742-
// Sema warning and just bail here.
1743-
if (pai->getFunctionType()->isSendableType())
1744-
return;
1734+
// First check if our partial apply is Sendable and not global actor
1735+
// isolated. In such a case, we will have emitted an earlier warning in Sema
1736+
// and can return early. If we have a global actor isolated partial_apply,
1737+
// we can be looser and can use region isolation since we know that the
1738+
// Sendable closure will be executed serially due to the closure having to
1739+
// run on the global actor queue meaning that we do not have to worry about
1740+
// the Sendable closure being run concurrency.
1741+
if (pai->getFunctionType()->isSendableType()) {
1742+
auto isolationInfo = SILIsolationInfo::get(pai);
1743+
if (!isolationInfo || !isolationInfo.hasActorIsolation() ||
1744+
!isolationInfo.getActorIsolation().isGlobalActor())
1745+
return;
1746+
}
17451747

17461748
// Then check if our partial_apply is fed into an async let begin. If so,
17471749
// handle it especially.

test/Concurrency/actor_isolation.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
// RUN: %target-swift-frontend -emit-module -emit-module-path %t/OtherActors.swiftmodule -module-name OtherActors %S/Inputs/OtherActors.swift -disable-availability-checking
44

5-
// RUN: %target-swift-frontend -I %t -disable-availability-checking -strict-concurrency=complete -parse-as-library -emit-sil -o /dev/null -verify -enable-experimental-feature GlobalActorIsolatedTypesUsability %s
6-
// RUN: %target-swift-frontend -I %t -disable-availability-checking -strict-concurrency=complete -parse-as-library -emit-sil -o /dev/null -verify -enable-upcoming-feature RegionBasedIsolation -enable-experimental-feature GlobalActorIsolatedTypesUsability %s
5+
// RUN: %target-swift-frontend -I %t -disable-availability-checking -strict-concurrency=complete -parse-as-library -emit-sil -o /dev/null -verify -enable-upcoming-feature GlobalActorIsolatedTypesUsability %s
6+
// RUN: %target-swift-frontend -I %t -disable-availability-checking -strict-concurrency=complete -parse-as-library -emit-sil -o /dev/null -verify -enable-upcoming-feature RegionBasedIsolation -enable-upcoming-feature GlobalActorIsolatedTypesUsability %s
77

88
// REQUIRES: concurrency
99
// REQUIRES: asserts

test/Concurrency/actor_isolation_swift6.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-swift-frontend -disable-availability-checking -swift-version 6 -emit-sil -o /dev/null -verify -enable-experimental-feature GlobalActorIsolatedTypesUsability %s
1+
// RUN: %target-swift-frontend -disable-availability-checking -swift-version 6 -emit-sil -o /dev/null -verify -enable-upcoming-feature GlobalActorIsolatedTypesUsability %s
22

33
// REQUIRES: concurrency
44
// REQUIRES: asserts

test/Concurrency/derived_conformances_nonisolated.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// RUN: %target-swift-frontend -disable-availability-checking -strict-concurrency=complete -parse-as-library %s -emit-sil -o /dev/null -verify -enable-experimental-feature GlobalActorIsolatedTypesUsability
2-
// RUN: %target-swift-frontend -disable-availability-checking -strict-concurrency=complete -parse-as-library %s -emit-sil -o /dev/null -verify -strict-concurrency=complete -enable-upcoming-feature RegionBasedIsolation -enable-experimental-feature GlobalActorIsolatedTypesUsability
1+
// RUN: %target-swift-frontend -disable-availability-checking -strict-concurrency=complete -parse-as-library %s -emit-sil -o /dev/null -verify -enable-upcoming-feature GlobalActorIsolatedTypesUsability
2+
// RUN: %target-swift-frontend -disable-availability-checking -strict-concurrency=complete -parse-as-library %s -emit-sil -o /dev/null -verify -strict-concurrency=complete -enable-upcoming-feature RegionBasedIsolation -enable-upcoming-feature GlobalActorIsolatedTypesUsability
33

44
// REQUIRES: concurrency
55
// REQUIRES: asserts

test/Concurrency/global_actor_inference.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
// RUN: %empty-directory(%t)
22

3-
// RUN: %target-swift-frontend -emit-module -emit-module-path %t/other_global_actor_inference.swiftmodule -module-name other_global_actor_inference -strict-concurrency=complete %S/Inputs/other_global_actor_inference.swift -enable-experimental-feature GlobalActorIsolatedTypesUsability
4-
// RUN: %target-swift-frontend -I %t -disable-availability-checking %s -emit-sil -o /dev/null -verify -verify-additional-prefix minimal-targeted- -enable-experimental-feature GlobalActorIsolatedTypesUsability
5-
// RUN: %target-swift-frontend -I %t -disable-availability-checking %s -emit-sil -o /dev/null -verify -strict-concurrency=targeted -verify-additional-prefix minimal-targeted- -enable-experimental-feature GlobalActorIsolatedTypesUsability
6-
// RUN: %target-swift-frontend -I %t -disable-availability-checking %s -emit-sil -o /dev/null -verify -strict-concurrency=complete -verify-additional-prefix complete-tns- -enable-experimental-feature GlobalActorIsolatedTypesUsability
7-
// RUN: %target-swift-frontend -I %t -disable-availability-checking %s -emit-sil -o /dev/null -verify -strict-concurrency=complete -enable-upcoming-feature RegionBasedIsolation -verify-additional-prefix complete-tns- -enable-experimental-feature GlobalActorIsolatedTypesUsability
3+
// RUN: %target-swift-frontend -emit-module -emit-module-path %t/other_global_actor_inference.swiftmodule -module-name other_global_actor_inference -strict-concurrency=complete %S/Inputs/other_global_actor_inference.swift -enable-upcoming-feature GlobalActorIsolatedTypesUsability
4+
// RUN: %target-swift-frontend -I %t -disable-availability-checking %s -emit-sil -o /dev/null -verify -verify-additional-prefix minimal-targeted- -enable-upcoming-feature GlobalActorIsolatedTypesUsability
5+
// RUN: %target-swift-frontend -I %t -disable-availability-checking %s -emit-sil -o /dev/null -verify -strict-concurrency=targeted -verify-additional-prefix minimal-targeted- -enable-upcoming-feature GlobalActorIsolatedTypesUsability
6+
// RUN: %target-swift-frontend -I %t -disable-availability-checking %s -emit-sil -o /dev/null -verify -strict-concurrency=complete -verify-additional-prefix complete-tns- -enable-upcoming-feature GlobalActorIsolatedTypesUsability
7+
// RUN: %target-swift-frontend -I %t -disable-availability-checking %s -emit-sil -o /dev/null -verify -strict-concurrency=complete -enable-upcoming-feature RegionBasedIsolation -verify-additional-prefix complete-tns- -enable-upcoming-feature GlobalActorIsolatedTypesUsability
88

99
// REQUIRES: concurrency
1010
// REQUIRES: asserts

test/Concurrency/global_actor_inference_swift6.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
// RUN: %target-swift-frontend -swift-version 6 -emit-module -emit-module-path %t/other_global_actor_inference.swiftmodule -module-name other_global_actor_inference -strict-concurrency=complete %S/Inputs/other_global_actor_inference.swift
44

5-
// RUN: %target-swift-frontend -swift-version 6 -I %t -disable-availability-checking %s -emit-sil -o /dev/null -verify -enable-experimental-feature GlobalActorIsolatedTypesUsability
5+
// RUN: %target-swift-frontend -swift-version 6 -I %t -disable-availability-checking %s -emit-sil -o /dev/null -verify -enable-upcoming-feature GlobalActorIsolatedTypesUsability
66

77
// REQUIRES: concurrency
88

test/Concurrency/global_actor_sendable_fn_type_inference.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-typecheck-verify-swift -strict-concurrency=complete -disable-availability-checking -enable-upcoming-feature RegionBasedIsolation -enable-experimental-feature GlobalActorIsolatedTypesUsability
1+
// RUN: %target-typecheck-verify-swift -strict-concurrency=complete -disable-availability-checking -enable-upcoming-feature RegionBasedIsolation -enable-upcoming-feature GlobalActorIsolatedTypesUsability
22

33
// REQUIRES: concurrency
44
// REQUIRES: asserts

test/Concurrency/predates_concurrency_swift6.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func testInAsync(x: X) async {
2727
let _: Int = unsafelySendableClosure // expected-error{{type '@Sendable (@Sendable () -> Void) -> ()'}}
2828
let _: Int = unsafelyMainActorClosure // expected-error{{type '@Sendable (@MainActor () -> Void) -> ()'}}
2929
let _: Int = unsafelyDoEverythingClosure // expected-error{{type '@Sendable (@MainActor @Sendable () -> Void) -> ()'}}
30-
let _: Int = x.unsafelyDoEverythingClosure // expected-error{{type '(@MainActor @Sendable () -> Void) -> ()'}}
30+
let _: Int = x.unsafelyDoEverythingClosure // expected-error{{type '@Sendable (@MainActor @Sendable () -> Void) -> ()'}}
3131
let _: Int = X.unsafelyDoEverythingClosure // expected-error{{type '@Sendable (X) -> @Sendable (@MainActor @Sendable () -> Void) -> ()'}}
3232
let _: Int = (X.unsafelyDoEverythingClosure)(x) // expected-error{{type '@Sendable (@MainActor @Sendable () -> Void) -> ()'}}
3333

@@ -42,7 +42,7 @@ func testElsewhere(x: X) {
4242
let _: Int = unsafelySendableClosure // expected-error{{type '@Sendable (@Sendable () -> Void) -> ()'}}
4343
let _: Int = unsafelyMainActorClosure // expected-error{{type '@Sendable (@MainActor () -> Void) -> ()'}}
4444
let _: Int = unsafelyDoEverythingClosure // expected-error{{type '@Sendable (@MainActor @Sendable () -> Void) -> ()'}}
45-
let _: Int = x.unsafelyDoEverythingClosure // expected-error{{type '(@MainActor @Sendable () -> Void) -> ()'}}
45+
let _: Int = x.unsafelyDoEverythingClosure // expected-error{{type '@Sendable (@MainActor @Sendable () -> Void) -> ()'}}
4646
let _: Int = X.unsafelyDoEverythingClosure // expected-error{{type '@Sendable (X) -> @Sendable (@MainActor @Sendable () -> Void) -> ()'}}
4747
let _: Int = (X.unsafelyDoEverythingClosure)(x) // expected-error{{type '@Sendable (@MainActor @Sendable () -> Void) -> ()'}}
4848

test/Concurrency/sendable_keypaths.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-typecheck-verify-swift -enable-upcoming-feature InferSendableFromCaptures -strict-concurrency=complete -enable-experimental-feature GlobalActorIsolatedTypesUsability
1+
// RUN: %target-typecheck-verify-swift -enable-upcoming-feature InferSendableFromCaptures -strict-concurrency=complete -enable-upcoming-feature GlobalActorIsolatedTypesUsability
22

33
// REQUIRES: concurrency
44
// REQUIRES: asserts

0 commit comments

Comments
 (0)