Skip to content

Commit 70a1ec3

Browse files
committed
test updates
1 parent 0f415f5 commit 70a1ec3

9 files changed

+156
-39
lines changed

test/Concurrency/actor_call_implicitly_async.swift

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -356,25 +356,17 @@ actor Calculator {
356356
}
357357

358358
@OrangeActor func doSomething() async {
359+
// We will error on the next line when we get past type checking. But since we
360+
// error in the type checker, we do not make further progress.
359361
let _ = (await bananaAdd(1))(2)
360-
// expected-warning@-1{{non-sendable result type '(Int) -> Int' cannot be sent from global actor 'BananaActor'-isolated context in call to global function 'bananaAdd'}}
361-
// expected-note@-2{{a function type must be marked '@Sendable' to conform to 'Sendable'}}
362362
let _ = await (await bananaAdd(1))(2) // expected-warning{{no 'async' operations occur within 'await' expression}}
363-
// expected-warning@-1{{non-sendable result type '(Int) -> Int' cannot be sent from global actor 'BananaActor'-isolated context in call to global function 'bananaAdd'}}
364-
// expected-note@-2{{a function type must be marked '@Sendable' to conform to 'Sendable'}}
365363

366364
let calc = Calculator()
367365

368366
let _ = (await calc.addCurried(1))(2)
369-
// expected-warning@-1{{non-sendable result type '(Int) -> Int' cannot be sent from actor-isolated context in call to instance method 'addCurried'}}
370-
// expected-note@-2{{a function type must be marked '@Sendable' to conform to 'Sendable'}}
371367
let _ = await (await calc.addCurried(1))(2) // expected-warning{{no 'async' operations occur within 'await' expression}}
372-
// expected-warning@-1{{non-sendable result type '(Int) -> Int' cannot be sent from actor-isolated context in call to instance method 'addCurried'}}
373-
// expected-note@-2{{a function type must be marked '@Sendable' to conform to 'Sendable'}}
374368

375369
let plusOne = await calc.addCurried(await calc.add(0, 1))
376-
// expected-warning@-1{{non-sendable result type '(Int) -> Int' cannot be sent from actor-isolated context in call to instance method 'addCurried'}}
377-
// expected-note@-2{{a function type must be marked '@Sendable' to conform to 'Sendable'}}
378370
let _ = plusOne(2)
379371
}
380372

test/Concurrency/concurrent_value_checking.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// REQUIRES: concurrency
66
// REQUIRES: asserts
77

8-
class NotConcurrent { } // expected-note 13{{class 'NotConcurrent' does not conform to the 'Sendable' protocol}}
8+
class NotConcurrent { } // expected-note 12{{class 'NotConcurrent' does not conform to the 'Sendable' protocol}}
99
// expected-tns-allow-typechecker-note @-1 {{class 'NotConcurrent' does not conform to the 'Sendable' protocol}}
1010

1111
// ----------------------------------------------------------------------
@@ -102,7 +102,7 @@ extension A1 {
102102
_ = other.localLet // expected-warning{{non-sendable type 'NotConcurrent' of property 'localLet' cannot exit actor-isolated context}}
103103
// expected-warning@-1 {{expression is 'async' but is not marked with 'await'}}
104104
// expected-note@-2 {{property access is 'async'}}
105-
_ = await other.synchronous() // expected-warning{{non-sendable result type 'NotConcurrent?' cannot be sent from actor-isolated context in call to instance method 'synchronous()'}}
105+
_ = await other.synchronous() // expected-tns-warning {{non-Sendable 'NotConcurrent?'-typed result can not be returned from actor-isolated instance method 'synchronous()' to actor-isolated context}}
106106
_ = await other.asynchronous(nil)
107107
}
108108
}
@@ -164,7 +164,7 @@ struct HasSubscript {
164164
subscript (i: Int) -> NotConcurrent? { nil }
165165
}
166166

