You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[send-non-sendable] Update concurrency tests so that we run them in all concurrency modes as appropriate.
This means that:
1. In test cases where minimal is the default (swift 5 without
-warn-concurrency), I added RUN lines for targeted, complete, and complete +
sns.
2. In test cases where complete is the default (swift 6, -warn-concurrency,
specified complete with -strict-concurrency), I added a send non-sendable run
line.
In each of these cases, I added additional expected-* lines as appropriate so
the tests can compile in each mode successfully.
// expected-warning@-1{{passing argument of non-sendable type '() -> ()' into global actor 'BananaActor'-isolated context may introduce data races}}
293
-
// expected-note@-2{{a function type must be marked '@Sendable' to conform to 'Sendable'}}
294
+
// expected-complete-warning@-1{{passing argument of non-sendable type '() -> ()' into global actor 'BananaActor'-isolated context may introduce data races}}
295
+
// expected-complete-note@-2{{a function type must be marked '@Sendable' to conform to 'Sendable'}}
// expected-warning@-1 2{{converting function value of type '@BananaActor () -> ()' to '() -> Void' loses global actor 'BananaActor'}}
301
303
302
304
awaitwisk(peelBanana)
303
-
// expected-warning@-1{{passing argument of non-sendable type '() -> ()' into global actor 'BananaActor'-isolated context may introduce data races}}
304
-
// expected-note@-2{{a function type must be marked '@Sendable' to conform to 'Sendable'}}
305
+
// expected-complete-warning@-1{{passing argument of non-sendable type '() -> ()' into global actor 'BananaActor'-isolated context may introduce data races}}
306
+
// expected-complete-note@-2{{a function type must be marked '@Sendable' to conform to 'Sendable'}}
305
307
306
308
awaitwisk(wisk)
307
-
// expected-warning@-1{{passing argument of non-sendable type '(Any) -> ()' into global actor 'BananaActor'-isolated context may introduce data races}}
308
-
// expected-note@-2{{a function type must be marked '@Sendable' to conform to 'Sendable'}}
309
+
// expected-complete-warning@-1{{passing argument of non-sendable type '(Any) -> ()' into global actor 'BananaActor'-isolated context may introduce data races}}
310
+
// expected-complete-note@-2{{a function type must be marked '@Sendable' to conform to 'Sendable'}}
309
311
await(((wisk)))(((wisk)))
310
-
// expected-warning@-1{{passing argument of non-sendable type '(Any) -> ()' into global actor 'BananaActor'-isolated context may introduce data races}}
311
-
// expected-note@-2{{a function type must be marked '@Sendable' to conform to 'Sendable'}}
312
+
// expected-complete-warning@-1{{passing argument of non-sendable type '(Any) -> ()' into global actor 'BananaActor'-isolated context may introduce data races}}
313
+
// expected-complete-note@-2{{a function type must be marked '@Sendable' to conform to 'Sendable'}}
// Verify that we don't allow actor-isolated state to be passed via inout
@@ -96,7 +100,9 @@ extension TestActor {
96
100
97
101
// external class method call
98
102
@available(SwiftStdlib 5.1,*)
99
-
classNonAsyncClass{
103
+
classNonAsyncClass{ // expected-targeted-complete-note {{class 'NonAsyncClass' does not conform to the 'Sendable' protocol}}
104
+
// expected-targeted-complete-sns-note @-1 {{class 'NonAsyncClass' does not conform to the 'Sendable' protocol}}
105
+
// expected-sns-note @-2 {{class 'NonAsyncClass' does not conform to the 'Sendable' protocol}}
100
106
func modifyOtherAsync(_ other :inoutInt)async{
101
107
// ...
102
108
}
@@ -114,20 +120,26 @@ extension TestActor {
114
120
func passStateIntoDifferentClassMethod()async{
115
121
letother=NonAsyncClass()
116
122
letotherCurry= other.modifyOtherAsync
117
-
// expected-error@+1{{actor-isolated property 'value2' cannot be passed 'inout' to 'async' function call}}
123
+
// expected-targeted-complete-sns-warning @-1 {{non-sendable type 'NonAsyncClass' exiting actor-isolated context in call to non-isolated instance method 'modifyOtherAsync' cannot cross actor boundary}}
118
124
await other.modifyOtherAsync(&value2)
119
-
// expected-error@+1{{actor-isolated property 'value1' cannot be passed 'inout' to 'async' function call}}
125
+
// expected-error @-1 {{actor-isolated property 'value2' cannot be passed 'inout' to 'async' function call}}
126
+
// expected-targeted-complete-warning @-2 {{passing argument of non-sendable type 'NonAsyncClass' outside of actor-isolated context may introduce data races}}
127
+
120
128
awaitotherCurry(&value1)
129
+
// expected-error @-1 {{actor-isolated property 'value1' cannot be passed 'inout' to 'async' function call}}
130
+
121
131
other.modifyOtherNotAsync(&value2) // This is okay since it's not async!
122
132
123
133
}
124
134
125
135
func callMutatingFunctionOnStruct()async{
136
+
// expected-targeted-complete-warning @+4 {{passing argument of non-sendable type 'inout Point' outside of actor-isolated context may introduce data races}}
126
137
// expected-error@+3:20{{cannot call mutating async function 'setComponents(x:y:)' on actor-isolated property 'position'}}
127
138
// expected-error@+2:51{{actor-isolated property 'nextPosition' cannot be passed 'inout' to 'async' function call}}
128
139
// expected-error@+1:71{{actor-isolated property 'nextPosition' cannot be passed 'inout' to 'async' function call}}
// expected-targeted-complete-warning @+4 {{passing argument of non-sendable type 'inout Point' outside of actor-isolated context may introduce data races}}
131
143
// expected-error@+3:20{{cannot call mutating async function 'setComponents(x:y:)' on actor-isolated property 'position'}}
132
144
// expected-error@+2:38{{actor-isolated property 'value1' cannot be passed 'inout' to 'async' function call}}
133
145
// expected-error@+1:50{{actor-isolated property 'value2' cannot be passed 'inout' to 'async' function call}}
@@ -201,20 +213,26 @@ struct MyGlobalActor {
201
213
}
202
214
203
215
@MyGlobalActorvarnumber:Int=0
204
-
// expected-note@-1{{var declared here}}
205
-
// expected-note@-2{{var declared here}}
206
-
// expected-note@-3{{mutation of this var is only permitted within the actor}}
216
+
// expected-note @-1 {{var declared here}}
217
+
// expected-note @-2 {{var declared here}}
218
+
// expected-note @-3 {{mutation of this var is only permitted within the actor}}
219
+
// expected-complete-sns-error @-4 {{top-level code variables cannot have a global actor}}
220
+
// expected-complete-sns-note @-5 4{{mutation of this var is only permitted within the actor}}
221
+
207
222
208
-
// expected-error@+3{{actor-isolated var 'number' cannot be passed 'inout' to 'async' function call}}
209
-
// expected-error@+2{{global actor 'MyGlobalActor'-isolated var 'number' can not be used 'inout' from a non-isolated context}}
210
223
if #available(SwiftStdlib 5.1,*){
211
-
let _ =Task.detached{await{(_ foo:inoutInt)asyncin foo +=1}(&number)}
224
+
let _ =Task.detached{await{(_ foo:inoutInt)asyncin foo +=1}(&number)}
225
+
// expected-error @-1 {{actor-isolated var 'number' cannot be passed 'inout' to 'async' function call}}
226
+
// expected-minimal-targeted-error @-2 {{global actor 'MyGlobalActor'-isolated var 'number' can not be used 'inout' from a non-isolated context}}
227
+
// expected-complete-sns-error @-3 {{main actor-isolated var 'number' can not be used 'inout' from a non-isolated context}}
212
228
}
213
229
214
230
// attempt to pass global state owned by the global actor to another async function
215
-
// expected-error@+2{{actor-isolated var 'number' cannot be passed 'inout' to 'async' function call}}
@MainActor(unsafe)func globalMain(){} // expected-note {{calls to global function 'globalMain()' from outside of its actor context are implicitly asynchronous}}
10
14
11
15
@SomeGlobalActor(unsafe)func globalSome(){} // expected-note 2{{calls to global function 'globalSome()' from outside of its actor context are implicitly asynchronous}}
16
+
// expected-complete-sns-note @-1 {{calls to global function 'globalSome()' from outside of its actor context are implicitly asynchronous}}
@MainActor(unsafe)func onMainActor() // expected-note{{mark the protocol requirement 'onMainActor()' 'async' to allow actor-isolated conformances}}
23
+
// expected-complete-sns-note @-1 {{mark the protocol requirement 'onMainActor()' 'async' to allow actor-isolated conformances}}
18
24
}
19
25
20
26
structS1_P1:P1{
@@ -31,6 +37,7 @@ struct S3_P1: P1 {
31
37
32
38
structS4_P1_quietly:P1{
33
39
@SomeGlobalActorfunc onMainActor(){}
40
+
// expected-complete-sns-warning @-1 {{global actor 'SomeGlobalActor'-isolated instance method 'onMainActor()' cannot be used to satisfy main actor-isolated protocol requirement}}
34
41
}
35
42
36
43
@SomeGlobalActor
@@ -42,11 +49,13 @@ struct S4_P1: P1 {
42
49
@MainActor(unsafe)
43
50
protocolP2{
44
51
func f() // expected-note{{calls to instance method 'f()' from outside of its actor context are implicitly asynchronous}}
52
+
// expected-complete-sns-note @-1 {{calls to instance method 'f()' from outside of its actor context are implicitly asynchronous}}
45
53
nonisolatedfunc g()
46
54
}
47
55
48
56
structS5_P2:P2{
49
57
func f(){} // expected-note{{calls to instance method 'f()' from outside of its actor context are implicitly asynchronous}}
58
+
// expected-complete-sns-note @-1 {{calls to instance method 'f()' from outside of its actor context are implicitly asynchronous}}
// expected-complete-sns-note @-1 2{{add '@MainActor' to make global function 'testP2_noconcurrency(x:p2:)' part of global actor 'MainActor'}}
71
+
p2.f() // okay without complete. with targeted/minimal not concurrency-related code.
72
+
// expected-complete-sns-error @-1 {{call to main actor-isolated instance method 'f()' in a synchronous nonisolated context}}
62
73
p2.g() // okay
63
-
x.f() // okay, not concurrency-related code
74
+
x.f() // okay without complete. with targeted/minimal not concurrency-related code
75
+
// expected-complete-sns-error @-1 {{call to main actor-isolated instance method 'f()' in a synchronous nonisolated context}}
64
76
x.g() // OKAY
65
77
}
66
78
@@ -73,7 +85,8 @@ class C1 {
73
85
74
86
classC2:C1{
75
87
overridefunc method(){ // expected-note 2{{overridden declaration is here}}
76
-
globalSome() // okay
88
+
globalSome() // okay when not in complete
89
+
// expected-complete-sns-error @-1 {{call to global actor 'SomeGlobalActor'-isolated global function 'globalSome()' in a synchronous main actor-isolated context}}
0 commit comments