Skip to content

Commit c853796

Browse files
committed
[Test] Add tests for prespecialized singleton enums with layout strings
1 parent e89de6e commit c853796

File tree

2 files changed

+93
-6
lines changed

2 files changed

+93
-6
lines changed

test/Interpreter/Inputs/layout_string_witnesses_types.swift

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

476+
public enum PrespecializedSingletonEnum<T> {
477+
case only(Int, T)
478+
}
479+
476480
@inline(never)
477481
public func consume<T>(_ x: T.Type) {
478482
withExtendedLifetime(x) {}
@@ -481,6 +485,10 @@ public func preSpec() {
481485
consume(PrespecializedStruct<AnyObject>.self)
482486
consume(PrespecializedStruct<SimpleClass>.self)
483487
consume(PrespecializedStruct<Int>.self)
488+
489+
consume(PrespecializedSingletonEnum<AnyObject>.self)
490+
consume(PrespecializedSingletonEnum<SimpleClass>.self)
491+
consume(PrespecializedSingletonEnum<Int>.self)
484492
}
485493

486494
@inline(never)

test/Interpreter/layout_string_witnesses_dynamic.swift

Lines changed: 85 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,86 @@ 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()
133212

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

0 commit comments

Comments
 (0)