@@ -1584,7 +1584,15 @@ class SubstFunctionTypePatternVisitor
1584
1584
// If so, let's put a fresh generic parameter in the substituted signature
1585
1585
// here.
1586
1586
unsigned paramIndex = substGenericParams.size ();
1587
- auto gp = GenericTypeParamType::get (false , 0 , paramIndex, TC.Context );
1587
+
1588
+ bool isParameterPack = false ;
1589
+ if (substTy->isParameterPack () || substTy->is <PackArchetypeType>())
1590
+ isParameterPack = true ;
1591
+ else if (pattern.isTypeParameterPack ())
1592
+ isParameterPack = true ;
1593
+
1594
+ auto gp = GenericTypeParamType::get (isParameterPack, 0 , paramIndex,
1595
+ TC.Context );
1588
1596
substGenericParams.push_back (gp);
1589
1597
substReplacementTypes.push_back (substTy);
1590
1598
@@ -1881,11 +1889,30 @@ class SubstFunctionTypePatternVisitor
1881
1889
}
1882
1890
1883
1891
CanType visitPackType (PackType *pack, AbstractionPattern pattern) {
1884
- llvm_unreachable (" Unimplemented!" );
1892
+ if (auto gp = handleTypeParameterInAbstractionPattern (pattern, pack))
1893
+ return gp;
1894
+
1895
+ // Break down the pack.
1896
+ SmallVector<Type, 4 > packElts;
1897
+ for (unsigned i = 0 ; i < pack->getNumElements (); ++i) {
1898
+ packElts.push_back (visit (pack->getElementType (i),
1899
+ pattern.getPackElementType (i)));
1900
+ }
1901
+
1902
+ return CanType (PackType::get (TC.Context , packElts));
1885
1903
}
1886
1904
1887
- CanType visitPackExpansionType (PackExpansionType *pack, AbstractionPattern pattern) {
1888
- llvm_unreachable (" Unimplemented!" );
1905
+ CanType visitPackExpansionType (PackExpansionType *pack,
1906
+ AbstractionPattern pattern) {
1907
+ // Avoid walking into the pattern and count type if we can help it.
1908
+ if (!pack->hasTypeParameter () && !pack->hasArchetype () &&
1909
+ !pack->hasOpaqueArchetype ()) {
1910
+ return CanType (pack);
1911
+ }
1912
+
1913
+ return CanType (PackExpansionType::get (
1914
+ visit (pack->getPatternType (), pattern.getPackExpansionPatternType ()),
1915
+ visit (pack->getCountType (), pattern.getPackExpansionCountType ())));
1889
1916
}
1890
1917
1891
1918
CanType visitExistentialType (ExistentialType *exist,
0 commit comments