Skip to content

Commit 649aa1a

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

File tree

2 files changed

+89
-0
lines changed

2 files changed

+89
-0
lines changed

test/Interpreter/Inputs/layout_string_witnesses_types.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,12 @@ public enum PrespecializedSingletonEnum<T> {
477477
case only(Int, T)
478478
}
479479

480+
public enum PrespecializedSinglePayloadEnum<T> {
481+
case empty0
482+
case empty1
483+
case nonEmpty(Int, T)
484+
}
485+
480486
@inline(never)
481487
public func consume<T>(_ x: T.Type) {
482488
withExtendedLifetime(x) {}
@@ -489,6 +495,10 @@ public func preSpec() {
489495
consume(PrespecializedSingletonEnum<AnyObject>.self)
490496
consume(PrespecializedSingletonEnum<SimpleClass>.self)
491497
consume(PrespecializedSingletonEnum<Int>.self)
498+
499+
consume(PrespecializedSinglePayloadEnum<AnyObject>.self)
500+
consume(PrespecializedSinglePayloadEnum<SimpleClass>.self)
501+
consume(PrespecializedSinglePayloadEnum<Int>.self)
492502
}
493503

494504
@inline(never)

test/Interpreter/layout_string_witnesses_dynamic.swift

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,85 @@ func testPrespecializedSingletonEnumInt() {
210210

211211
testPrespecializedSingletonEnumInt()
212212

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+
213292
func testGenericTuple() {
214293
let ptr = allocateInternalGenericPtr(of: GenericTupleWrapper<TestClass>.self)
215294

0 commit comments

Comments
 (0)