Skip to content

Commit 0d8aac1

Browse files
committed
[Test] Verified called witness.
Previously, the test didn't actually verify that the called witness method was the witness method from the right method--all the methods had the same implementation and just forwarded the type along to be printed. Now an id specific to each method is printed as well.
1 parent befd0bc commit 0d8aac1

File tree

2 files changed

+53
-15
lines changed

2 files changed

+53
-15
lines changed

test/IRGen/run_variadic_generics.sil

Lines changed: 41 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// RUN: %empty-directory(%t)
2-
// RUN: %target-build-swift-dylib(%t/%target-library-name(PrintShims)) %S/../Inputs/print-shims.swift -module-name PrintShims -emit-module -emit-module-path %t/PrintShims.swiftmodule
2+
// RUN: %target-build-swift-dylib(%t/%target-library-name(PrintShims)) -parse-stdlib %S/../Inputs/print-shims-stdlib.swift -module-name PrintShims -emit-module -emit-module-path %t/PrintShims.swiftmodule
33
// RUN: %target-codesign %t/%target-library-name(PrintShims)
44
// RUN: %target-build-swift -enable-experimental-feature VariadicGenerics -g -parse-sil %s -emit-ir -I %t -L %t -lPrintShim | %FileCheck %s --check-prefix=CHECK-LL
55
// RUN: %target-build-swift -enable-experimental-feature VariadicGenerics -g -parse-sil %s -module-name main -o %t/main -I %t -L %t -lPrintShims %target-rpath(%t)
@@ -18,6 +18,7 @@ import Swift
1818
import PrintShims
1919

2020
sil public_external @printGenericType : $@convention(thin) <T> (@thick T.Type) -> ()
21+
sil public_external @printGenericTypeAndWord : $@convention(thin) <T> (@thick T.Type, Builtin.Word) -> ()
2122

