Skip to content

Commit 46e5519

Browse files
committed
Add a test case for the work in this PR.
My original test case here used a memberwise initializer, but those use their own logic for binding and forward parameters which will need to be updated separately.
1 parent 16b1034 commit 46e5519

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

test/SILGen/variadic-generic-tuples.swift

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,3 +204,52 @@ func projectTupleElements<each T>(_ value: repeat Wrapper<each T>) {
204204

205205
let tuple = (repeat (each value).value)
206206
}
207+
208+
func takesVariadicTuple<each T>(tuple: (repeat each T)) {}
209+
210+
// CHECK-LABEL: sil{{.*}} @$s4main28testConcreteVariadicTupleArg1i1sySi_SStF :
211+
// CHECK: [[PACK:%.*]] = alloc_pack $Pack{Int, String}
212+
// CHECK-NEXT: [[I_COPY:%.*]] = alloc_stack $Int
213+
// CHECK-NEXT: store %0 to [trivial] [[I_COPY]] : $*Int
214+
// CHECK-NEXT: [[I_INDEX:%.*]] = scalar_pack_index 0 of $Pack{Int, String}
215+
// CHECK-NEXT: pack_element_set [[I_COPY]] : $*Int into [[I_INDEX]] of [[PACK]] :
216+
// CHECK-NEXT: [[S_COPY:%.*]] = alloc_stack $String
217+
// CHECK-NEXT: [[T0:%.*]] = copy_value %1 : $String
218+
// CHECK-NEXT: store [[T0]] to [init] [[S_COPY]] : $*String
219+
// CHECK-NEXT: [[S_INDEX:%.*]] = scalar_pack_index 1 of $Pack{Int, String}
220+
// CHECK-NEXT: pack_element_set [[S_COPY]] : $*String into [[S_INDEX]] of [[PACK]] :
221+
// CHECK-NEXT: // function_ref
222+
// CHECK-NEXT: [[FN:%.*]] = function_ref @$s4main18takesVariadicTuple5tupleyxxQp_t_tRvzlF : $@convention(thin) <each τ_0_0> (@pack_guaranteed Pack{repeat each τ_0_0}) -> ()
223+
// CHECK-NEXT: apply [[FN]]<Pack{Int, String}>([[PACK]])
224+
// CHECK-NEXT: destroy_addr [[S_COPY]] :
225+
// CHECK-NEXT: dealloc_stack [[S_COPY]] :
226+
// CHECK-NEXT: dealloc_stack [[I_COPY]] :
227+
// CHECK-NEXT: dealloc_pack [[PACK]] :
228+
func testConcreteVariadicTupleArg(i: Int, s: String) {
229+
takesVariadicTuple(tuple: (i, s))
230+
}
231+
232+
struct TupleHolder<each T> {
233+
var content: (repeat each T)
234+
235+
// Suppress the memberwise initializer
236+
init(values: repeat each T) {
237+
content = (repeat each values)
238+
}
239+
}
240+
241+
// CHECK-LABEL: sil{{.*}} @$s4main31takesConcreteTupleHolderFactory7factoryyAA0dE0VySi_SSQPGyXE_tF :
242+
// CHECK-SAME: $@convention(thin) (@guaranteed @noescape @callee_guaranteed () -> @owned TupleHolder<Int, String>) -> ()
243+
// CHECK: [[T0:%.*]] = copy_value %0 :
244+
// CHECK: [[T1:%.*]] = begin_borrow [[T0]]
245+
// CHECK: [[RESULT:%.*]] = apply [[T1]]() :
246+
// CHECK: destroy_value [[RESULT]]
247+
func takesConcreteTupleHolderFactory(factory: () -> TupleHolder<Int, String>) {
248+
let holder = factory()
249+
}
250+
251+
/* We still crash with memberwise initializers
252+
func generateConcreteMemberTuple() -> TupleHolder<Int, String> {
253+
return HasMemberTuple(content: (0, "hello"))
254+
}
255+
*/

0 commit comments

Comments
 (0)