Skip to content

Commit 223a9ee

Browse files
committed
[Concurrency] split global variable tests from experimental feature strict concurrency tests
1 parent e8945ac commit 223a9ee

File tree

2 files changed

+83
-79
lines changed

2 files changed

+83
-79
lines changed

test/Concurrency/experimental_feature_strictconcurrency.swift

Lines changed: 5 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
1-
// RUN: %empty-directory(%t)
2-
// RUN: %target-swift-frontend -emit-module -emit-module-path %t/GlobalVariables.swiftmodule -module-name GlobalVariables -parse-as-library -strict-concurrency=minimal -swift-version 5 %S/Inputs/GlobalVariables.swift
3-
// RUN: %target-swift-frontend -disable-availability-checking -parse-as-library -enable-experimental-feature StrictConcurrency -enable-experimental-feature GlobalConcurrency -swift-version 6 -I %t %s %s -emit-sil -o /dev/null -verify %s
4-
// RUN: %target-swift-frontend -disable-availability-checking -parse-as-library -enable-experimental-feature StrictConcurrency=complete -enable-experimental-feature GlobalConcurrency -swift-version 6 -I %t %s %s -emit-sil -o /dev/null -verify %s
5-
// RUN: %target-swift-frontend -disable-availability-checking -parse-as-library -enable-experimental-feature StrictConcurrency=complete -enable-experimental-feature GlobalConcurrency -swift-version 6 -I %t %s %s -emit-sil -o /dev/null -verify -verify-additional-prefix region-isolation- -enable-experimental-feature RegionBasedIsolation %s
1+
// RUN: %target-swift-frontend -disable-availability-checking -enable-experimental-feature StrictConcurrency -emit-sil -o /dev/null -verify %s
2+
// RUN: %target-swift-frontend -disable-availability-checking -enable-experimental-feature StrictConcurrency=complete -emit-sil -o /dev/null -verify %s
3+
// RUN: %target-swift-frontend -disable-availability-checking -enable-experimental-feature StrictConcurrency=complete -emit-sil -o /dev/null -verify -verify-additional-prefix region-isolation- -enable-experimental-feature RegionBasedIsolation %s
64

75
// REQUIRES: concurrency
86
// REQUIRES: asserts
97

10-
@preconcurrency import GlobalVariables
11-
128
class C1 { } // expected-note{{class 'C1' does not conform to the 'Sendable' protocol}}
139
class C2 { }
1410

@@ -19,85 +15,15 @@ protocol TestProtocol {
1915
associatedtype Value: Sendable
2016
}
2117