167-
class ClassWithGlobalActorInits { // expected-note 2{{class 'ClassWithGlobalActorInits' does not conform to the 'Sendable' protocol}}
167+
class ClassWithGlobalActorInits { // expected-tns-note 2{{class 'ClassWithGlobalActorInits' does not conform to the 'Sendable' protocol}}
168168
@SomeGlobalActor
169169
init(_: NotConcurrent) { }
170170

@@ -182,10 +182,10 @@ func globalTestMain(nc: NotConcurrent) async {
182182
// expected-tns-note @-1 {{sending global actor 'SomeGlobalActor'-isolated 'a' to global actor 'SomeGlobalActor'-isolated global function 'globalAsync' risks causing data races between global actor 'SomeGlobalActor'-isolated and local main actor-isolated uses}}
183183
await globalSync(a) // expected-tns-note {{access can happen concurrently}}
184184
_ = await ClassWithGlobalActorInits(nc)
185-
// expected-warning @-1 {{non-sendable result type 'ClassWithGlobalActorInits' cannot be sent from global actor 'SomeGlobalActor'-isolated context in call to initializer 'init(_:)'}}
185+
// expected-tns-warning @-1 {{non-Sendable 'ClassWithGlobalActorInits'-typed result can not be returned from global actor 'SomeGlobalActor'-isolated initializer 'init(_:)' to main actor-isolated context}}
186186
// expected-tns-warning @-2 {{sending 'nc' risks causing data races}}
187187
// expected-tns-note @-3 {{sending main actor-isolated 'nc' to global actor 'SomeGlobalActor'-isolated initializer 'init(_:)' risks causing data races between global actor 'SomeGlobalActor'-isolated and main actor-isolated uses}}
188-
_ = await ClassWithGlobalActorInits() // expected-warning{{non-sendable result type 'ClassWithGlobalActorInits' cannot be sent from global actor 'SomeGlobalActor'-isolated context in call to initializer 'init()'}}
188+
_ = await ClassWithGlobalActorInits() // expected-tns-warning {{non-Sendable 'ClassWithGlobalActorInits'-typed result can not be returned from global actor 'SomeGlobalActor'-isolated initializer 'init()' to main actor-isolated context}}
189189
}
190190

191191
@SomeGlobalActor

test/Concurrency/sendable_checking.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
@available(SwiftStdlib 5.1, *)
99
struct NS1 { }
10-
// expected-note @-1 {{consider making struct 'NS1' conform to the 'Sendable' protocol}}
1110

1211
@available(SwiftStdlib 5.1, *)
1312
@available(*, unavailable)
@@ -96,7 +95,7 @@ public actor MyActor: MyProto {
9695
await nonisolatedAsyncFunc1(ns1)
9796
// expected-tns-warning @-1 {{sending 'ns1' risks causing data races}}
9897
// expected-tns-note @-2 {{sending 'self'-isolated 'ns1' to nonisolated global function 'nonisolatedAsyncFunc1' risks causing data races between nonisolated and 'self'-isolated uses}}
99-
_ = await nonisolatedAsyncFunc2() // expected-warning{{non-sendable result type 'NS1' cannot be sent from nonisolated context in call to global function 'nonisolatedAsyncFunc2()'}}
98+
_ = await nonisolatedAsyncFunc2()
10099
}
101100
}
102101

test/Concurrency/sendable_module_checking.swift

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
// RUN: %target-swift-frontend -emit-module -emit-module-path %t/StrictModule.swiftmodule -module-name StrictModule -strict-concurrency=complete %S/Inputs/StrictModule.swift
33
// RUN: %target-swift-frontend -emit-module -emit-module-path %t/NonStrictModule.swiftmodule -module-name NonStrictModule %S/Inputs/NonStrictModule.swift
44

5-
// We leave this as just type check since we are checking something that is cross module.
6-
// RUN: %target-swift-frontend -typecheck -strict-concurrency=targeted -disable-availability-checking -I %t 2>&1 %s | %FileCheck %s
5+
// RUN: %target-swift-frontend -c -strict-concurrency=complete -disable-availability-checking -I %t 2>&1 %s | %FileCheck %s
76

87
// REQUIRES: concurrency
98

@@ -15,9 +14,9 @@ actor A {
1514
}
1615

1716
func testA(a: A) async {
18-
_ = await a.f() // CHECK: warning: cannot call function returning non-sendable type '[StrictStruct : NonStrictClass]' across actors}}
19-
// CHECK: note: struct 'StrictStruct' does not conform to the 'Sendable' protocol
20-
// CHECK: note: class 'NonStrictClass' does not conform to the 'Sendable' protocol
17+
_ = await a.f()
18+
// CHECK: warning: non-Sendable '[StrictStruct : NonStrictClass]'-typed result can not be returned from actor-isolated instance method 'f()' to nonisolated context; this is an error in the Swift 6 language mode
19+
// CHECK: note: note: generic struct 'Dictionary' does not conform to the 'Sendable' protocol
2120
}
2221

2322
extension NonStrictStruct: @unchecked Sendable { }

test/Concurrency/transfernonsendable.sil

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import _Concurrency
2121

2222
class Klass {}
2323

24-
class NonSendableKlass {
24+
class NonSendableKlass { // expected-note 2{{}}
2525
var klass: Klass
2626

2727
func asyncCall() async
@@ -121,10 +121,6 @@ bb0(%0 : $*{ var NonSendableKlass }):
121121
return %9999 : $()
122122
}
123123

124-
// This doesn't error since the @out parameter is not transferred when it is initialized.
125-
//
126-
// DISCUSSION: The frontend prevents us from using such a value. But we
127-
// shouldn't crash on such values.
128124
sil [ossa] @transfer_does_not_transfer_out_parameters_1 : $@convention(thin) @async () -> () {
129125
bb0:
130126
%0 = alloc_stack $NonSendableKlass
@@ -133,7 +129,7 @@ bb0:
133129

134130
%1 = alloc_stack $NonSendableKlass
135131
%f = function_ref @transferIndirectWithOutResult : $@convention(thin) @async <τ_0_0> (@in_guaranteed τ_0_0) -> @out τ_0_0
136-
apply [caller_isolation=nonisolated] [callee_isolation=global_actor] %f<NonSendableKlass>(%1, %0) : $@convention(thin) @async <τ_0_0> (@in_guaranteed τ_0_0) -> @out τ_0_0
132+
apply [caller_isolation=nonisolated] [callee_isolation=global_actor] %f<NonSendableKlass>(%1, %0) : $@convention(thin) @async <τ_0_0> (@in_guaranteed τ_0_0) -> @out τ_0_0 // expected-warning {{}}
137133

138134
%useIndirect = function_ref @useIndirect : $@convention(thin) <τ_0_0> (@in_guaranteed τ_0_0) -> ()
139135
apply %useIndirect<NonSendableKlass>(%1) : $@convention(thin) <τ_0_0> (@in_guaranteed τ_0_0) -> ()
@@ -155,7 +151,7 @@ bb0:
155151

156152
%1 = alloc_stack $NonSendableKlass
157153
%f = function_ref @transferIndirectWithOutResult : $@convention(thin) @async <τ_0_0> (@in_guaranteed τ_0_0) -> @out τ_0_0
158-
apply [caller_isolation=nonisolated] [callee_isolation=global_actor] %f<NonSendableKlass>(%1, %0) : $@convention(thin) @async <τ_0_0> (@in_guaranteed τ_0_0) -> @out τ_0_0
154+
apply [caller_isolation=nonisolated] [callee_isolation=global_actor] %f<NonSendableKlass>(%1, %0) : $@convention(thin) @async <τ_0_0> (@in_guaranteed τ_0_0) -> @out τ_0_0 // expected-warning {{}}
159155

160156
%f2 = function_ref @transferIndirect : $@convention(thin) @async <τ_0_0> (@in_guaranteed τ_0_0) -> ()
161157
apply [caller_isolation=nonisolated] [callee_isolation=global_actor] %f2<NonSendableKlass>(%1) : $@convention(thin) @async <τ_0_0> (@in_guaranteed τ_0_0) -> ()

test/Concurrency/transfernonsendable_asynclet.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class NonSendableKlass {
1818

1919
class SendableKlass : @unchecked Sendable {}
2020

21-
struct NonSendableStruct { // expected-note {{}}
21+
struct NonSendableStruct {
2222
var ns = NonSendableKlass()
2323
}
2424

@@ -722,7 +722,7 @@ func asyncLetWithoutCapture() async {
722722
//
723723
// NOTE: Error below will go away in next commit.
724724
async let x: NonSendableKlass = await returnValueFromMain()
725-
// expected-warning @-1 {{non-sendable result type 'NonSendableKlass' cannot be sent from main actor-isolated context in call to global function 'returnValueFromMain()'}}
725+
// expected-warning @-1 {{non-Sendable 'NonSendableKlass'-typed result can not be returned from main actor-isolated global function 'returnValueFromMain()' to nonisolated context}}
726726
let y = await x
727727
await transferToMain(y) // expected-warning {{sending 'y' risks causing data races}}
728728
// expected-note @-1 {{sending 'y' to main actor-isolated global function 'transferToMain' risks causing data races between main actor-isolated and local nonisolated uses}}
@@ -774,7 +774,6 @@ extension NonSendableStruct {
774774
async let subTask6: NonSendableStruct = self
775775
// expected-warning @-1 {{sending 'self' risks causing data races}}
776776
// expected-note @-2 {{sending 'actor'-isolated 'self' into async let risks causing data races between nonisolated and 'actor'-isolated uses}}
777-
// expected-warning @-3 {{non-sendable result type 'NonSendableStruct' cannot be sent from nonisolated context in call to async function}}
778777
_ = await subTask6
779778
}
780779
}

test/Concurrency/transfernonsendable_defer_and_typecheck_only.swift

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
*/
1515

1616
class NonSendable {
17-
// expected-note@-1 3{{class 'NonSendable' does not conform to the 'Sendable' protocol}}
1817
var x = 0
1918
}
2019

@@ -31,10 +30,8 @@ func callActorFuncsFromNonisolated(a : A, ns : NonSendable) async {
3130
// Non-sendable value passed from actor isolated to nonisolated
3231

3332
await a.actorTakesNS(ns)
34-
//deferred-warning@-1{{passing argument of non-sendable type 'NonSendable' into actor-isolated context may introduce data races}}
3533

3634
_ = await a.actorRetsNS()
37-
//expected-warning@-1{{non-sendable result type 'NonSendable' cannot be sent from actor-isolated context in call to instance method 'actorRetsNS()'}}
3835
}
3936

4037
@available(SwiftStdlib 5.1, *)
@@ -52,7 +49,6 @@ actor A {
5249
//deferred-warning@-1{{passing argument of non-sendable type 'NonSendable' outside of actor-isolated context may introduce data races}}
5350

5451
_ = await retsNS()
55-
//expected-warning@-1{{non-sendable result type 'NonSendable' cannot be sent from nonisolated context in call to global function 'retsNS()'}}
5652
}
5753

5854
func callActorFuncsFromDiffActor(ns : NonSendable, a : A) async {
@@ -62,6 +58,5 @@ actor A {
6258
//deferred-warning@-1{{passing argument of non-sendable type 'NonSendable' into actor-isolated context may introduce data races}}
6359

6460
_ = await a.actorRetsNS()
65-
//expected-warning@-1{{non-sendable result type 'NonSendable' cannot be sent from actor-isolated context in call to instance method 'actorRetsNS()'}}
6661
}
6762
}
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
// RUN: %target-swift-frontend -target %target-swift-5.1-abi-triple -swift-version 6 -parse-as-library %s -emit-sil -o /dev/null -verify
2+
3+
// REQUIRES: asserts
4+
// REQUIRES: concurrency
5+
6+
///////////////////////
7+
// MARK: Declaration //
8+
///////////////////////
9+
10+
actor Custom {
11+
}
12+
13+
@globalActor
14+
struct CustomActor {
15+
static var shared: Custom {
16+
return Custom()
17+
}
18+
}
19+
20+
class NonSendable {} // expected-note 3{{}}
21+
22+
func passNonSendable(_: NonSendable) async { }
23+
24+
func returnsNonSendable() async -> NonSendable { NonSendable() }
25+
26+
@MainActor
27+
func mainActorPassNonSendable(_: NonSendable) async { }
28+
29+
@MainActor
30+
func mainActorReturnNonSendable() async -> NonSendable { NonSendable() }
31+
32+
@MainActor
33+
func mainActorGenericPassNonSendable<T>(_: T) async { }
34+
35+
@MainActor
36+
func mainActorGenericReturnNonSendable<T>() async -> T { fatalError() }
37+
38+
@MainActor
39+
func mainActorAsyncFunc3() async -> ((Int) -> Int) {
40+
return { (_ y: Int) in y }
41+
}
42+
43+
/////////////////
44+
// MARK: Tests //
45+
/////////////////
46+
47+
@MainActor func mainActorResult(_ x : Int) -> ((Int) -> Int) {
48+
return { (_ y : Int) in x + y }
49+
}
50+
51+
actor Calculator {
52+
func addCurried(_ x : Int) -> ((Int) -> Int) {
53+
return { (_ y : Int) in x + y }
54+
}
55+
56+
func add(_ x : Int, _ y : Int) -> Int {
57+
return x + y
58+
}
59+
}
60+
61+
@CustomActor
62+
func testActorCrossingBoundary() async {
63+
let _ = (await mainActorResult(1))(5)
64+
// expected-error @-1 {{non-Sendable '(Int) -> Int'-typed result can not be returned from main actor-isolated global function 'mainActorResult' to global actor 'CustomActor'-isolated context}}
65+
// expected-note @-2 {{a function type must be marked '@Sendable' to conform to 'Sendable'}}
66+
let _ = await (await mainActorResult(1))(2)
67+
// expected-error @-1 {{non-Sendable '(Int) -> Int'-typed result can not be returned from main actor-isolated global function 'mainActorResult' to global actor 'CustomActor'-isolated context}}
68+
// expected-note @-2 {{a function type must be marked '@Sendable' to conform to 'Sendable'}}
69+
// expected-warning @-3 {{no 'async' operations occur within 'await' expression}}
70+
71+
let calc = Calculator()
72+
73+
let _ = (await calc.addCurried(1))(2)
74+
// expected-error @-1 {{non-Sendable '(Int) -> Int'-typed result can not be returned from actor-isolated instance method 'addCurried' to global actor 'CustomActor'-isolated context}}
75+
// expected-note@-2{{a function type must be marked '@Sendable' to conform to 'Sendable'}}
76+
let _ = await (await calc.addCurried(1))(2) // expected-warning{{no 'async' operations occur within 'await' expression}}
77+
// expected-error @-1 {{non-Sendable '(Int) -> Int'-typed result can not be returned from actor-isolated instance method 'addCurried' to global actor 'CustomActor'-isolated context}}
78+
// expected-note @-2 {{a function type must be marked '@Sendable' to conform to 'Sendable'}}
79+
80+
let plusOne = await calc.addCurried(await calc.add(0, 1))
81+
// expected-error @-1 {{non-Sendable '(Int) -> Int'-typed result can not be returned from actor-isolated instance method 'addCurried' to global actor 'CustomActor'-isolated context}}
82+
// expected-note @-2 {{a function type must be marked '@Sendable' to conform to 'Sendable'}}
83+
let _ = plusOne(2)
84+
}
85+
86+
actor A {
87+
let actorNS = NonSendable()
88+
89+
func actorTakesNS(_ : NonSendable) async {}
90+
91+
func actorRetsNS() async -> NonSendable { NonSendable() }
92+
93+
func callNonisolatedFuncsFromActor(ns: NonSendable) async {
94+
// Non-sendable value passed from nonisolated to actor isolated
95+
96+
await passNonSendable(ns)
97+
// expected-error @-1 {{sending 'ns' risks causing data races}}
98+
// expected-note @-2 {{sending 'self'-isolated 'ns' to nonisolated global function 'passNonSendable' risks causing data races between nonisolated and 'self'-isolated uses}}
99+
100+
_ = await returnsNonSendable()
101+
}
102+
103+
func callActorFuncsFromDiffActor(ns : NonSendable, a : A) async {
104+
// Non-sendable value passed between the isolation of two different actors
105+
106+
await a.actorTakesNS(ns)
107+
// expected-error @-1 {{sending 'ns' risks causing data races}}
108+
// expected-note @-2 {{sending 'self'-isolated 'ns' to actor-isolated instance method 'actorTakesNS' risks causing data races between actor-isolated and 'self'-isolated uses}}
109+
110+
_ = await a.actorRetsNS()
111+
// expected-error @-1 {{non-Sendable 'NonSendable'-typed result can not be returned from actor-isolated instance method 'actorRetsNS()' to actor-isolated context}}
112+
}
113+
114+
func validateErrorForPassingIsolatedNonSendable(_ ns: NonSendable) async {
115+
await mainActorGenericPassNonSendable(ns)
116+
// expected-error @-1 {{sending 'ns' risks causing data races}}
117+
// expected-note @-2 {{sending 'self'-isolated 'ns' to main actor-isolated global function 'mainActorGenericPassNonSendable' risks causing data races between main actor-isolated and 'self'-isolated uses}}
118+
}
119+
120+
func validateErrorReturningFromNonIsolated() async {
121+
let _ = await returnsNonSendable()
122+
}
123+
}
124+
125+
func callActorFuncsFromNonisolated(a : A, ns : NonSendable) async {
126+
await a.actorTakesNS(ns)
127+
// expected-error @-1 {{sending 'ns' risks causing data races}}
128+
// expected-note @-2 {{sending task-isolated 'ns' to actor-isolated instance method 'actorTakesNS' risks causing data races between actor-isolated and task-isolated uses}}
129+
130+
_ = await a.actorRetsNS()
131+
// expected-error @-1 {{non-Sendable 'NonSendable'-typed result can not be returned from actor-isolated instance method 'actorRetsNS()' to nonisolated context}}
132+
}
133+
134+
func testGenericResults() async {
135+
let _: NonSendable = await mainActorGenericReturnNonSendable()
136+
// expected-error @-1 {{non-Sendable 'NonSendable'-typed result can not be returned from main actor-isolated global function 'mainActorGenericReturnNonSendable()' to nonisolated context}}
137+
}

test/Concurrency/transfernonsendable_sending_results.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ func asyncLetReabstractionThunkTest() async {
238238
func asyncLetReabstractionThunkTest2() async {
239239
// We emit the error here since we are returning a main actor isolated value.
240240
async let newValue: NonSendableKlass = await getMainActorValueAsync()
241-
// expected-warning @-1 {{non-sendable result type 'NonSendableKlass' cannot be sent from main actor-isolated context in call to global function 'getMainActorValueAsync()'}}
241+
// expected-warning @-1 {{non-Sendable 'NonSendableKlass'-typed result can not be returned from main actor-isolated global function 'getMainActorValueAsync()' to nonisolated context}}
242242

243243
let _ = await newValue
244244

@@ -261,7 +261,7 @@ func asyncLetReabstractionThunkTest2() async {
261261
@MainActor func asyncLetReabstractionThunkTestGlobalActor2() async {
262262
// We emit the error here since we are returning a main actor isolated value.
263263
async let newValue: NonSendableKlass = await getMainActorValueAsync()
264-
// expected-warning @-1 {{non-sendable result type 'NonSendableKlass' cannot be sent from main actor-isolated context in call to global function 'getMainActorValueAsync()'}}
264+
// expected-warning @-1 {{non-Sendable 'NonSendableKlass'-typed result can not be returned from main actor-isolated global function 'getMainActorValueAsync()' to nonisolated context}}
265265

266266
let _ = await newValue
267267

0 commit comments

Comments
 (0)