Skip to content

Commit 9ff33c5

Browse files
committed
Update tests for allocbox to stack error change.
I also extended the tests to handle more interesting cases. NOTE: There are a few cases where we introduced some new do not understand errors. I am going to fix that in the next commit. I just wanted to completely update the tests for the manner in which the allocbox to stack change affects them.
1 parent 7d86bf0 commit 9ff33c5

6 files changed

+1464
-166
lines changed

test/SILGen/moveonly_escaping_closure.swift

Lines changed: 46 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -126,14 +126,21 @@ func testGlobalClosureCaptureVar() {
126126
// CHECK: } // end sil function '$s16moveonly_closure29testLocalLetClosureCaptureVaryyFyycfU_'
127127
func testLocalLetClosureCaptureVar() {
128128
var x = SingleElt()
129+
// expected-error @-1 {{'x' consumed more than once}}
130+
// expected-error @-2 {{'x' used after consume}}
131+
// expected-error @-3 {{'x' used after consume}}
129132
x = SingleElt()
130133
let f = {
131134
borrowVal(x)
132-
consumeVal(x) // expected-error {{'x' was consumed but it is illegal to consume a noncopyable mutable capture of an escaping closure. One can only read from it or assign over it}}
133-
consumeVal(x) // expected-error {{'x' was consumed but it is illegal to consume a noncopyable mutable capture of an escaping closure. One can only read from it or assign over it}}
134-
borrowConsumeVal(x, x) // expected-error {{'x' was consumed but it is illegal to consume a noncopyable mutable capture of an escaping closure. One can only read from it or assign over it}}
135+
consumeVal(x) // expected-note {{consuming use here}}
136+
consumeVal(x) // expected-note {{consuming use here}}
137+
// expected-note @-1 {{consuming use here}}
138+
borrowConsumeVal(x, x)
135139
// expected-error @-1 {{overlapping accesses, but deinitialization requires exclusive access}}
136140
// expected-note @-2 {{conflicting access is here}}
141+
// expected-note @-3 {{non-consuming use here}}
142+
// expected-note @-4 {{non-consuming use here}}
143+
// expected-note @-5 {{consuming use here}}
137144
}
138145
f()
139146
}
@@ -409,11 +416,14 @@ func testGlobalClosureCaptureLet() {
409416
// CHECK: } // end sil function '$s16moveonly_closure026testLocalLetClosureCaptureE0yyFyycfU_'
410417
func testLocalLetClosureCaptureLet() {
411418
let x = SingleElt()
419+
// expected-error @-1 {{'x' consumed in closure. This is illegal since if the closure is invoked more than once the binding will be uninitialized on later invocations}}
420+
// expected-error @-2 {{'x' consumed in closure. This is illegal since if the closure is invoked more than once the binding will be uninitialized on later invocations}}
421+
// expected-error @-3 {{'x' consumed in closure. This is illegal since if the closure is invoked more than once the binding will be uninitialized on later invocations}}
412422
let f = {
413423
borrowVal(x)
414-
consumeVal(x) // expected-error {{'x' was consumed but it is illegal to consume a noncopyable immutable capture of an escaping closure. One can only read from it}}
415-
consumeVal(x) // expected-error {{'x' was consumed but it is illegal to consume a noncopyable immutable capture of an escaping closure. One can only read from it}}
416-
borrowConsumeVal(x, x) // expected-error {{'x' was consumed but it is illegal to consume a noncopyable immutable capture of an escaping closure. One can only read from it}}
424+
consumeVal(x) // expected-note {{consuming use here}}
425+
consumeVal(x) // expected-note {{consuming use here}}
426+
borrowConsumeVal(x, x) // expected-note {{consuming use here}}
417427
}
418428
f()
419429
}
@@ -608,6 +618,7 @@ func testConsumingEscapeClosureCaptureLet(_ f: consuming @escaping () -> ()) {
608618
var globalClosureCaptureInOut: () -> () = {}
609619
func testGlobalClosureCaptureInOut(_ x: inout SingleElt) {
610620
// expected-note @-1 {{'x' is declared 'inout'}}
621+
// expected-error @-2 {{Usage of a move only type that the move checker does not know how to check}}
611622
globalClosureCaptureInOut = { // expected-error {{escaping closure captures 'inout' parameter 'x'}}
612623
borrowVal(x) // expected-note {{captured here}}
613624
consumeVal(x) // expected-note {{captured here}}
@@ -697,6 +708,7 @@ func testLocalLetClosureCaptureInOut(_ x: inout SingleElt) {
697708
// CHECK: } // end sil function '$s16moveonly_closure31testLocalVarClosureCaptureInOutyyAA9SingleEltVzFyycfU_'
698709
func testLocalVarClosureCaptureInOut(_ x: inout SingleElt) {
699710
// expected-note @-1 {{'x' is declared 'inout'}}
711+
// expected-error @-2 {{Usage of a move only type that the move checker does not know how to check}}
700712
var f = { // expected-error {{escaping closure captures 'inout' parameter 'x'}}
701713
borrowVal(x) // expected-note {{captured here}}
702714
consumeVal(x) // expected-note {{captured here}}
@@ -745,6 +757,7 @@ func testLocalVarClosureCaptureInOut(_ x: inout SingleElt) {
745757
// CHECK: } // end sil function '$s16moveonly_closure026testInOutVarClosureCapturedE0yyyycz_AA9SingleEltVztFyycfU_'
746758
func testInOutVarClosureCaptureInOut(_ f: inout () -> (), _ x: inout SingleElt) {
747759
// expected-note @-1 {{'x' is declared 'inout'}}
760+
// expected-error @-2 {{Usage of a move only type that the move checker does not know how to check}}
748761
f = { // expected-error {{escaping closure captures 'inout' parameter 'x'}}
749762
borrowVal(x) // expected-note {{captured here}}
750763
consumeVal(x) // expected-note {{captured here}}
@@ -797,6 +810,7 @@ func testInOutVarClosureCaptureInOut(_ f: inout () -> (), _ x: inout SingleElt)
797810
// CHECK: } // end sil function '$s16moveonly_closure38testConsumingEscapeClosureCaptureInOutyyyycn_AA9SingleEltVztFyycfU_'
798811
func testConsumingEscapeClosureCaptureInOut(_ f: consuming @escaping () -> (), _ x: inout SingleElt) {
799812
// expected-note @-1 {{'x' is declared 'inout'}}
813+
// expected-error @-2 {{Usage of a move only type that the move checker does not know how to check}}
800814
f = { // expected-error {{escaping closure captures 'inout' parameter 'x'}}
801815
borrowVal(x) // expected-note {{captured here}}
802816
consumeVal(x) // expected-note {{captured here}}
@@ -920,6 +934,24 @@ func testGlobalClosureCaptureConsuming(_ x: consuming SingleElt) {
920934
// CHECK: end_access [[READ_ACCESS]]
921935
// CHECK: } // end sil function '$s16moveonly_closure35testLocalLetClosureCaptureConsumingyyAA9SingleEltVnFyycfU_'
922936
func testLocalLetClosureCaptureConsuming(_ x: consuming SingleElt) {
937+
// expected-error @-1 {{'x' consumed more than once}}
938+
// expected-error @-2 {{'x' used after consume}}
939+
// expected-error @-3 {{'x' used after consume}}
940+
let f = {
941+
borrowVal(x)
942+
consumeVal(x) // expected-note {{consuming use here}}
943+
consumeVal(x) // expected-note {{consuming use here}}
944+
// expected-note @-1 {{consuming use here}}
945+
borrowConsumeVal(x, x) // expected-note {{non-consuming use here}}
946+
// expected-error @-1 {{overlapping accesses, but deinitialization requires exclusive access}}
947+
// expected-note @-2 {{conflicting access is here}}
948+
// expected-note @-3 {{consuming use here}}
949+
// expected-note @-4 {{non-consuming use here}}
950+
}
951+
f()
952+
}
953+
954+
func testLocalLetClosureCaptureConsuming2(_ x: consuming SingleElt) -> (() -> ()) {
923955
let f = {
924956
borrowVal(x)
925957
consumeVal(x) // expected-error {{'x' was consumed but it is illegal to consume a noncopyable mutable capture of an escaping closure. One can only read from it or assign over it}}
@@ -929,8 +961,10 @@ func testLocalLetClosureCaptureConsuming(_ x: consuming SingleElt) {
929961
// expected-note @-2 {{conflicting access is here}}
930962
}
931963
f()
964+
return f
932965
}
933966

967+
934968
// CHECK-LABEL: sil hidden [ossa] @$s16moveonly_closure35testLocalVarClosureCaptureConsumingyyAA9SingleEltVnF : $@convention(thin) (@owned SingleElt) -> () {
935969
// CHECK: [[BOX:%.*]] = alloc_box
936970
// CHECK: [[PROJECT:%.*]] = project_box [[BOX]]
@@ -1136,11 +1170,14 @@ func testGlobalClosureCaptureOwned(_ x: __owned SingleElt) {
11361170
// CHECK: apply {{%.*}}([[LOADED_READ]], [[LOADED_TAKE]])
11371171
// CHECK: } // end sil function '$s16moveonly_closure31testLocalLetClosureCaptureOwnedyyAA9SingleEltVnFyycfU_'
11381172
func testLocalLetClosureCaptureOwned(_ x: __owned SingleElt) {
1173+
// expected-error @-1 {{'x' consumed in closure. This is illegal since if the closure is invoked more than once the binding will be uninitialized on later invocations}}
1174+
// expected-error @-2 {{'x' consumed in closure. This is illegal since if the closure is invoked more than once the binding will be uninitialized on later invocations}}
1175+
// expected-error @-3 {{'x' consumed in closure. This is illegal since if the closure is invoked more than once the binding will be uninitialized on later invocations}}
11391176
let f = {
11401177
borrowVal(x)
1141-
consumeVal(x) // expected-error {{'x' was consumed but it is illegal to consume a noncopyable immutable capture of an escaping closure. One can only read from it}}
1142-
consumeVal(x) // expected-error {{'x' was consumed but it is illegal to consume a noncopyable immutable capture of an escaping closure. One can only read from it}}
1143-
borrowConsumeVal(x, x) // expected-error {{'x' was consumed but it is illegal to consume a noncopyable immutable capture of an escaping closure. One can only read from it}}
1178+
consumeVal(x) // expected-note {{consuming use here}}
1179+
consumeVal(x) // expected-note {{consuming use here}}
1180+
borrowConsumeVal(x, x) // expected-note {{consuming use here}}
11441181
}
11451182
f()
11461183
}

0 commit comments

Comments
 (0)