@@ -376,7 +376,8 @@ void decodeRequirement(NodePointer node,
376376 llvm::SmallVectorImpl<BuiltRequirement> &requirements,
377377 BuilderType &Builder) {
378378 for (auto &child : *node) {
379- if (child->getKind () == Demangle::Node::Kind::DependentGenericParamCount)
379+ if (child->getKind () == Demangle::Node::Kind::DependentGenericParamCount ||
380+ child->getKind () == Demangle::Node::Kind::DependentGenericParamPackMarker)
380381 continue ;
381382
382383 if (child->getNumChildren () != 2 )
@@ -1180,28 +1181,12 @@ class TypeDecoder {
11801181 llvm::SmallVector<Field, 4 > fields;
11811182 llvm::SmallVector<BuiltSubstitution, 4 > substitutions;
11821183 llvm::SmallVector<BuiltRequirement, 4 > requirements;
1184+ llvm::SmallVector<BuiltType, 4 > genericParams;
11831185
11841186 if (Node->getNumChildren () < 1 )
11851187 return MAKE_NODE_TYPE_ERROR0 (Node, " no children" );
11861188
1187- auto fieldsNode = Node->getChild (0 );
1188- if (fieldsNode->getKind () != NodeKind::SILBoxLayout)
1189- return MAKE_NODE_TYPE_ERROR0 (fieldsNode, " expected layout" );
1190- for (auto *fieldNode : *fieldsNode) {
1191- bool isMutable;
1192- switch (fieldNode->getKind ()) {
1193- case NodeKind::SILBoxMutableField: isMutable = true ; break ;
1194- case NodeKind::SILBoxImmutableField: isMutable = false ; break ;
1195- default :
1196- return MAKE_NODE_TYPE_ERROR0 (fieldNode, " unhandled field type" );
1197- }
1198- if (fieldNode->getNumChildren () < 1 )
1199- return MAKE_NODE_TYPE_ERROR0 (fieldNode, " no children" );
1200- auto type = decodeMangledType (fieldNode->getChild (0 ), depth + 1 );
1201- if (type.isError ())
1202- return type;
1203- fields.emplace_back (type.getType (), isMutable);
1204- }
1189+ bool pushedGenericParams = false ;
12051190
12061191 if (Node->getNumChildren () > 1 ) {
12071192 auto *substNode = Node->getChild (2 );
@@ -1218,47 +1203,76 @@ class TypeDecoder {
12181203 dependentGenericSignatureNode,
12191204 " fewer children (%zu) than required (1)" ,
12201205 dependentGenericSignatureNode->getNumChildren ());
1221- decodeRequirement<BuiltType, BuiltRequirement, BuiltLayoutConstraint,
1222- BuilderType>(dependentGenericSignatureNode,
1223- requirements,
1224- Builder /* ,
1225- [&](NodePointer Node) -> BuiltType {
1226- return decodeMangledType(Node, depth + 1).getType();
1227- },
1228- [&](LayoutConstraintKind Kind) -> BuiltLayoutConstraint {
1229- return {}; // Not implemented!
1230- },
1231- [&](LayoutConstraintKind Kind, unsigned SizeInBits,
1232- unsigned Alignment) -> BuiltLayoutConstraint {
1233- return {}; // Not Implemented!
1234- }*/ );
1206+
12351207 // The number of generic parameters at each depth are in a mini
12361208 // state machine and come first.
12371209 llvm::SmallVector<unsigned , 4 > genericParamsAtDepth;
12381210 for (auto *reqNode : *dependentGenericSignatureNode)
12391211 if (reqNode->getKind () == NodeKind::DependentGenericParamCount)
12401212 if (reqNode->hasIndex ())
12411213 genericParamsAtDepth.push_back (reqNode->getIndex ());
1242- unsigned paramDepth = 0 ;
1243- unsigned index = 0 ;
1244- for (auto *subst : *substNode) {
1245- if (paramDepth >= genericParamsAtDepth.size ())
1246- return MAKE_NODE_TYPE_ERROR0 (
1247- dependentGenericSignatureNode,
1248- " more substitutions than generic params" );
1249- while (index >= genericParamsAtDepth[paramDepth])
1250- ++paramDepth, index = 0 ;
1214+
1215+ llvm::SmallVector<std::pair<unsigned , unsigned >> parameterPacks;
1216+ for (auto &child : *dependentGenericSignatureNode) {
1217+ if (child->getKind () == Demangle::Node::Kind::DependentGenericParamPackMarker) {
1218+ auto *marker = child->getChild (0 )->getChild (0 );
1219+ parameterPacks.emplace_back (marker->getChild (0 )->getIndex (),
1220+ marker->getChild (1 )->getIndex ());
1221+ }
1222+ }
1223+
1224+ Builder.pushGenericParams (parameterPacks);
1225+ pushedGenericParams = true ;
1226+
1227+ // Decode generic parameter types.
1228+ for (unsigned d = 0 ; d < genericParamsAtDepth.size (); ++d) {
1229+ for (unsigned i = 0 ; i < genericParamsAtDepth[d]; ++i) {
1230+ auto paramTy = Builder.createGenericTypeParameterType (d, i);
1231+ genericParams.push_back (paramTy);
1232+ }
1233+ }
1234+
1235+ // Decode requirements.
1236+ decodeRequirement<BuiltType, BuiltRequirement, BuiltLayoutConstraint,
1237+ BuilderType>(dependentGenericSignatureNode,
1238+ requirements,
1239+ Builder);
1240+
1241+ // Decode substitutions.
1242+ for (unsigned i = 0 , e = substNode->getNumChildren (); i < e; ++i) {
1243+ auto *subst = substNode->getChild (i);
12511244 auto substTy = decodeMangledType (subst, depth + 1 ,
12521245 /* forRequirement=*/ false );
12531246 if (substTy.isError ())
12541247 return substTy;
1255- auto paramTy = Builder.createGenericTypeParameterType (
1256- paramDepth, index);
1257- substitutions.emplace_back (paramTy, substTy.getType ());
1258- ++index;
1248+ substitutions.emplace_back (genericParams[i], substTy.getType ());
12591249 }
12601250 }
12611251
1252+ // Decode field types.
1253+ auto fieldsNode = Node->getChild (0 );
1254+ if (fieldsNode->getKind () != NodeKind::SILBoxLayout)
1255+ return MAKE_NODE_TYPE_ERROR0 (fieldsNode, " expected layout" );
1256+ for (auto *fieldNode : *fieldsNode) {
1257+ bool isMutable;
1258+ switch (fieldNode->getKind ()) {
1259+ case NodeKind::SILBoxMutableField: isMutable = true ; break ;
1260+ case NodeKind::SILBoxImmutableField: isMutable = false ; break ;
1261+ default :
1262+ return MAKE_NODE_TYPE_ERROR0 (fieldNode, " unhandled field type" );
1263+ }
1264+ if (fieldNode->getNumChildren () < 1 )
1265+ return MAKE_NODE_TYPE_ERROR0 (fieldNode, " no children" );
1266+ auto type = decodeMangledType (fieldNode->getChild (0 ), depth + 1 );
1267+ if (type.isError ())
1268+ return type;
1269+ fields.emplace_back (type.getType (), isMutable);
1270+ }
1271+
1272+ if (pushedGenericParams) {
1273+ Builder.popGenericParams ();
1274+ }
1275+
12621276 return Builder.createSILBoxTypeWithLayout (fields, substitutions,
12631277 requirements);
12641278 }
0 commit comments