2223
protocol P {
2324
static func static_member_fn()
@@ -47,8 +48,9 @@ struct G : P {
4748

4849
sil private @A_static_member_fn : $@convention(witness_method: P) (@thick A.Type) -> () {
4950
bb0(%0 : $@thick A.Type):
50-
%printGenericType = function_ref @printGenericType : $@convention(thin) <T> (@thick T.Type) -> ()
51-
apply %printGenericType<A>(%0) : $@convention(thin) <T> (@thick T.Type) -> ()
51+
%printGenericTypeAndWord = function_ref @printGenericTypeAndWord : $@convention(thin) <T> (@thick T.Type, Builtin.Word) -> ()
52+
%id = integer_literal $Builtin.Word, 0
53+
apply %printGenericTypeAndWord<A>(%0, %id) : $@convention(thin) <T> (@thick T.Type, Builtin.Word) -> ()
5254
%4 = tuple ()
5355
return %4 : $()
5456
}
@@ -57,8 +59,9 @@ sil_witness_table A : P module main {
5759
}
5860
sil private @B_static_member_fn : $@convention(witness_method: P) (@thick B.Type) -> () {
5961
bb0(%0 : $@thick B.Type):
60-
%printGenericType = function_ref @printGenericType : $@convention(thin) <T> (@thick T.Type) -> ()
61-
apply %printGenericType<B>(%0) : $@convention(thin) <T> (@thick T.Type) -> ()
62+
%printGenericTypeAndWord = function_ref @printGenericTypeAndWord : $@convention(thin) <T> (@thick T.Type, Builtin.Word) -> ()
63+
%id = integer_literal $Builtin.Word, 1
64+
apply %printGenericTypeAndWord<B>(%0, %id) : $@convention(thin) <T> (@thick T.Type, Builtin.Word) -> ()
6265
%4 = tuple ()
6366
return %4 : $()
6467
}
@@ -67,8 +70,9 @@ sil_witness_table B : P module main {
6770
}
6871
sil private @C_static_member_fn : $@convention(witness_method: P) (@thick C.Type) -> () {
6972
bb0(%0 : $@thick C.Type):
70-
%printGenericType = function_ref @printGenericType : $@convention(thin) <T> (@thick T.Type) -> ()
71-
apply %printGenericType<C>(%0) : $@convention(thin) <T> (@thick T.Type) -> ()
73+
%printGenericTypeAndWord = function_ref @printGenericTypeAndWord : $@convention(thin) <T> (@thick T.Type, Builtin.Word) -> ()
74+
%id = integer_literal $Builtin.Word, 2
75+
apply %printGenericTypeAndWord<C>(%0, %id) : $@convention(thin) <T> (@thick T.Type, Builtin.Word) -> ()
7276
%4 = tuple ()
7377
return %4 : $()
7478
}
@@ -77,8 +81,9 @@ sil_witness_table C : P module main {
7781
}
7882
sil private @D_static_member_fn : $@convention(witness_method: P) (@thick D.Type) -> () {
7983
bb0(%0 : $@thick D.Type):
80-
%printGenericType = function_ref @printGenericType : $@convention(thin) <T> (@thick T.Type) -> ()
81-
apply %printGenericType<D>(%0) : $@convention(thin) <T> (@thick T.Type) -> ()
84+
%printGenericTypeAndWord = function_ref @printGenericTypeAndWord : $@convention(thin) <T> (@thick T.Type, Builtin.Word) -> ()
85+
%id = integer_literal $Builtin.Word, 3
86+
apply %printGenericTypeAndWord<D>(%0, %id) : $@convention(thin) <T> (@thick T.Type, Builtin.Word) -> ()
8287
%4 = tuple ()
8388
return %4 : $()
8489
}
@@ -87,8 +92,9 @@ sil_witness_table D : P module main {
8792
}
8893
sil private @E_static_member_fn : $@convention(witness_method: P) (@thick E.Type) -> () {
8994
bb0(%0 : $@thick E.Type):
90-
%printGenericType = function_ref @printGenericType : $@convention(thin) <T> (@thick T.Type) -> ()
91-
apply %printGenericType<E>(%0) : $@convention(thin) <T> (@thick T.Type) -> ()
95+
%printGenericTypeAndWord = function_ref @printGenericTypeAndWord : $@convention(thin) <T> (@thick T.Type, Builtin.Word) -> ()
96+
%id = integer_literal $Builtin.Word, 4
97+
apply %printGenericTypeAndWord<E>(%0, %id) : $@convention(thin) <T> (@thick T.Type, Builtin.Word) -> ()
9298
%4 = tuple ()
9399
return %4 : $()
94100
}
@@ -97,8 +103,9 @@ sil_witness_table E : P module main {
97103
}
98104
sil private @F_static_member_fn : $@convention(witness_method: P) (@thick F.Type) -> () {
99105
bb0(%0 : $@thick F.Type):
100-
%printGenericType = function_ref @printGenericType : $@convention(thin) <T> (@thick T.Type) -> ()
101-
apply %printGenericType<F>(%0) : $@convention(thin) <T> (@thick T.Type) -> ()
106+
%printGenericTypeAndWord = function_ref @printGenericTypeAndWord : $@convention(thin) <T> (@thick T.Type, Builtin.Word) -> ()
107+
%id = integer_literal $Builtin.Word, 5
108+
apply %printGenericTypeAndWord<F>(%0, %id) : $@convention(thin) <T> (@thick T.Type, Builtin.Word) -> ()
102109
%4 = tuple ()
103110
return %4 : $()
104111
}
@@ -107,8 +114,9 @@ sil_witness_table F : P module main {
107114
}
108115
sil private @G_static_member_fn : $@convention(witness_method: P) (@thick G.Type) -> () {
109116
bb0(%0 : $@thick G.Type):
110-
%printGenericType = function_ref @printGenericType : $@convention(thin) <T> (@thick T.Type) -> ()
111-
apply %printGenericType<G>(%0) : $@convention(thin) <T> (@thick T.Type) -> ()
117+
%printGenericTypeAndWord = function_ref @printGenericTypeAndWord : $@convention(thin) <T> (@thick T.Type, Builtin.Word) -> ()
118+
%id = integer_literal $Builtin.Word, 6
119+
apply %printGenericTypeAndWord<G>(%0, %id) : $@convention(thin) <T> (@thick T.Type, Builtin.Word) -> ()
112120
%4 = tuple ()
113121
return %4 : $()
114122
}
@@ -205,55 +213,67 @@ bb0(%argc : $Int32, %argv : $UnsafeMutablePointer<Optional<UnsafeMutablePointer<
205213
// ---0--> ^
206214
// CHECK: A
207215
// CHECK: A
216+
// CHECK: 0
208217
// U_2 -> {D, E, F, A, B, C}
209218
// ---0--> ^
210219
// CHECK: D
211220
// CHECK: D
221+
// CHECK: 3
212222
apply %two_archetypes_from_two_params_no_singles_with_conformance<Pack{A, B, C}, Pack{D, E, F}>(%0) : $@convention(thin) <T_1... : P, T_2... : P where (repeat (each T_1, each T_2)): Any> (Builtin.Word) -> ()
213223
// U_1 -> {A, B, C, D, E, F}
214224
// ----1----> ^
215225
// CHECK: B
216226
// CHECK: B
227+
// CHECK: 1
217228
// U_2 -> {D, E, F, A, B, C}
218229
// ----1----> ^
219230
// CHECK: E
220231
// CHECK: E
232+
// CHECK: 4
221233
apply %two_archetypes_from_two_params_no_singles_with_conformance<Pack{A, B, C}, Pack{D, E, F}>(%1) : $@convention(thin) <T_1... : P, T_2... : P where (repeat (each T_1, each T_2)): Any> (Builtin.Word) -> ()
222234
// U_1 -> {A, B, C, D, E, F}
223235
// ------2-----> ^
224236
// CHECK: C
225237
// CHECK: C
238+
// CHECK: 2
226239
// U_2 -> {D, E, F, A, B, C}
227240
// ------2-----> ^
228241
// CHECK: F
229242
// CHECK: F
243+
// CHECK: 5
230244
apply %two_archetypes_from_two_params_no_singles_with_conformance<Pack{A, B, C}, Pack{D, E, F}>(%2) : $@convention(thin) <T_1... : P, T_2... : P where (repeat (each T_1, each T_2)): Any> (Builtin.Word) -> ()
231245
// U_1 -> {A, B, C, D, E, F}
232246
// -------3-------> ^
233247
// CHECK: D
234248
// CHECK: D
249+
// CHECK: 3
235250
// U_2 -> {D, E, F, A, B, C}
236251
// -------3-------> ^
237252
// CHECK: A
238253
// CHECK: A
254+
// CHECK: 0
239255
apply %two_archetypes_from_two_params_no_singles_with_conformance<Pack{A, B, C}, Pack{D, E, F}>(%3) : $@convention(thin) <T_1... : P, T_2... : P where (repeat (each T_1, each T_2)): Any> (Builtin.Word) -> ()
240256
// U_1 -> {A, B, C, D, E, F}
241257
// ---------4--------> ^
242258
// CHECK: E
243259
// CHECK: E
260+
// CHECK: 4
244261
// U_2 -> {D, E, F, A, B, C}
245262
// ---------4--------> ^
246263
// CHECK: B
247264
// CHECK: B
265+
// CHECK: 1
248266
apply %two_archetypes_from_two_params_no_singles_with_conformance<Pack{A, B, C}, Pack{D, E, F}>(%4) : $@convention(thin) <T_1... : P, T_2... : P where (repeat (each T_1, each T_2)): Any> (Builtin.Word) -> ()
249267
// U_1 -> {A, B, C, D, E, F}
250268
// -----------5---------> ^
251269
// CHECK: F
252270
// CHECK: F
271+
// CHECK: 5
253272
// U_2 -> {D, E, F, A, B, C}
254273
// -----------5---------> ^
255274
// CHECK: C
256275
// CHECK: C
276+
// CHECK: 2
257277
apply %two_archetypes_from_two_params_no_singles_with_conformance<Pack{A, B, C}, Pack{D, E, F}>(%5) : $@convention(thin) <T_1... : P, T_2... : P where (repeat (each T_1, each T_2)): Any> (Builtin.Word) -> ()
258278

259279

@@ -262,31 +282,37 @@ bb0(%argc : $Int32, %argv : $UnsafeMutablePointer<Optional<UnsafeMutablePointer<
262282
// --0---> ^
263283
// CHECK: A
264284
// CHECK: A
285+
// CHECK: 0
265286
apply %direct_access_from_parameter_with_conformance<Pack{A, B, C, D, E, F}>(%0) : $@convention(thin) <T_1... : P> (Builtin.Word) -> ()
266287
// U_1 -> {A, B, C, D, E, F}
267288
// ----1----> ^
268289
// CHECK: B
269290
// CHECK: B
291+
// CHECK: 1
270292
apply %direct_access_from_parameter_with_conformance<Pack{A, B, C, D, E, F}>(%1) : $@convention(thin) <T_1... : P> (Builtin.Word) -> ()
271293
// U_1 -> {A, B, C, D, E, F}
272294
// -----2------> ^
273295
// CHECK: C
274296
// CHECK: C
297+
// CHECK: 2
275298
apply %direct_access_from_parameter_with_conformance<Pack{A, B, C, D, E, F}>(%2) : $@convention(thin) <T_1... : P> (Builtin.Word) -> ()
276299
// U_1 -> {A, B, C, D, E, F}
277300
// -------3-------> ^
278301
// CHECK: D
279302
// CHECK: D
303+
// CHECK: 3
280304
apply %direct_access_from_parameter_with_conformance<Pack{A, B, C, D, E, F}>(%3) : $@convention(thin) <T_1... : P> (Builtin.Word) -> ()
281305
// U_1 -> {A, B, C, D, E, F}
282306
// --------4---------> ^
283307
// CHECK: E
284308
// CHECK: E
309+
// CHECK: 4
285310
apply %direct_access_from_parameter_with_conformance<Pack{A, B, C, D, E, F}>(%4) : $@convention(thin) <T_1... : P> (Builtin.Word) -> ()
286311
// U_1 -> {A, B, C, D, E, F}
287312
// ----------5----------> ^
288313
// CHECK: F
289314
// CHECK: F
315+
// CHECK: 5
290316
apply %direct_access_from_parameter_with_conformance<Pack{A, B, C, D, E, F}>(%5) : $@convention(thin) <T_1... : P> (Builtin.Word) -> ()
291317

292318
%outb = integer_literal $Builtin.Int32, 0

test/Inputs/print-shims-stdlib.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import Swift
2+
3+
@_silgen_name("printGenericType")
4+
public func printGenericType<T>(_ t: T.Type) {
5+
print(T.self)
6+
}
7+
8+
@_silgen_name("printGenericTypeAndWord")
9+
public func printGenericType<T>(_ t: T.Type, _ w: Builtin.Word) {
10+
print(T.self, Int(w))
11+
}
12+

0 commit comments

Comments
 (0)