Skip to content

Commit 92a63b9

Browse files
authored
Merge pull request #41641 from AnthonyLatsis/se-309-vararg
[SE-309] Add tests for covariant variadic parameters
2 parents 8c9b429 + 8df964e commit 92a63b9

File tree

2 files changed

+124
-0
lines changed

2 files changed

+124
-0
lines changed

test/SILGen/existential_member_accesses_self_assoctype.swift

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ protocol P {
1010
func covariantSelfMethod5() -> Array<Self>
1111
func covariantSelfMethod6() -> [String : Self]
1212
func covariantSelfMethod7(_: (Self) -> Void)
13+
func covariantSelfMethod8(_: (Self...) -> Void)
1314

1415
func covariantAssocMethod1() -> A
1516
func covariantAssocMethod2() -> A?
@@ -18,6 +19,7 @@ protocol P {
1819
func covariantAssocMethod5() -> Array<A>
1920
func covariantAssocMethod6() -> [String : A]
2021
func covariantAssocMethod7(_: (A) -> Void)
22+
func covariantAssocMethod8(_: (A...) -> Void)
2123

2224
var covariantSelfProperty1: Self { get }
2325
var covariantSelfProperty2: Self? { get }
@@ -26,6 +28,7 @@ protocol P {
2628
var covariantSelfProperty5: Array<Self> { get }
2729
var covariantSelfProperty6: [String : Self] { get }
2830
var covariantSelfProperty7: ((Self) -> Void) -> Void { get }
31+
var covariantSelfProperty8: ((Self...) -> Void) -> Void { get }
2932

3033
var covariantAssocProperty1: A { get }
3134
var covariantAssocProperty2: A? { get }
@@ -34,6 +37,7 @@ protocol P {
3437
var covariantAssocProperty5: Array<A> { get }
3538
var covariantAssocProperty6: [String : A] { get }
3639
var covariantAssocProperty7: ((A) -> Void) -> Void { get }
40+
var covariantAssocProperty8: ((A...) -> Void) -> Void { get }
3741

3842
subscript(covariantSelfSubscript1 _: Void) -> Self { get }
3943
subscript(covariantSelfSubscript2 _: Void) -> Self? { get }
@@ -42,6 +46,7 @@ protocol P {
4246
subscript(covariantSelfSubscript5 _: Void) -> Array<Self> { get }
4347
subscript(covariantSelfSubscript6 _: Void) -> [String : Self] { get }
4448
subscript(covariantSelfSubscript7 _: (Self) -> Void) -> Void { get }
49+
subscript(covariantSelfSubscript8 _: (Self...) -> Void) -> Void { get }
4550

4651
subscript(covariantAssocSubscript1 _: Void) -> A { get }
4752
subscript(covariantAssocSubscript2 _: Void) -> A? { get }
@@ -50,6 +55,7 @@ protocol P {
5055
subscript(covariantAssocSubscript5 _: Void) -> Array<A> { get }
5156
subscript(covariantAssocSubscript6 _: Void) -> [String : A] { get }
5257
subscript(covariantAssocSubscript7 _: (A) -> Void) -> Void { get }
58+
subscript(covariantAssocSubscript8 _: (A...) -> Void) -> Void { get }
5359
}
5460

5561
// -----------------------------------------------------------------------------
@@ -124,6 +130,22 @@ func testCovariantSelfMethod6(p: any P) {
124130
func testCovariantSelfMethod7(p: any P) {
125131
p.covariantSelfMethod7 { _ in }
126132
}
133+
// CHECK-LABEL: sil hidden [ossa] @$s42existential_member_accesses_self_assoctype24testCovariantSelfMethod81pyAA1P_p_tF
134+
// CHECK: [[OPENED:%[0-9]+]] = open_existential_addr immutable_access %0 : $*P to $*[[OPENED_TY:@opened\("[0-9A-F-]+"\) P]]
135+
// CHECK: [[THUNK:%[0-9]+]] = function_ref @[[SELF_ARRAY_THUNK_NAME:\$[0-9a-zA-Z_]+]] : $@convention(thin) <τ_0_0 where τ_0_0 : P> (@guaranteed Array<τ_0_0>, @noescape @callee_guaranteed (@guaranteed Array<P>) -> ()) -> ()
136+
// CHECK: [[STEP1:%[0-9]+]] = partial_apply [callee_guaranteed] [[THUNK]]<[[OPENED_TY]]>
137+
// CHECK: [[STEP2:%[0-9]+]] = convert_function [[STEP1]] : $@callee_guaranteed (@guaranteed Array<[[OPENED_TY]]>) -> () to $@callee_guaranteed @substituted <τ_0_0, τ_0_1 where τ_0_0 == τ_0_1> (@guaranteed Array<τ_0_0>) -> () for <[[OPENED_TY]], [[OPENED_TY]]>
138+
// CHECK: [[STEP3:%[0-9]+]] = convert_escape_to_noescape [not_guaranteed] [[STEP2]]
139+
// CHECK: [[WITNESS:%[0-9]+]] = witness_method $[[OPENED_TY]], #P.covariantSelfMethod8 : <Self where Self : P> (Self) -> ((Self...) -> ()) -> ()
140+
// CHECK: apply [[WITNESS]]<[[OPENED_TY]]>([[STEP3]], [[OPENED]]) : $@convention(witness_method: P) <τ_0_0 where τ_0_0 : P> (@noescape @callee_guaranteed @substituted <τ_0_0, τ_0_1 where τ_0_0 == τ_0_1> (@guaranteed Array<τ_0_0>) -> () for <τ_0_0, τ_0_0>, @in_guaranteed τ_0_0) -> ()
141+
142+
// CHECK: sil shared [transparent] [serializable] [reabstraction_thunk] [ossa] @[[SELF_ARRAY_THUNK_NAME]]
143+
// CHECK: [[ARRAY_UPCAST:%[0-9]+]] = function_ref @$ss15_arrayForceCastySayq_GSayxGr0_lF
144+
// CHECK: apply [[ARRAY_UPCAST]]<τ_0_0, P>
145+
// CHECK: } // end sil function '[[SELF_ARRAY_THUNK_NAME]]'
146+
func testCovariantSelfMethod8(p: any P) {
147+
p.covariantSelfMethod8 { _ in }
148+
}
127149

128150
// CHECK-LABEL: sil hidden [ossa] @$s42existential_member_accesses_self_assoctype26testCovariantSelfProperty11pyAA1P_p_tF
129151
// CHECK: [[LET:%[0-9]+]] = alloc_stack [lexical] $P, let, name "x"
@@ -208,6 +230,24 @@ func testCovariantSelfProperty6(p: any P) {
208230
func testCovariantSelfProperty7(p: any P) {
209231
let x = p.covariantSelfProperty7
210232
}
233+
// CHECK-LABEL: sil hidden [ossa] @$s42existential_member_accesses_self_assoctype26testCovariantSelfProperty81pyAA1P_p_tF
234+
// CHECK: [[OPENED:%[0-9]+]] = open_existential_addr immutable_access %0 : $*P to $*[[OPENED_TY:@opened\("[0-9A-F-]+"\) P]]
235+
// CHECK: [[OPENED_COPY:%[0-9]+]] = alloc_stack $[[OPENED_TY]]
236+
// CHECK: copy_addr [[OPENED]] to [initialization] [[OPENED_COPY]] : $*[[OPENED_TY]]
237+
// CHECK: [[WITNESS:%[0-9]+]] = witness_method $[[OPENED_TY]], #P.covariantSelfProperty8!getter : <Self where Self : P> (Self) -> () -> ((Self...) -> ()) -> ()
238+
// CHECK: [[RESULT_FN:%[0-9]+]] = apply [[WITNESS]]<[[OPENED_TY]]>([[OPENED_COPY]]) : $@convention(witness_method: P) <τ_0_0 where τ_0_0 : P> (@in_guaranteed τ_0_0) -> @owned @callee_guaranteed @substituted <τ_0_0, τ_0_1 where τ_0_0 == τ_0_1> (@noescape @callee_guaranteed @substituted <τ_0_0, τ_0_1 where τ_0_0 == τ_0_1> (@guaranteed Array<τ_0_0>) -> () for <τ_0_0, τ_0_0>) -> () for <τ_0_0, τ_0_0>
239+
// CHECK: [[STEP1:%[0-9]+]] = convert_function [[RESULT_FN]] : $@callee_guaranteed @substituted <τ_0_0, τ_0_1 where τ_0_0 == τ_0_1> (@noescape @callee_guaranteed @substituted <τ_0_0, τ_0_1 where τ_0_0 == τ_0_1> (@guaranteed Array<τ_0_0>) -> () for <τ_0_0, τ_0_0>) -> () for <[[OPENED_TY]], [[OPENED_TY]]> to $@callee_guaranteed (@noescape @callee_guaranteed @substituted <τ_0_0, τ_0_1 where τ_0_0 == τ_0_1> (@guaranteed Array<τ_0_0>) -> () for <[[OPENED_TY]], [[OPENED_TY]]>) -> ()
240+
// CHECK: [[THUNK:%[0-9]+]] = function_ref @[[THUNK_NAME:\$[0-9a-zA-Z_]+]] : $@convention(thin) <τ_0_0 where τ_0_0 : P> (@noescape @callee_guaranteed (@guaranteed Array<P>) -> (), @guaranteed @callee_guaranteed (@noescape @callee_guaranteed @substituted <τ_0_0, τ_0_1 where τ_0_0 == τ_0_1> (@guaranteed Array<τ_0_0>) -> () for <τ_0_0, τ_0_0>) -> ()) -> ()
241+
// CHECK: partial_apply [callee_guaranteed] [[THUNK]]<[[OPENED_TY]]>([[STEP1]])
242+
// CHECK: debug_value %{{[0-9]+}} : $@callee_guaranteed (@noescape @callee_guaranteed (@guaranteed Array<P>) -> ()) -> (), let, name "x"
243+
// CHECK: } // end sil function '$s42existential_member_accesses_self_assoctype26testCovariantSelfProperty81pyAA1P_p_tF'
244+
245+
// CHECK: sil shared [transparent] [serializable] [reabstraction_thunk] [ossa] @[[THUNK_NAME]]
246+
// CHECK: function_ref @[[SELF_ARRAY_THUNK_NAME]]
247+
// CHECK: } // end sil function '[[THUNK_NAME]]'
248+
func testCovariantSelfProperty8(p: any P) {
249+
let x = p.covariantSelfProperty8
250+
}
211251

212252
// CHECK-LABEL: sil hidden [ossa] @$s42existential_member_accesses_self_assoctype27testCovariantSelfSubscript11pyAA1P_p_tF
213253
// CHECK: [[LET:%[0-9]+]] = alloc_stack [lexical] $P, let, name "x"
@@ -291,6 +331,19 @@ func testCovariantSelfSubscript6(p: any P) {
291331
func testCovariantSelfSubscript7(p: any P) {
292332
_ = p[covariantSelfSubscript7: { _ in }]
293333
}
334+
// CHECK-LABEL: sil hidden [ossa] @$s42existential_member_accesses_self_assoctype27testCovariantSelfSubscript81pyAA1P_p_tF
335+
// CHECK: [[OPENED:%[0-9]+]] = open_existential_addr immutable_access %0 : $*P to $*[[OPENED_TY:@opened\("[0-9A-F-]+"\) P]]
336+
// CHECK: [[THUNK:%[0-9]+]] = function_ref @[[SELF_ARRAY_THUNK_NAME]] : $@convention(thin) <τ_0_0 where τ_0_0 : P> (@guaranteed Array<τ_0_0>, @noescape @callee_guaranteed (@guaranteed Array<P>) -> ()) -> ()
337+
// CHECK: [[STEP1:%[0-9]+]] = partial_apply [callee_guaranteed] [[THUNK]]<[[OPENED_TY]]>
338+
// CHECK: [[STEP2:%[0-9]+]] = convert_function [[STEP1]] : $@callee_guaranteed (@guaranteed Array<[[OPENED_TY]]>) -> () to $@callee_guaranteed @substituted <τ_0_0, τ_0_1 where τ_0_0 == τ_0_1> (@guaranteed Array<τ_0_0>) -> () for <[[OPENED_TY]], [[OPENED_TY]]>
339+
// CHECK: [[STEP3:%[0-9]+]] = convert_escape_to_noescape [not_guaranteed] [[STEP2]]
340+
// CHECK: [[OPENED_COPY:%[0-9]+]] = alloc_stack $[[OPENED_TY]]
341+
// CHECK: copy_addr [[OPENED]] to [initialization] [[OPENED_COPY]] : $*[[OPENED_TY]]
342+
// CHECK: [[WITNESS:%[0-9]+]] = witness_method $[[OPENED_TY]], #P.subscript!getter : <Self where Self : P> (Self) -> ((Self...) -> ()) -> ()
343+
// CHECK: apply [[WITNESS]]<[[OPENED_TY]]>([[STEP3]], [[OPENED_COPY]]) : $@convention(witness_method: P) <τ_0_0 where τ_0_0 : P> (@noescape @callee_guaranteed @substituted <τ_0_0, τ_0_1 where τ_0_0 == τ_0_1> (@guaranteed Array<τ_0_0>) -> () for <τ_0_0, τ_0_0>, @in_guaranteed τ_0_0) -> ()
344+
func testCovariantSelfSubscript8(p: any P) {
345+
_ = p[covariantSelfSubscript8: { _ in }]
346+
}
294347

295348
// CHECK-LABEL: sil hidden [ossa] @$s42existential_member_accesses_self_assoctype25testCovariantAssocMethod11pyAA1P_p_tF
296349
// CHECK: [[LET:%[0-9]+]] = alloc_stack [lexical] $Any, let, name "x"
@@ -361,6 +414,22 @@ func testCovariantAssocMethod6(p: any P) {
361414
func testCovariantAssocMethod7(p: any P) {
362415
p.covariantAssocMethod7 { _ in }
363416
}
417+
// CHECK-LABEL: sil hidden [ossa] @$s42existential_member_accesses_self_assoctype25testCovariantAssocMethod81pyAA1P_p_tF
418+
// CHECK: [[OPENED:%[0-9]+]] = open_existential_addr immutable_access %0 : $*P to $*[[OPENED_TY:@opened\("[0-9A-F-]+"\) P]]
419+
// CHECK: [[THUNK:%[0-9]+]] = function_ref @[[ASSOCTYPE_ARRAY_THUNK_NAME:\$[0-9a-zA-Z_]+]] : $@convention(thin) <τ_0_0 where τ_0_0 : P> (@guaranteed Array<τ_0_0.A>, @noescape @callee_guaranteed (@guaranteed Array<Any>) -> ()) -> ()
420+
// CHECK: [[STEP1:%[0-9]+]] = partial_apply [callee_guaranteed] [[THUNK]]<[[OPENED_TY]]>
421+
// CHECK: [[STEP2:%[0-9]+]] = convert_function [[STEP1]] : $@callee_guaranteed (@guaranteed Array<([[OPENED_TY]]).A>) -> () to $@callee_guaranteed @substituted <τ_0_0, τ_0_1 where τ_0_0 == τ_0_1> (@guaranteed Array<τ_0_0>) -> () for <([[OPENED_TY]]).A, ([[OPENED_TY]]).A>
422+
// CHECK: [[STEP3:%[0-9]+]] = convert_escape_to_noescape [not_guaranteed] [[STEP2]]
423+
// CHECK: [[WITNESS:%[0-9]+]] = witness_method $[[OPENED_TY]], #P.covariantAssocMethod8 : <Self where Self : P> (Self) -> ((Self.A...) -> ()) -> ()
424+
// CHECK: apply [[WITNESS]]<[[OPENED_TY]]>([[STEP3]], [[OPENED]]) : $@convention(witness_method: P) <τ_0_0 where τ_0_0 : P> (@noescape @callee_guaranteed @substituted <τ_0_0, τ_0_1 where τ_0_0 == τ_0_1> (@guaranteed Array<τ_0_0>) -> () for <τ_0_0.A, τ_0_0.A>, @in_guaranteed τ_0_0) -> ()
425+
426+
// CHECK: sil shared [transparent] [serializable] [reabstraction_thunk] [ossa] @[[ASSOCTYPE_ARRAY_THUNK_NAME]]
427+
// CHECK: [[ARRAY_UPCAST:%[0-9]+]] = function_ref @$ss15_arrayForceCastySayq_GSayxGr0_lF
428+
// CHECK: apply [[ARRAY_UPCAST]]<τ_0_0.A, Any>
429+
// CHECK: } // end sil function '[[ASSOCTYPE_ARRAY_THUNK_NAME]]'
430+
func testCovariantAssocMethod8(p: any P) {
431+
p.covariantAssocMethod8 { _ in }
432+
}
364433

365434
// CHECK-LABEL: sil hidden [ossa] @$s42existential_member_accesses_self_assoctype27testCovariantAssocProperty11pyAA1P_p_tF
366435
// CHECK: [[LET:%[0-9]+]] = alloc_stack [lexical] $Any, let, name "x"
@@ -444,6 +513,24 @@ func testCovariantAssocProperty6(p: any P) {
444513
func testCovariantAssocProperty7(p: any P) {
445514
let x = p.covariantAssocProperty7
446515
}
516+
// CHECK-LABEL: sil hidden [ossa] @$s42existential_member_accesses_self_assoctype27testCovariantAssocProperty81pyAA1P_p_tF
517+
// CHECK: [[OPENED:%[0-9]+]] = open_existential_addr immutable_access %0 : $*P to $*[[OPENED_TY:@opened\("[0-9A-F-]+"\) P]]
518+
// CHECK: [[OPENED_COPY:%[0-9]+]] = alloc_stack $[[OPENED_TY]]
519+
// CHECK: copy_addr [[OPENED]] to [initialization] [[OPENED_COPY]] : $*[[OPENED_TY]]
520+
// CHECK: [[WITNESS:%[0-9]+]] = witness_method $[[OPENED_TY]], #P.covariantAssocProperty8!getter : <Self where Self : P> (Self) -> () -> ((Self.A...) -> ()) -> ()
521+
// CHECK: [[RESULT_FN:%[0-9]+]] = apply [[WITNESS]]<[[OPENED_TY]]>([[OPENED_COPY]]) : $@convention(witness_method: P) <τ_0_0 where τ_0_0 : P> (@in_guaranteed τ_0_0) -> @owned @callee_guaranteed @substituted <τ_0_0, τ_0_1 where τ_0_0 == τ_0_1> (@noescape @callee_guaranteed @substituted <τ_0_0, τ_0_1 where τ_0_0 == τ_0_1> (@guaranteed Array<τ_0_0>) -> () for <τ_0_0, τ_0_0>) -> () for <τ_0_0.A, τ_0_0.A>
522+
// CHECK: [[STEP1:%[0-9]+]] = convert_function [[RESULT_FN]] : $@callee_guaranteed @substituted <τ_0_0, τ_0_1 where τ_0_0 == τ_0_1> (@noescape @callee_guaranteed @substituted <τ_0_0, τ_0_1 where τ_0_0 == τ_0_1> (@guaranteed Array<τ_0_0>) -> () for <τ_0_0, τ_0_0>) -> () for <([[OPENED_TY]]).A, ([[OPENED_TY]]).A> to $@callee_guaranteed (@noescape @callee_guaranteed @substituted <τ_0_0, τ_0_1 where τ_0_0 == τ_0_1> (@guaranteed Array<τ_0_0>) -> () for <([[OPENED_TY]]).A, ([[OPENED_TY]]).A>) -> ()
523+
// CHECK: [[THUNK:%[0-9]+]] = function_ref @[[THUNK_NAME:\$[0-9a-zA-Z_]+]] : $@convention(thin) <τ_0_0 where τ_0_0 : P> (@noescape @callee_guaranteed (@guaranteed Array<Any>) -> (), @guaranteed @callee_guaranteed (@noescape @callee_guaranteed @substituted <τ_0_0, τ_0_1 where τ_0_0 == τ_0_1> (@guaranteed Array<τ_0_0>) -> () for <τ_0_0.A, τ_0_0.A>) -> ()) -> ()
524+
// CHECK: partial_apply [callee_guaranteed] [[THUNK]]<[[OPENED_TY]]>([[STEP1]])
525+
// CHECK: debug_value %{{[0-9]+}} : $@callee_guaranteed (@noescape @callee_guaranteed (@guaranteed Array<Any>) -> ()) -> (), let, name "x"
526+
// CHECK: } // end sil function '$s42existential_member_accesses_self_assoctype27testCovariantAssocProperty81pyAA1P_p_tF'
527+
528+
// CHECK: sil shared [transparent] [serializable] [reabstraction_thunk] [ossa] @[[THUNK_NAME]]
529+
// CHECK: function_ref @[[ASSOCTYPE_ARRAY_THUNK_NAME]]
530+
// CHECK: } // end sil function '[[THUNK_NAME]]'
531+
func testCovariantAssocProperty8(p: any P) {
532+
let x = p.covariantAssocProperty8
533+
}
447534

448535
// CHECK-LABEL: sil hidden [ossa] @$s42existential_member_accesses_self_assoctype28testCovariantAssocSubscript11pyAA1P_p_tF
449536
// CHECK: [[LET:%[0-9]+]] = alloc_stack [lexical] $Any, let, name "x"
@@ -527,6 +614,19 @@ func testCovariantAssocSubscript6(p: any P) {
527614
func testCovariantAssocSubscript7(p: any P) {
528615
_ = p[covariantAssocSubscript7: { _ in }]
529616
}
617+
// CHECK-LABEL: sil hidden [ossa] @$s42existential_member_accesses_self_assoctype28testCovariantAssocSubscript81pyAA1P_p_tF
618+
// CHECK: [[OPENED:%[0-9]+]] = open_existential_addr immutable_access %0 : $*P to $*[[OPENED_TY:@opened\("[0-9A-F-]+"\) P]]
619+
// CHECK: [[THUNK:%[0-9]+]] = function_ref @[[ASSOCTYPE_ARRAY_THUNK_NAME]] : $@convention(thin) <τ_0_0 where τ_0_0 : P> (@guaranteed Array<τ_0_0.A>, @noescape @callee_guaranteed (@guaranteed Array<Any>) -> ()) -> ()
620+
// CHECK: [[STEP1:%[0-9]+]] = partial_apply [callee_guaranteed] [[THUNK]]<[[OPENED_TY]]>
621+
// CHECK: [[STEP2:%[0-9]+]] = convert_function [[STEP1]] : $@callee_guaranteed (@guaranteed Array<([[OPENED_TY]]).A>) -> () to $@callee_guaranteed @substituted <τ_0_0, τ_0_1 where τ_0_0 == τ_0_1> (@guaranteed Array<τ_0_0>) -> () for <([[OPENED_TY]]).A, ([[OPENED_TY]]).A>
622+
// CHECK: [[STEP3:%[0-9]+]] = convert_escape_to_noescape [not_guaranteed] [[STEP2]]
623+
// CHECK: [[OPENED_COPY:%[0-9]+]] = alloc_stack $[[OPENED_TY]]
624+
// CHECK: copy_addr [[OPENED]] to [initialization] [[OPENED_COPY]] : $*[[OPENED_TY]]
625+
// CHECK: [[WITNESS:%[0-9]+]] = witness_method $[[OPENED_TY]], #P.subscript!getter : <Self where Self : P> (Self) -> ((Self.A...) -> ()) -> ()
626+
// CHECK: apply [[WITNESS]]<[[OPENED_TY]]>([[STEP3]], [[OPENED_COPY]]) : $@convention(witness_method: P) <τ_0_0 where τ_0_0 : P> (@noescape @callee_guaranteed @substituted <τ_0_0, τ_0_1 where τ_0_0 == τ_0_1> (@guaranteed Array<τ_0_0>) -> () for <τ_0_0.A, τ_0_0.A>, @in_guaranteed τ_0_0) -> ()
627+
func testCovariantAssocSubscript8(p: any P) {
628+
_ = p[covariantAssocSubscript8: { _ in }]
629+
}
530630

531631
// -----------------------------------------------------------------------------
532632
// Covariant dependent member type erasure

0 commit comments

Comments
 (0)