Skip to content

Commit 4cd7a3b

Browse files
committed
[move-only] Add additional test coverage to nonescaping closure test.
Specifically: 1. I added consuming test cases alongside __owned test cases. 2. I inserted the actual error messages so that we can see if we are emitting the correct error messages. 3. I enabled the NONTRIVIAL and NONTRIVIAL/REABSTRACT variants of the tests. There are some differences in the address only version of the test that I am still looking into.
1 parent 444701c commit 4cd7a3b

File tree

1 file changed

+32
-11
lines changed

1 file changed

+32
-11
lines changed

test/SILOptimizer/moveonly_nonescaping_closures.swift

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
// RUN: %target-swift-frontend -emit-sil -verify %s
2+
// RUN: %target-swift-frontend -DNONTRIVIAL -emit-sil -verify %s
3+
// RUN: %target-swift-frontend -DNONTRIVIAL -DREABSTRACT -emit-sil -verify %s
24
// TODO: test with (-DNONTRIVIAL | -DADDRESS_ONLY) * (REABSTRACT)
35

46
protocol P {}
@@ -52,17 +54,33 @@ func b(x: __owned M) { // expected-error {{'x' used after consume}}
5254
// expected-note @-2:37 {{consuming use here}}
5355
}
5456

57+
func b2(x: consuming M) {
58+
clodger({ borrow(x) }, // expected-note {{conflicting access is here}}
59+
consume: x) // expected-error {{overlapping accesses to 'x', but deinitialization requires exclusive access}}
60+
}
61+
5562
func c(x: __owned M) {
5663
clodger({ borrow(x) })
5764
borrow(x)
5865
consume(x)
5966
}
6067

68+
func c2(x: consuming M) {
69+
clodger({ borrow(x) })
70+
borrow(x)
71+
consume(x)
72+
}
73+
6174
func d(x: __owned M) { // expected-error {{'x' consumed in closure. This is illegal since if the closure is invoked more than once the binding will be uninitialized on later invocations}}
6275
clodger({ consume(x) })
6376
// expected-note @-1 {{consuming use here}}
6477
}
6578

79+
func d2(x: consuming M) { // expected-error {{'x' consumed in closure but not reinitialized before end of closure}}
80+
clodger({ consume(x) })
81+
// expected-note @-1 {{consuming use here}}
82+
}
83+
6684
func e(x: inout M) {
6785
clodger({ mutate(&x) })
6886
mutate(&x)
@@ -76,16 +94,19 @@ func f(x: borrowing M) {
7694
}
7795

7896
func g(x: inout M) {
79-
clodger({ mutate(&x) }, borrow: x) // expected-error{{}} // expected-note{{}}
97+
clodger({ mutate(&x) }, // expected-error {{overlapping accesses to 'x', but modification requires exclusive access}}}
98+
borrow: x) // expected-note {{conflicting access is here}}
8099
}
81100

82101
func h(x: inout M) {
83-
clodger({ mutate(&x) }, consume: x) // expected-error{{}} // expected-note{{}}
102+
clodger({ mutate(&x) }, // expected-note {{conflicting access is here}}
103+
consume: x) // expected-error {{overlapping accesses to 'x', but deinitialization requires exclusive access}}}
84104
x = M()
85105
}
86106

87107
func i(x: inout M) {
88-
clodger({ mutate(&x) }, mutate: &x) // expected-error{{}} // expected-note{{}}
108+
clodger({ mutate(&x) }, // expected-note {{conflicting access is here}}
109+
mutate: &x) // expected-error {{overlapping accesses to 'x', but modification requires exclusive access}}}
89110
}
90111

91112
// Multiple closures are allowed to capture the same inout binding concurrently.
@@ -100,20 +121,20 @@ func k(x: borrowing M) {
100121
}
101122

102123

103-
func l(x: inout M) { // expected-error{{}}
104-
clodger({ consume(x) }) // expected-note{{}}
124+
func l(x: inout M) { // expected-error {{'x' consumed in closure but not reinitialized before end of closure}}
125+
clodger({ consume(x) }) // expected-note {{consuming use here}}
105126
}
106127

107-
func m(x: inout M) { // expected-error{{}}
108-
consume(x) // expected-note{{}}
128+
func m(x: inout M) { // expected-error {{'x' used after consume}}
129+
consume(x) // expected-note {{consuming use here}}
109130

110-
clodger({ borrow(x) }) // expected-note{{}}
131+
clodger({ borrow(x) }) // expected-note {{non-consuming use here}}
111132
}
112133

113-
func n(x: inout M) { // expected-error{{}}
114-
consume(x) // expected-note{{}}
134+
func n(x: inout M) { // expected-error {{'x' used after consume}}
135+
consume(x) // expected-note {{consuming use here}}
115136

116-
clodger({ // expected-note{{}}
137+
clodger({ // expected-note {{non-consuming use here}}
117138
mutate(&x)
118139
})
119140
}

0 commit comments

Comments
 (0)