Skip to content

Commit 4f0680c

Browse files
committed
Unit test TypeLowering of ~Copyable & ~Escapable.
1 parent a90b515 commit 4f0680c

File tree

1 file changed

+203
-1
lines changed

1 file changed

+203
-1
lines changed

test/SIL/type_lowering_unit.sil

+203-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
// RUN: %target-sil-opt -test-runner %s -o /dev/null 2>&1 | %FileCheck %s
1+
// RUN: %target-sil-opt -test-runner \
2+
// RUN: -enable-experimental-feature NoncopyableGenerics -enable-experimental-feature NonescapableTypes \
3+
// RUN: -enable-experimental-feature BitwiseCopyable \
4+
// RUN: %s -o /dev/null 2>&1 | %FileCheck %s
25

36
sil_stage raw
47

@@ -7,6 +10,8 @@ import Swift
710

811
struct S : ~Copyable {}
912

13+
struct SCopyable {}
14+
1015
// CHECK-LABEL: begin {{.*}} print-type-lowering with: @argument[0]
1116
// CHECK: isLexical: true
1217
// CHECK-LABEL: end {{.*}} print-type-lowering with: @argument[0]
@@ -106,3 +111,200 @@ entry(%addr : $*Builtin.RawPointer):
106111
specify_test "print_ast_type_lowering %instance"
107112
return undef : $()
108113
}
114+
115+
struct GSNC<T: ~Copyable>: ~Copyable {
116+
var x: T
117+
}
118+
119+
extension GSNC: Copyable where T: Copyable {}
120+
121+
struct GSNE<T: ~Escapable>: ~Escapable {
122+
var x: T
123+
}
124+
125+
extension GSNE: Escapable where T: Escapable {}
126+
127+
enum GENC<T: ~Copyable>: ~Copyable {
128+
case x(T)
129+
case knoll
130+
}
131+
132+
enum GENE<T: ~Escapable>: ~Escapable {
133+
case x(T)
134+
case knoll
135+
}
136+
137+
extension GENC: Copyable where T: Copyable {}
138+
139+
extension GENE: Escapable where T: Escapable {}
140+
141+
// TODO: We should have 'isTrivial: true' for the following four tests: gsnc_argument, gsne_argument, genc_argument,
142+
// gene_argument. This requires fixing Typelowering visitAnyStructType and visitAnyEnumType to apply the current
143+
// abstraction pattern for each stored property that refers to an archetype. Similar how TypeLowering handles the
144+
// aggregate type by calling AbstractionPattern::conformsToKnownProtocol.
145+
//
146+
// CHECK-LABEL: begin running test 1 of 1 on gsnc_argument: print-type-lowering with: @argument[0]
147+
// CHECK: Type Lowering for lowered type: $*GSNC<T>.
148+
// CHECK: isTrivial: false.
149+
// CHECK-LABEL: end running test 1 of 1 on gsnc_argument: print-type-lowering with: @argument[0]
150+
sil [ossa] @gsnc_argument : $@convention(thin) <T: _BitwiseCopyable> (@in_guaranteed GSNC<T>) -> () {
151+
bb0(%0 : $*GSNC<T>):
152+
specify_test "print-type-lowering @argument[0]"
153+
%retval = tuple ()
154+
return %retval : $()
155+
}
156+
157+
// CHECK-LABEL: begin running test 1 of 1 on gsne_argument: print-type-lowering with: @argument[0]
158+
// CHECK: isTrivial: false.
159+
// CHECK-LABEL: end running test 1 of 1 on gsne_argument: print-type-lowering with: @argument[0]
160+
sil [ossa] @gsne_argument : $@convention(thin) <T: _BitwiseCopyable> (@in_guaranteed GSNE<T>) -> () {
161+
bb0(%0 : $*GSNE<T>):
162+
specify_test "print-type-lowering @argument[0]"
163+
%retval = tuple ()
164+
return %retval : $()
165+
}
166+
167+
// CHECK-LABEL: begin running test 1 of 1 on genc_argument: print-type-lowering with: @argument[0]
168+
// CHECK: isTrivial: false.
169+
// CHECK-LABEL: end running test 1 of 1 on genc_argument: print-type-lowering with: @argument[0]
170+
sil [ossa] @genc_argument : $@convention(thin) <T: _BitwiseCopyable> (@in_guaranteed GENC<T>) -> () {
171+
bb0(%0 : $*GENC<T>):
172+
specify_test "print-type-lowering @argument[0]"
173+
%retval = tuple ()
174+
return %retval : $()
175+
}
176+
177+
// CHECK-LABEL: begin running test 1 of 1 on gene_argument: print-type-lowering with: @argument[0]
178+
// CHECK: isTrivial: false.
179+
// CHECK-LABEL: end running test 1 of 1 on gene_argument: print-type-lowering with: @argument[0]
180+
sil [ossa] @gene_argument : $@convention(thin) <T: _BitwiseCopyable> (@in_guaranteed GENE<T>) -> () {
181+
bb0(%0 : $*GENE<T>):
182+
specify_test "print-type-lowering @argument[0]"
183+
%retval = tuple ()
184+
return %retval : $()
185+
}
186+
187+
struct Bitwise<T: _BitwiseCopyable>: _BitwiseCopyable {
188+
var x: T
189+
}
190+
191+
// TODO: This should return 'isTrivial: true'. This is particularly inexcusable because the 'Bitwise' cannot be
192+
// nontrivial over any 'T', *and* the declaration itself is declared BitwiseCopyable.
193+
//
194+
// CHECK-LABEL: begin running test 1 of 1 on bitwise_argument: print-type-lowering with: @argument[0]
195+
// CHECK: isTrivial: false.
196+
// CHECK-LABEL: end running test 1 of 1 on bitwise_argument: print-type-lowering with: @argument[0]
197+
sil [ossa] @bitwise_argument : $@convention(thin) <T: _BitwiseCopyable> (@in_guaranteed Bitwise<T>) -> () {
198+
bb0(%0 : $*Bitwise<T>):
199+
specify_test "print-type-lowering @argument[0]"
200+
%retval = tuple ()
201+
return %retval : $()
202+
}
203+
204+
// CHECK-LABEL: begin running test 1 of 1 on gsnc_specialized_argument: print-type-lowering with: @argument[0]
205+
// CHECK: isTrivial: true.
206+
// CHECK-LABEL: end running test 1 of 1 on gsnc_specialized_argument: print-type-lowering with: @argument[0]
207+
sil [ossa] @gsnc_specialized_argument : $@convention(thin) (@in_guaranteed GSNC<SCopyable>) -> () {
208+
bb0(%0 : $*GSNC<SCopyable>):
209+
specify_test "print-type-lowering @argument[0]"
210+
%retval = tuple ()
211+
return %retval : $()
212+
}
213+
214+
// CHECK-LABEL: begin running test 1 of 1 on gsne_specialized_argument: print-type-lowering with: @argument[0]
215+
// CHECK: isTrivial: true.
216+
// CHECK-LABEL: end running test 1 of 1 on gsne_specialized_argument: print-type-lowering with: @argument[0]
217+
sil [ossa] @gsne_specialized_argument : $@convention(thin) (@in_guaranteed GSNE<SCopyable>) -> () {
218+
bb0(%0 : $*GSNE<SCopyable>):
219+
specify_test "print-type-lowering @argument[0]"
220+
%retval = tuple ()
221+
return %retval : $()
222+
}
223+
224+
// CHECK-LABEL: begin running test 1 of 1 on genc_specialized_argument: print-type-lowering with: @argument[0]
225+
// CHECK: isTrivial: true.
226+
// CHECK-LABEL: end running test 1 of 1 on genc_specialized_argument: print-type-lowering with: @argument[0]
227+
sil [ossa] @genc_specialized_argument : $@convention(thin) (@in_guaranteed GENC<SCopyable>) -> () {
228+
bb0(%0 : $*GENC<SCopyable>):
229+
specify_test "print-type-lowering @argument[0]"
230+
%retval = tuple ()
231+
return %retval : $()
232+
}
233+
234+
// CHECK-LABEL: begin running test 1 of 1 on gene_specialized_argument: print-type-lowering with: @argument[0]
235+
// CHECK: isTrivial: true.
236+
// CHECK-LABEL: end running test 1 of 1 on gene_specialized_argument: print-type-lowering with: @argument[0]
237+
sil [ossa] @gene_specialized_argument : $@convention(thin) (@in_guaranteed GENE<SCopyable>) -> () {
238+
bb0(%0 : $*GENE<SCopyable>):
239+
specify_test "print-type-lowering @argument[0]"
240+
%retval = tuple ()
241+
return %retval : $()
242+
}
243+
244+
struct GSNCInt<T: ~Copyable>: ~Copyable {
245+
var x: Int
246+
}
247+
248+
extension GSNCInt: Copyable where T: Copyable {}
249+
250+
struct GSNEInt<T: ~Escapable>: ~Escapable {
251+
var x: Int
252+
@_unsafeNonescapableResult
253+
init() { x = 0 }
254+
}
255+
256+
extension GSNEInt: Escapable where T: Escapable {}
257+
258+
enum GENCInt<T: ~Copyable>: ~Copyable {
259+
case x(Int)
260+
case knoll
261+
}
262+
263+
enum GENEInt<T: ~Escapable>: ~Escapable {
264+
case x(Int)
265+
case knoll
266+
}
267+
268+
extension GENCInt: Copyable where T: Copyable {}
269+
270+
extension GENEInt: Escapable where T: Escapable {}
271+
272+
// CHECK-LABEL: begin running test 1 of 1 on gsncint_argument: print-type-lowering with: @argument[0]
273+
// CHECK: isTrivial: true.
274+
// CHECK-LABEL: end running test 1 of 1 on gsncint_argument: print-type-lowering with: @argument[0]
275+
sil [ossa] @gsncint_argument : $@convention(thin) <T: _BitwiseCopyable> (@in_guaranteed GSNCInt<T>) -> () {
276+
bb0(%0 : $*GSNCInt<T>):
277+
specify_test "print-type-lowering @argument[0]"
278+
%retval = tuple ()
279+
return %retval : $()
280+
}
281+
282+
// CHECK-LABEL: begin running test 1 of 1 on gsneint_argument: print-type-lowering with: @argument[0]
283+
// CHECK: isTrivial: true.
284+
// CHECK-LABEL: end running test 1 of 1 on gsneint_argument: print-type-lowering with: @argument[0]
285+
sil [ossa] @gsneint_argument : $@convention(thin) <T: _BitwiseCopyable> (@in_guaranteed GSNEInt<T>) -> () {
286+
bb0(%0 : $*GSNEInt<T>):
287+
specify_test "print-type-lowering @argument[0]"
288+
%retval = tuple ()
289+
return %retval : $()
290+
}
291+
292+
// CHECK-LABEL: begin running test 1 of 1 on gencint_argument: print-type-lowering with: @argument[0]
293+
// CHECK: isTrivial: true.
294+
// CHECK-LABEL: end running test 1 of 1 on gencint_argument: print-type-lowering with: @argument[0]
295+
sil [ossa] @gencint_argument : $@convention(thin) <T: _BitwiseCopyable> (@in_guaranteed GENCInt<T>) -> () {
296+
bb0(%0 : $*GENCInt<T>):
297+
specify_test "print-type-lowering @argument[0]"
298+
%retval = tuple ()
299+
return %retval : $()
300+
}
301+
302+
// CHECK-LABEL: begin running test 1 of 1 on geneint_argument: print-type-lowering with: @argument[0]
303+
// CHECK: isTrivial: true.
304+
// CHECK-LABEL: end running test 1 of 1 on geneint_argument: print-type-lowering with: @argument[0]
305+
sil [ossa] @geneint_argument : $@convention(thin) <T: _BitwiseCopyable> (@in_guaranteed GENEInt<T>) -> () {
306+
bb0(%0 : $*GENEInt<T>):
307+
specify_test "print-type-lowering @argument[0]"
308+
%retval = tuple ()
309+
return %retval : $()
310+
}

0 commit comments

Comments
 (0)