Skip to content

Commit 5956cc3

Browse files
authored
Merge pull request swiftlang#67366 from drexin/wip-prespec-enum
[Test] Add tests for prespecialized enums with layout strings
2 parents 0c2e2d8 + 8a260ff commit 5956cc3

File tree

2 files changed

+272
-6
lines changed

2 files changed

+272
-6
lines changed

test/Interpreter/Inputs/layout_string_witnesses_types.swift

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,23 @@ public struct PrespecializedStruct<T> {
473473
}
474474
}
475475

476+
public enum PrespecializedSingletonEnum<T> {
477+
case only(Int, T)
478+
}
479+
480+
public enum PrespecializedSinglePayloadEnum<T> {
481+
case empty0
482+
case empty1
483+
case nonEmpty(Int, T)
484+
}
485+
486+
public enum PrespecializedMultiPayloadEnum<T> {
487+
case empty0
488+
case empty1
489+
case nonEmpty0(Int, T)
490+
case nonEmpty1(T, Int)
491+
}
492+
476493
@inline(never)
477494
public func consume<T>(_ x: T.Type) {
478495
withExtendedLifetime(x) {}
@@ -481,6 +498,18 @@ public func preSpec() {
481498
consume(PrespecializedStruct<AnyObject>.self)
482499
consume(PrespecializedStruct<SimpleClass>.self)
483500
consume(PrespecializedStruct<Int>.self)
501+
502+
consume(PrespecializedSingletonEnum<AnyObject>.self)
503+
consume(PrespecializedSingletonEnum<SimpleClass>.self)
504+
consume(PrespecializedSingletonEnum<Int>.self)
505+
506+
consume(PrespecializedSinglePayloadEnum<AnyObject>.self)
507+
consume(PrespecializedSinglePayloadEnum<SimpleClass>.self)
508+
consume(PrespecializedSinglePayloadEnum<Int>.self)
509+
510+
consume(PrespecializedMultiPayloadEnum<AnyObject>.self)
511+
consume(PrespecializedMultiPayloadEnum<SimpleClass>.self)
512+
consume(PrespecializedMultiPayloadEnum<Int>.self)
484513
}
485514

486515
@inline(never)

test/Interpreter/layout_string_witnesses_dynamic.swift

Lines changed: 243 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func testGeneric() {
5252

5353
testGeneric()
5454

55-
func testPrespecializedAnyObject() {
55+
func testPrespecializedStructAnyObject() {
5656
let ptr = UnsafeMutablePointer<PrespecializedStruct<AnyObject>>.allocate(capacity: 1)
5757

5858
do {
@@ -80,9 +80,9 @@ func testPrespecializedAnyObject() {
8080
ptr.deallocate()
8181
}
8282

83-
testPrespecializedAnyObject()
83+
testPrespecializedStructAnyObject()
8484

85-
func testPrespecializedSimpleClass() {
85+
func testPrespecializedStructSimpleClass() {
8686
let ptr = UnsafeMutablePointer<PrespecializedStruct<SimpleClass>>.allocate(capacity: 1)
8787

8888
do {
@@ -110,10 +110,10 @@ func testPrespecializedSimpleClass() {
110110
ptr.deallocate()
111111
}
112112

113-
testPrespecializedSimpleClass()
113+
testPrespecializedStructSimpleClass()
114114

115115

116-
func testPrespecializedInt() {
116+
func testPrespecializedStructInt() {
117117
let ptr = UnsafeMutablePointer<PrespecializedStruct<Int>>.allocate(capacity: 1)
118118

119119
do {
@@ -129,7 +129,244 @@ func testPrespecializedInt() {
129129
ptr.deallocate()
130130
}
131131

132-
testPrespecializedInt()
132+
testPrespecializedStructInt()
133+
134+
func testPrespecializedSingletonEnumAnyObject() {
135+
let ptr = UnsafeMutablePointer<PrespecializedSingletonEnum<AnyObject>>.allocate(capacity: 1)
136+
137+
do {
138+
let x = PrespecializedSingletonEnum<AnyObject>.only(23, SimpleClass(x: 23))
139+
testInit(ptr, to: x)
140+
}
141+
142+
do {
143+
let y = PrespecializedSingletonEnum<AnyObject>.only(32, SimpleClass(x: 32))
144+
145+
// CHECK-NEXT: Before deinit
146+
print("Before deinit")
147+
148+
// CHECK-NEXT: SimpleClass deinitialized!
149+
testAssign(ptr, from: y)
150+
}
151+
152+
// CHECK-NEXT: Before deinit
153+
print("Before deinit")
154+
155+
156+
// CHECK-NEXT: SimpleClass deinitialized!
157+
testDestroy(ptr)
158+
159+
ptr.deallocate()
160+
}
161+
162+
testPrespecializedSingletonEnumAnyObject()
163+
164+
func testPrespecializedSingletonEnumSimpleClass() {
165+
let ptr = UnsafeMutablePointer<PrespecializedSingletonEnum<SimpleClass>>.allocate(capacity: 1)
166+
167+
do {
168+
let x = PrespecializedSingletonEnum<SimpleClass>.only(23, SimpleClass(x: 23))
169+
testInit(ptr, to: x)
170+
}
171+
172+
do {
173+
let y = PrespecializedSingletonEnum<SimpleClass>.only(32, SimpleClass(x: 32))
174+
175+
// CHECK-NEXT: Before deinit
176+
print("Before deinit")
177+
178+
// CHECK-NEXT: SimpleClass deinitialized!
179+
testAssign(ptr, from: y)
180+
}
181+
182+
// CHECK-NEXT: Before deinit
183+
print("Before deinit")
184+
185+
186+
// CHECK-NEXT: SimpleClass deinitialized!
187+
testDestroy(ptr)
188+
189+
ptr.deallocate()
190+
}
191+
192+
testPrespecializedSingletonEnumSimpleClass()
193+
194+
195+
func testPrespecializedSingletonEnumInt() {
196+
let ptr = UnsafeMutablePointer<PrespecializedSingletonEnum<Int>>.allocate(capacity: 1)
197+
198+
do {
199+
let x = PrespecializedSingletonEnum<Int>.only(23, 23)
200+
testInit(ptr, to: x)
201+
}
202+
203+
do {
204+
let y = PrespecializedSingletonEnum<Int>.only(32, 32)
205+
testAssign(ptr, from: y)
206+
}
207+
208+
ptr.deallocate()
209+
}
210+
211+
testPrespecializedSingletonEnumInt()
212+
213+
func testPrespecializedSinglePayloadEnumAnyObject() {
214+
let ptr = UnsafeMutablePointer<PrespecializedSinglePayloadEnum<AnyObject>>.allocate(capacity: 1)
215+
216+
do {
217+
let x = PrespecializedSinglePayloadEnum<AnyObject>.nonEmpty(23, SimpleClass(x: 23))
218+
testInit(ptr, to: x)
219+
}
220+
221+
do {
222+
let y = PrespecializedSinglePayloadEnum<AnyObject>.nonEmpty(32, SimpleClass(x: 32))
223+
224+
// CHECK-NEXT: Before deinit
225+
print("Before deinit")
226+
227+
// CHECK-NEXT: SimpleClass deinitialized!
228+
testAssign(ptr, from: y)
229+
}
230+
231+
// CHECK-NEXT: Before deinit
232+
print("Before deinit")
233+
234+
235+
// CHECK-NEXT: SimpleClass deinitialized!
236+
testDestroy(ptr)
237+
238+
ptr.deallocate()
239+
}
240+
241+
testPrespecializedSinglePayloadEnumAnyObject()
242+
243+
func testPrespecializedSinglePayloadEnumSimpleClass() {
244+
let ptr = UnsafeMutablePointer<PrespecializedSinglePayloadEnum<SimpleClass>>.allocate(capacity: 1)
245+
246+
do {
247+
let x = PrespecializedSinglePayloadEnum<SimpleClass>.nonEmpty(23, SimpleClass(x: 23))
248+
testInit(ptr, to: x)
249+
}
250+
251+
do {
252+
let y = PrespecializedSinglePayloadEnum<SimpleClass>.nonEmpty(32, SimpleClass(x: 32))
253+
254+
// CHECK-NEXT: Before deinit
255+
print("Before deinit")
256+
257+
// CHECK-NEXT: SimpleClass deinitialized!
258+
testAssign(ptr, from: y)
259+
}
260+
261+
// CHECK-NEXT: Before deinit
262+
print("Before deinit")
263+
264+
265+
// CHECK-NEXT: SimpleClass deinitialized!
266+
testDestroy(ptr)
267+
268+
ptr.deallocate()
269+
}
270+
271+
testPrespecializedSinglePayloadEnumSimpleClass()
272+
273+
274+
func testPrespecializedSinglePayloadEnumInt() {
275+
let ptr = UnsafeMutablePointer<PrespecializedSinglePayloadEnum<Int>>.allocate(capacity: 1)
276+
277+
do {
278+
let x = PrespecializedSinglePayloadEnum<Int>.nonEmpty(23, 23)
279+
testInit(ptr, to: x)
280+
}
281+
282+
do {
283+
let y = PrespecializedSinglePayloadEnum<Int>.nonEmpty(32, 32)
284+
testAssign(ptr, from: y)
285+
}
286+
287+
ptr.deallocate()
288+
}
289+
290+
testPrespecializedSinglePayloadEnumInt()
291+
292+
func testPrespecializedMultiPayloadEnumAnyObject() {
293+
let ptr = UnsafeMutablePointer<PrespecializedMultiPayloadEnum<AnyObject>>.allocate(capacity: 1)
294+
295+
do {
296+
let x = PrespecializedMultiPayloadEnum<AnyObject>.nonEmpty0(23, SimpleClass(x: 23))
297+
testInit(ptr, to: x)
298+
}
299+
300+
do {
301+
let y = PrespecializedMultiPayloadEnum<AnyObject>.nonEmpty0(32, SimpleClass(x: 32))
302+
303+
// CHECK-NEXT: Before deinit
304+
print("Before deinit")
305+
306+
// CHECK-NEXT: SimpleClass deinitialized!
307+
testAssign(ptr, from: y)
308+
}
309+
310+
// CHECK-NEXT: Before deinit
311+
print("Before deinit")
312+
313+
314+
// CHECK-NEXT: SimpleClass deinitialized!
315+
testDestroy(ptr)
316+
317+
ptr.deallocate()
318+
}
319+
320+
testPrespecializedMultiPayloadEnumAnyObject()
321+
322+
func testPrespecializedMultiPayloadEnumSimpleClass() {
323+
let ptr = UnsafeMutablePointer<PrespecializedMultiPayloadEnum<SimpleClass>>.allocate(capacity: 1)
324+
325+
do {
326+
let x = PrespecializedMultiPayloadEnum<SimpleClass>.nonEmpty0(23, SimpleClass(x: 23))
327+
testInit(ptr, to: x)
328+
}
329+
330+
do {
331+
let y = PrespecializedMultiPayloadEnum<SimpleClass>.nonEmpty0(32, SimpleClass(x: 32))
332+
333+
// CHECK-NEXT: Before deinit
334+
print("Before deinit")
335+
336+
// CHECK-NEXT: SimpleClass deinitialized!
337+
testAssign(ptr, from: y)
338+
}
339+
340+
// CHECK-NEXT: Before deinit
341+
print("Before deinit")
342+
343+
344+
// CHECK-NEXT: SimpleClass deinitialized!
345+
testDestroy(ptr)
346+
347+
ptr.deallocate()
348+
}
349+
350+
testPrespecializedMultiPayloadEnumSimpleClass()
351+
352+
353+
func testPrespecializedMultiPayloadEnumInt() {
354+
let ptr = UnsafeMutablePointer<PrespecializedMultiPayloadEnum<Int>>.allocate(capacity: 1)
355+
356+
do {
357+
let x = PrespecializedMultiPayloadEnum<Int>.nonEmpty0(23, 23)
358+
testInit(ptr, to: x)
359+
}
360+
361+
do {
362+
let y = PrespecializedMultiPayloadEnum<Int>.nonEmpty0(32, 32)
363+
testAssign(ptr, from: y)
364+
}
365+
366+
ptr.deallocate()
367+
}
368+
369+
testPrespecializedMultiPayloadEnumInt()
133370

134371
func testGenericTuple() {
135372
let ptr = allocateInternalGenericPtr(of: GenericTupleWrapper<TestClass>.self)

0 commit comments

Comments
 (0)