22-
struct Test1: TestProtocol { // expected-error{{type 'Test1.Value' (aka 'C1') does not conform to the 'Sendable' protocol}}
18+
struct Test1: TestProtocol { // expected-warning{{type 'Test1.Value' (aka 'C1') does not conform to the 'Sendable' protocol}}
2319
typealias Value = C1
2420
}
2521

26-
struct Test2: TestProtocol { // expected-error{{conformance of 'C2' to 'Sendable' is unavailable}}
22+
struct Test2: TestProtocol { // expected-warning{{conformance of 'C2' to 'Sendable' is unavailable}}
2723
// expected-note@-1{{in associated type 'Self.Value' (inferred as 'C2')}}
2824
typealias Value = C2
2925
}
3026

31-
@globalActor
32-
actor TestGlobalActor {
33-
static var shared = TestGlobalActor()
34-
}
35-
36-
@TestGlobalActor
37-
var mutableIsolatedGlobal = 1
38-
39-
var mutableNonisolatedGlobal = 1 // expected-error{{var 'mutableNonisolatedGlobal' is not concurrency-safe because it is non-isolated global shared mutable state}}
40-
// expected-note@-1{{isolate 'mutableNonisolatedGlobal' to a global actor, or convert it to a 'let' constant and conform it to 'Sendable'}}
41-
42-
let immutableGlobal = 1
43-
44-
final class TestSendable: Sendable {
45-
init() {}
46-
}
47-
48-
final class TestNonsendable {
49-
init() {}
50-
}
51-
52-
nonisolated(unsafe) let immutableNonisolatedUnsafeTopLevelGlobal = TestNonsendable()
53-
54-
@propertyWrapper
55-
public struct TestWrapper {
56-
public init() {}
57-
public var wrappedValue: Int {
58-
return 0
59-
}
60-
}
61-
62-
struct TestStatics {
63-
static let immutableExplicitSendable = TestSendable()
64-
static let immutableNonsendable = TestNonsendable() // expected-error{{static property 'immutableNonsendable' is not concurrency-safe because it is not either conforming to 'Sendable' or isolated to a global actor}}
65-
static nonisolated(unsafe) let immutableNonisolatedUnsafe = TestNonsendable()
66-
static nonisolated let immutableNonisolated = TestNonsendable() // expected-error{{static property 'immutableNonisolated' is not concurrency-safe because it is not either conforming to 'Sendable' or isolated to a global actor}}
67-
static let immutableInferredSendable = 0
68-
static var mutable = 0 // expected-error{{static property 'mutable' is not concurrency-safe because it is non-isolated global shared mutable state}}
69-
// expected-note@-1{{isolate 'mutable' to a global actor, or convert it to a 'let' constant and conform it to 'Sendable'}}
70-
// expected-note@-2{{static property declared here}}
71-
static var computedProperty: Int { 0 } // computed property that, though static, has no storage so is not a global
72-
@TestWrapper static var wrapped: Int // expected-error{{static property 'wrapped' is not concurrency-safe because it is non-isolated global shared mutable state}}
73-
// expected-note@-1{{isolate 'wrapped' to a global actor, or convert it to a 'let' constant and conform it to 'Sendable'}}
74-
}
75-
76-
@TestGlobalActor
77-
func f() {
78-
print(TestStatics.immutableExplicitSendable)
79-
print(TestStatics.immutableInferredSendable)
80-
print(TestStatics.mutable) // expected-error{{reference to static property 'mutable' is not concurrency-safe because it involves shared mutable state}}
81-
print(Globals.actorInteger) // expected-error{{main actor-isolated static property 'actorInteger' can not be referenced from global actor 'TestGlobalActor'}}
82-
}
83-
84-
func testLocalNonisolatedUnsafe() async {
85-
nonisolated(unsafe) var value = 1
86-
let task = Task {
87-
value = 2
88-
return value
89-
}
90-
print(await task.value)
91-
}
92-
93-
func testCGlobals() { // expected-note{{add '@MainActor' to make global function 'testCGlobals()' part of global actor 'MainActor'}}
94-
let _ = Globals.integerConstant
95-
let _ = Globals.integerMutable // expected-warning{{reference to static property 'integerMutable' is not concurrency-safe because it involves shared mutable state}}
96-
let _ = Globals.nonisolatedUnsafeIntegerConstant
97-
let _ = Globals.nonisolatedUnsafeIntegerMutable
98-
let _ = Globals.actorInteger // expected-error{{main actor-isolated static property 'actorInteger' can not be referenced from a non-isolated context}}
99-
}
100-
10127
@MainActor
10228
func iterate(stream: AsyncStream<Int>) async {
10329
nonisolated(unsafe) var it = stream.makeAsyncIterator()
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-frontend -emit-module -emit-module-path %t/GlobalVariables.swiftmodule -module-name GlobalVariables -parse-as-library -strict-concurrency=minimal -swift-version 5 %S/Inputs/GlobalVariables.swift
3+
// RUN: %target-swift-frontend -disable-availability-checking -parse-as-library -enable-experimental-feature StrictConcurrency=complete -enable-experimental-feature GlobalConcurrency -swift-version 6 -I %t %s %s -emit-sil -o /dev/null -verify %s
4+
5+
// REQUIRES: concurrency
6+
// REQUIRES: asserts
7+
8+
@preconcurrency import GlobalVariables
9+
10+
@globalActor
11+
actor TestGlobalActor {
12+
static var shared = TestGlobalActor()
13+
}
14+
15+
@TestGlobalActor
16+
var mutableIsolatedGlobal = 1
17+
18+
var mutableNonisolatedGlobal = 1 // expected-error{{var 'mutableNonisolatedGlobal' is not concurrency-safe because it is non-isolated global shared mutable state}}
19+
// expected-note@-1{{isolate 'mutableNonisolatedGlobal' to a global actor, or convert it to a 'let' constant and conform it to 'Sendable'}}
20+
21+
let immutableGlobal = 1
22+
23+
final class TestSendable: Sendable {
24+
init() {}
25+
}
26+
27+
final class TestNonsendable {
28+
init() {}
29+
}
30+
31+
nonisolated(unsafe) let immutableNonisolatedUnsafeTopLevelGlobal = TestNonsendable()
32+
33+
@propertyWrapper
34+
public struct TestWrapper {
35+
public init() {}
36+
public var wrappedValue: Int {
37+
return 0
38+
}
39+
}
40+
41+
struct TestStatics {
42+
static let immutableExplicitSendable = TestSendable()
43+
static let immutableNonsendable = TestNonsendable() // expected-error{{static property 'immutableNonsendable' is not concurrency-safe because it is not either conforming to 'Sendable' or isolated to a global actor}}
44+
static nonisolated(unsafe) let immutableNonisolatedUnsafe = TestNonsendable()
45+
static nonisolated let immutableNonisolated = TestNonsendable() // expected-error{{static property 'immutableNonisolated' is not concurrency-safe because it is not either conforming to 'Sendable' or isolated to a global actor}}
46+
static let immutableInferredSendable = 0
47+
static var mutable = 0 // expected-error{{static property 'mutable' is not concurrency-safe because it is non-isolated global shared mutable state}}
48+
// expected-note@-1{{isolate 'mutable' to a global actor, or convert it to a 'let' constant and conform it to 'Sendable'}}
49+
// expected-note@-2{{static property declared here}}
50+
static var computedProperty: Int { 0 } // computed property that, though static, has no storage so is not a global
51+
@TestWrapper static var wrapped: Int // expected-error{{static property 'wrapped' is not concurrency-safe because it is non-isolated global shared mutable state}}
52+
// expected-note@-1{{isolate 'wrapped' to a global actor, or convert it to a 'let' constant and conform it to 'Sendable'}}
53+
}
54+
55+
@TestGlobalActor
56+
func f() {
57+
print(TestStatics.immutableExplicitSendable)
58+
print(TestStatics.immutableInferredSendable)
59+
print(TestStatics.mutable) // expected-error{{reference to static property 'mutable' is not concurrency-safe because it involves shared mutable state}}
60+
print(Globals.actorInteger) // expected-error{{main actor-isolated static property 'actorInteger' can not be referenced from global actor 'TestGlobalActor'}}
61+
}
62+
63+
func testLocalNonisolatedUnsafe() async {
64+
nonisolated(unsafe) var value = 1
65+
let task = Task {
66+
value = 2
67+
return value
68+
}
69+
print(await task.value)
70+
}
71+
72+
func testImportedGlobals() { // expected-note{{add '@MainActor' to make global function 'testImportedGlobals()' part of global actor 'MainActor'}}
73+
let _ = Globals.integerConstant
74+
let _ = Globals.integerMutable // expected-warning{{reference to static property 'integerMutable' is not concurrency-safe because it involves shared mutable state}}
75+
let _ = Globals.nonisolatedUnsafeIntegerConstant
76+
let _ = Globals.nonisolatedUnsafeIntegerMutable
77+
let _ = Globals.actorInteger // expected-error{{main actor-isolated static property 'actorInteger' can not be referenced from a non-isolated context}}
78+
}

0 commit comments

Comments
 (0)