2828#include " swift/AST/MacroDiscriminatorContext.h"
2929#include " swift/AST/Module.h"
3030#include " swift/AST/Ownership.h"
31+ #include " swift/AST/PackConformance.h"
3132#include " swift/AST/ParameterList.h"
3233#include " swift/AST/PrettyStackTrace.h"
3334#include " swift/AST/ProtocolConformance.h"
@@ -1874,8 +1875,22 @@ static bool isRetroactiveConformance(const RootProtocolConformance *root) {
18741875// / Determine whether the given protocol conformance contains a retroactive
18751876// / protocol conformance anywhere in it.
18761877static bool containsRetroactiveConformance (
1877- const ProtocolConformance *conformance ,
1878+ ProtocolConformanceRef conformanceRef ,
18781879 ModuleDecl *module ) {
1880+ if (!conformanceRef.isPack () && !conformanceRef.isConcrete ())
1881+ return false ;
1882+
1883+ if (conformanceRef.isPack ()) {
1884+ for (auto patternConf : conformanceRef.getPack ()->getPatternConformances ()) {
1885+ if (containsRetroactiveConformance (patternConf, module ))
1886+ return true ;
1887+ }
1888+
1889+ return false ;
1890+ }
1891+
1892+ auto *conformance = conformanceRef.getConcrete ();
1893+
18791894 // If the root conformance is retroactive, it's retroactive.
18801895 const RootProtocolConformance *rootConformance =
18811896 conformance->getRootConformance ();
@@ -1897,8 +1912,7 @@ static bool containsRetroactiveConformance(
18971912 // for indexing purposes.
18981913 continue ;
18991914 }
1900- if (conformance.isConcrete () &&
1901- containsRetroactiveConformance (conformance.getConcrete (), module )) {
1915+ if (containsRetroactiveConformance (conformance, module )) {
19021916 return true ;
19031917 }
19041918 }
@@ -1924,14 +1938,18 @@ void ASTMangler::appendRetroactiveConformances(SubstitutionMap subMap,
19241938 };
19251939
19261940 // Ignore abstract conformances.
1927- if (!conformance.isConcrete ())
1941+ if (!conformance.isConcrete () && !conformance. isPack () )
19281942 continue ;
19291943
19301944 // Skip non-retroactive conformances.
1931- if (!containsRetroactiveConformance (conformance. getConcrete () , fromModule))
1945+ if (!containsRetroactiveConformance (conformance, fromModule))
19321946 continue ;
19331947
1934- appendConcreteProtocolConformance (conformance.getConcrete (), sig);
1948+ if (conformance.isConcrete ())
1949+ appendConcreteProtocolConformance (conformance.getConcrete (), sig);
1950+ else
1951+ appendPackProtocolConformance (conformance.getPack (), sig);
1952+
19351953 appendOperator (" g" , Index (numProtocolRequirements));
19361954 }
19371955}
@@ -4143,8 +4161,14 @@ void ASTMangler::appendAnyProtocolConformance(
41434161 appendDependentProtocolConformance (conformancePath, opaqueSignature);
41444162 appendType (conformingType, genericSig);
41454163 appendOperator (" HO" );
4146- } else {
4164+ } else if (conformance. isConcrete ()) {
41474165 appendConcreteProtocolConformance (conformance.getConcrete (), genericSig);
4166+ } else if (conformance.isPack ()) {
4167+ appendPackProtocolConformance (conformance.getPack (), genericSig);
4168+ } else {
4169+ llvm::errs () << " Bad conformance in mangler: " ;
4170+ conformance.dump (llvm::errs ());
4171+ abort ();
41484172 }
41494173}
41504174
@@ -4199,6 +4223,32 @@ void ASTMangler::appendConcreteProtocolConformance(
41994223 appendOperator (" HC" );
42004224}
42014225
4226+ void ASTMangler::appendPackProtocolConformance (
4227+ const PackConformance *conformance,
4228+ GenericSignature sig) {
4229+ auto conformingType = conformance->getType ();
4230+ auto patternConformances = conformance->getPatternConformances ();
4231+ assert (conformingType->getNumElements () == patternConformances.size ());
4232+
4233+ if (conformingType->getNumElements () == 0 ) {
4234+ appendOperator (" y" );
4235+ } else {
4236+ bool firstField = true ;
4237+ for (unsigned i = 0 , e = conformingType->getNumElements (); i < e; ++i) {
4238+ auto type = conformingType->getElementType (i);
4239+ auto conf = patternConformances[i];
4240+
4241+ if (auto *expansionTy = type->getAs <PackExpansionType>())
4242+ type = expansionTy->getPatternType ();
4243+
4244+ appendAnyProtocolConformance (sig, type->getCanonicalType (), conf);
4245+ appendListSeparator (firstField);
4246+ }
4247+ }
4248+
4249+ appendOperator (" HX" );
4250+ }
4251+
42024252void ASTMangler::appendOpParamForLayoutConstraint (LayoutConstraint layout) {
42034253 assert (layout);
42044254 switch (layout->getKind ()) {
0 commit comments