File tree Expand file tree Collapse file tree 5 files changed +41
-7
lines changed Expand file tree Collapse file tree 5 files changed +41
-7
lines changed Original file line number Diff line number Diff line change @@ -3634,9 +3634,7 @@ class AnyFunctionType : public TypeBase {
3634
3634
return getExtInfo ().isNoEscape ();
3635
3635
}
3636
3636
3637
- bool isSendable () const {
3638
- return getExtInfo ().isSendable ();
3639
- }
3637
+ bool isSendable () const ;
3640
3638
3641
3639
bool isAsync () const { return getExtInfo ().isAsync (); }
3642
3640
Original file line number Diff line number Diff line change @@ -3895,6 +3895,15 @@ Type AnyFunctionType::getThrownError() const {
3895
3895
}
3896
3896
}
3897
3897
3898
+ bool AnyFunctionType::isSendable () const {
3899
+ auto &ctx = getASTContext ();
3900
+ if (ctx.LangOpts .hasFeature (Feature::GlobalActorIsolatedTypesUsability)) {
3901
+ // Global-actor-isolated function types are implicitly Sendable.
3902
+ return getExtInfo ().isSendable () || getIsolation ().isGlobalActor ();
3903
+ }
3904
+ return getExtInfo ().isSendable ();
3905
+ }
3906
+
3898
3907
Type AnyFunctionType::getGlobalActor () const {
3899
3908
switch (getKind ()) {
3900
3909
case TypeKind::Function:
Original file line number Diff line number Diff line change @@ -4181,15 +4181,21 @@ bool ActorIsolationChecker::mayExecuteConcurrentlyWith(
4181
4181
if (useIsolation == defIsolation)
4182
4182
return false ;
4183
4183
4184
+ auto &ctx = useContext->getASTContext ();
4185
+ bool regionIsolationEnabled =
4186
+ ctx.LangOpts .hasFeature (Feature::RegionBasedIsolation);
4187
+
4188
+ // Globally-isolated closures may never be executed concurrently.
4189
+ if (ctx.LangOpts .hasFeature (Feature::GlobalActorIsolatedTypesUsability) &&
4190
+ regionIsolationEnabled && useIsolation.isGlobalActor ())
4191
+ return false ;
4192
+
4184
4193
// If the local function is not Sendable, its isolation differs
4185
4194
// from that of the context, and both contexts are actor isolated,
4186
4195
// then capturing non-Sendable values allows the closure to stash
4187
4196
// those values into actor isolated state. The original context
4188
4197
// may also stash those values into isolated state, enabling concurrent
4189
4198
// access later on.
4190
- auto &ctx = useContext->getASTContext ();
4191
- bool regionIsolationEnabled =
4192
- ctx.LangOpts .hasFeature (Feature::RegionBasedIsolation);
4193
4199
isolatedStateMayEscape =
4194
4200
(!regionIsolationEnabled &&
4195
4201
useIsolation.isActorIsolated () && defIsolation.isActorIsolated ());
Original file line number Diff line number Diff line change @@ -559,7 +559,7 @@ extension MyActor {
559
559
560
560
func testBadImplicitGlobalActorClosureCall( ) async {
561
561
{ @MainActor in } ( ) // expected-error{{expression is 'async' but is not marked with 'await'}}
562
- // expected-note@-1{{calls function of type '@MainActor () -> ()' from outside of its actor context are implicitly asynchronous}}
562
+ // expected-note@-1{{calls function of type '@MainActor @Sendable () -> ()' from outside of its actor context are implicitly asynchronous}}
563
563
}
564
564
565
565
Original file line number Diff line number Diff line change
1
+ // RUN: %target-typecheck-verify-swift -strict-concurrency=complete -disable-availability-checking -enable-upcoming-feature RegionBasedIsolation -enable-experimental-feature GlobalActorIsolatedTypesUsability
2
+
3
+ // REQUIRES: concurrency
4
+ // REQUIRES: asserts
5
+
6
+ func inferSendableFunctionType( ) {
7
+ let closure : @MainActor ( ) -> Void = { }
8
+
9
+ Task {
10
+ await closure ( ) // okay
11
+ }
12
+ }
13
+
14
+ class NonSendable { }
15
+
16
+ func allowNonSendableCaptures( ) {
17
+ let nonSendable = NonSendable ( )
18
+ let _: @MainActor ( ) -> Void = {
19
+ let _ = nonSendable // okay
20
+ }
21
+ }
You can’t perform that action at this time.
0 commit comments