@@ -377,6 +377,27 @@ bb0(%0 : $*Pack{any P}, %1 : $*Pack{any P}):
377377 return %17
378378}
379379
380+ // Handling of generic type parameters in packs.
381+ // We should wait until these are fully specialized before exploding.
382+ sil [ossa] @copy_pack_generic : $@convention(thin) <T> (@pack_guaranteed Pack{T}) -> @pack_out Pack{T} {
383+ bb0(%0 : $*Pack{T}, %1 : $*Pack{T}):
384+ %2 = tuple ()
385+ return %2
386+ }
387+
388+ // CHECK-LABEL: sil [ossa] @call_copy_pack_generic : $@convention(thin) <T> (@pack_guaranteed Pack{T}) -> @pack_out Pack{T} {
389+ // CHECK: bb0(%0 : $*Pack{T}, %1 : $*Pack{T})
390+ // CHECK: [[CPG:%[0-9]+]] = function_ref @copy_pack_generic
391+ // CHECK-NEXT: [[RESULT:%[0-9]+]] = apply [[CPG]]
392+ // CHECK-NEXT: return [[RESULT]]
393+ // CHECK-LABEL: } // end sil function 'call_copy_pack_generic'
394+ sil [ossa] @call_copy_pack_generic : $@convention(thin) <T> (@pack_guaranteed Pack{T}) -> @pack_out Pack{T} {
395+ bb0(%0 : $*Pack{T}, %1 : $*Pack{T}):
396+ %16 = function_ref @copy_pack_generic : $@convention(thin) <T> (@pack_guaranteed Pack{T}) -> @pack_out Pack{T}
397+ %17 = apply %16<T>(%0, %1) : $@convention(thin) <T> (@pack_guaranteed Pack{T}) -> @pack_out Pack{T}
398+ return %17
399+ }
400+
380401// INTERLEAVING PACK AND NON-PACK ARGUMENTS TESTS:
381402//
382403// The new function arguments and return values corresponding to pack parameters
@@ -699,7 +720,8 @@ bb0(%0 : $*Pack{Int}):
699720// BAIL OUT CONDITION TESTS:
700721//
701722// Only perform pack specialization on functions that have indirect pack
702- // parameters that contain no pack expansions.
723+ // parameters and/or results that contain no pack expansions or generic type
724+ // parameters.
703725//
704726// 2025-10-15: We currently only explode packs with address elements
705727// (SILPackType::isElementAddress), because these are the most common (since
@@ -789,3 +811,54 @@ bb0(%0 : $*Pack{Int}):
789811 %2 = apply %1(%0) : $@convention(thin) (@pack_guaranteed Pack{Int}) -> ()
790812 return %2
791813}
814+
815+
816+ sil [ossa] @indirect_result_pack : $@convention(thin) () -> @pack_out Pack{Int} {
817+ bb0(%0 : $*Pack{Int}):
818+ %1 = tuple ()
819+ return %1
820+ }
821+
822+ sil [ossa] @direct_result_pack : $@convention(thin) () -> @pack_out @direct Pack{Int} {
823+ bb0(%0 : $*@direct Pack{Int}):
824+ %1 = tuple ()
825+ return %1
826+ }
827+
828+ sil [ossa] @result_pack_expansion : $@convention(thin) <each A> () -> @pack_out Pack{repeat each A} {
829+ bb0(%0 : $*Pack{repeat each A}):
830+ %1 = tuple ()
831+ return %1
832+ }
833+
834+ sil [ossa] @mixed_result_packs : $@convention(thin) <each A> () -> (@pack_out Pack{Int}, @pack_out @direct Pack{Int}, @pack_out Pack{repeat each A}) {
835+ bb0(%0 : $*Pack{Int}, %1 : $*@direct Pack{Int}, %2 : $*Pack{repeat each A}):
836+ %3 = tuple ()
837+ return %3
838+ }
839+
840+ // CHECK-LABEL: sil [ossa] @result_call_eligibility_tests : $@convention(thin) <each A> () -> (@pack_out Pack{Int}, @pack_out @direct Pack{Int}, @pack_out Pack{repeat each A}) {
841+ // CHECK: bb0(%0 : $*Pack{Int}, %1 : $*@direct Pack{Int}, %2 : $*Pack{repeat each A}):
842+ // CHECK: function_ref @$s20indirect_result_packTf8x_n : $@convention(thin) () -> Int
843+ // CHECK: function_ref @direct_result_pack : $@convention(thin) () -> @pack_out @direct Pack{Int}
844+ // CHECK: function_ref @result_pack_expansion : $@convention(thin) <each τ_0_0> () -> @pack_out Pack{repeat each τ_0_0}
845+ // CHECK: function_ref @$s18mixed_result_packsTf8xnn_n : $@convention(thin) <each τ_0_0> () -> (Int, @pack_out @direct Pack{Int}, @pack_out Pack{repeat each τ_0_0})
846+ // CHECK-LABEL: } // end sil function 'result_call_eligibility_tests'
847+ sil [ossa] @result_call_eligibility_tests : $@convention(thin) <each A> () -> (@pack_out Pack{Int}, @pack_out @direct Pack{Int}, @pack_out Pack{repeat each A}) {
848+ bb0(%1 : $*Pack{Int}, %2 : $*@direct Pack{Int}, %3 : $*Pack{repeat each A}):
849+
850+ %4 = function_ref @indirect_result_pack : $@convention(thin) () -> @pack_out Pack{Int}
851+ %5 = apply %4(%1) : $@convention(thin) () -> @pack_out Pack{Int}
852+
853+ %8 = function_ref @direct_result_pack : $@convention(thin) () -> @pack_out @direct Pack{Int}
854+ %9 = apply %8(%2) : $@convention(thin) () -> @pack_out @direct Pack{Int}
855+
856+ %10 = function_ref @result_pack_expansion : $@convention(thin) <each A> () -> @pack_out Pack{repeat each A}
857+ %11 = apply %10<Pack{repeat each A}>(%3) : $@convention(thin) <each A> () -> @pack_out Pack{repeat each A}
858+
859+ %12 = function_ref @mixed_result_packs : $@convention(thin) <each A> () -> (@pack_out Pack{Int}, @pack_out @direct Pack{Int}, @pack_out Pack{repeat each A})
860+ %13 = apply %12<Pack{repeat each A}>(%1, %2, %3) : $@convention(thin) <each A> () -> (@pack_out Pack{Int}, @pack_out @direct Pack{Int}, @pack_out Pack{repeat each A})
861+
862+ %99 = tuple ()
863+ return %99
864+ }
0 commit comments