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) {
5831
5831
return {};
5832
5832
};
5833
5833
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
+
5834
5840
// If we are required to use main actor... just use that.
5835
- if (ctx. LangOpts . DefaultIsolationBehavior == DefaultIsolation::MainActor)
5841
+ if (defaultIsolation == DefaultIsolation::MainActor)
5836
5842
if (auto result =
5837
5843
globalActorHelper (ctx.getMainActorType ()->mapTypeOutOfContext ()))
5838
5844
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 3
3
// REQUIRES: swift_feature_DefaultIsolationPerFile
4
4
5
5
using @MainActor
6
+ // expected-note@-1 {{default isolation was previously declared here}}
7
+
6
8
using nonisolated
9
+ // expected-error@-1 {{invalid redeclaration of file-level default actor isolation}}
7
10
8
11
using @Test // expected-error {{'using' declaration does not support 'Test' attribute}}
9
12
using test // expected-error {{'using' declaration does not support 'test' modifier}}
10
13
11
- using
12
- @MainActor
14
+ do {
15
+ using // expected-warning {{expression of type 'Int' is unused}}
16
+ @MainActor
17
+ // expected-error@+1 {{expected declaration}}
18
+ }
13
19
14
- using
15
- nonisolated
20
+ do {
21
+ using // expected-warning {{expression of type 'Int' is unused}}
22
+ nonisolated // expected-error {{cannot find 'nonisolated' in scope}}
23
+ }
16
24
17
25
do {
18
26
func
You can’t perform that action at this time.
0 commit comments