File tree Expand file tree Collapse file tree 3 files changed +62
-5
lines changed Expand file tree Collapse file tree 3 files changed +62
-5
lines changed Original file line number Diff line number Diff line change @@ -5831,8 +5831,14 @@ computeDefaultInferredActorIsolation(ValueDecl *value) {
58315831 return {};
58325832 };
58335833
5834+ DefaultIsolation defaultIsolation = ctx.LangOpts .DefaultIsolationBehavior ;
5835+ if (auto *SF = value->getDeclContext ()->getParentSourceFile ()) {
5836+ if (auto defaultIsolationInFile = SF->getDefaultIsolation ())
5837+ defaultIsolation = defaultIsolationInFile.value ();
5838+ }
5839+
58345840 // If we are required to use main actor... just use that.
5835- if (ctx. LangOpts . DefaultIsolationBehavior == DefaultIsolation::MainActor)
5841+ if (defaultIsolation == DefaultIsolation::MainActor)
58365842 if (auto result =
58375843 globalActorHelper (ctx.getMainActorType ()->mapTypeOutOfContext ()))
58385844 return *result;
Original file line number Diff line number Diff line change 1+ // RUN: %empty-directory(%t)
2+ // RUN: split-file %s %t
3+
4+ // REQUIRES: concurrency
5+ // REQUIRES: swift_feature_DefaultIsolationPerFile
6+
7+ // RUN: %target-swift-frontend -enable-experimental-feature DefaultIsolationPerFile -emit-sil -swift-version 6 -disable-availability-checking %t/main.swift %t/concurrent.swift | %FileCheck %s
8+
9+ //--- main.swift
10+
11+ using @MainActor
12+
13+ class C {
14+ // CHECK: // static C.shared.getter
15+ // CHECK-NEXT: // Isolation: global_actor. type: MainActor
16+ static let shared = C ( )
17+
18+ // CHECK: // C.init()
19+ // CHECK-NEXT: // Isolation: global_actor. type: MainActor
20+ init ( ) { }
21+ }
22+
23+ // CHECK: // test()
24+ // CHECK-NEXT: // Isolation: global_actor. type: MainActor
25+ func test( ) {
26+ // CHECK: // closure #1 in test()
27+ // CHECK-NEXT: // Isolation: nonisolated
28+ Task . detached {
29+ let s = S ( value: 0 )
30+ }
31+ }
32+
33+ //--- concurrent.swift
34+
35+ using nonisolated
36+
37+ // CHECK: // S.init(value:)
38+ // CHECK-NEXT: // Isolation: unspecified
39+ struct S {
40+ // CHECK: // S.value.getter
41+ // CHECK-NEXT: // Isolation: unspecified
42+ var value : Int
43+ }
Original file line number Diff line number Diff line change 55// REQUIRES: concurrency
66
77using @MainActor
8+ // expected-note@-1 {{default isolation was previously declared here}}
9+
810using nonisolated
11+ // expected-error@-1 {{invalid redeclaration of file-level default actor isolation}}
912
1013using @Test // expected-error {{'using' declaration does not support 'Test' attribute}}
1114using test // expected-error {{'using' declaration does not support 'test' modifier}}
1215
13- using
14- @MainActor
16+ do {
17+ using // expected-warning {{expression of type 'Int' is unused}}
18+ @MainActor
19+ // expected-error@+1 {{expected declaration}}
20+ }
1521
16- using
17- nonisolated
22+ do {
23+ using // expected-warning {{expression of type 'Int' is unused}}
24+ nonisolated // expected-error {{cannot find 'nonisolated' in scope}}
25+ }
1826
1927do {
2028 func
You can’t perform that action at this time.
0 commit comments