Skip to content

Commit 8a260ff

Browse files
committed
[Test] Add tests for prespecialized single payload enums with layout strings
1 parent 649aa1a commit 8a260ff

File tree

2 files changed

+90
-0
lines changed

2 files changed

+90
-0
lines changed

test/Interpreter/Inputs/layout_string_witnesses_types.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,13 @@ public enum PrespecializedSinglePayloadEnum<T> {
483483
case nonEmpty(Int, T)
484484
}
485485

486+
public enum PrespecializedMultiPayloadEnum<T> {
487+
case empty0
488+
case empty1
489+
case nonEmpty0(Int, T)
490+
case nonEmpty1(T, Int)
491+
}
492+
486493
@inline(never)
487494
public func consume<T>(_ x: T.Type) {
488495
withExtendedLifetime(x) {}
@@ -499,6 +506,10 @@ public func preSpec() {
499506
consume(PrespecializedSinglePayloadEnum<AnyObject>.self)
500507
consume(PrespecializedSinglePayloadEnum<SimpleClass>.self)
501508
consume(PrespecializedSinglePayloadEnum<Int>.self)
509+
510+
consume(PrespecializedMultiPayloadEnum<AnyObject>.self)
511+
consume(PrespecializedMultiPayloadEnum<SimpleClass>.self)
512+
consume(PrespecializedMultiPayloadEnum<Int>.self)
502513
}
503514

504515
@inline(never)

test/Interpreter/layout_string_witnesses_dynamic.swift

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,85 @@ func testPrespecializedSinglePayloadEnumInt() {
289289

290290
testPrespecializedSinglePayloadEnumInt()
291291

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()
370+
292371
func testGenericTuple() {
293372
let ptr = allocateInternalGenericPtr(of: GenericTupleWrapper<TestClass>.self)
294373

0 commit comments

Comments
 (0)