@@ -372,12 +372,16 @@ void decodeRequirement(NodePointer node,
372
372
373
373
BuiltType constraintType;
374
374
if (child->getKind () ==
375
- Demangle::Node::Kind::DependentGenericConformanceRequirement ||
376
- child->getKind () ==
377
- Demangle::Node::Kind::DependentGenericSameTypeRequirement) {
375
+ Demangle::Node::Kind::DependentGenericConformanceRequirement) {
378
376
constraintType = Builder.decodeMangledType (child->getChild (1 ));
379
377
if (!constraintType)
380
378
return ;
379
+ } else if (child->getKind () ==
380
+ Demangle::Node::Kind::DependentGenericSameTypeRequirement) {
381
+ constraintType = Builder.decodeMangledType (
382
+ child->getChild (1 ), /* forRequirement=*/ false );
383
+ if (!constraintType)
384
+ return ;
381
385
}
382
386
383
387
switch (child->getKind ()) {
@@ -468,15 +472,17 @@ class TypeDecoder {
468
472
explicit TypeDecoder (BuilderType &Builder) : Builder(Builder) {}
469
473
470
474
// / Given a demangle tree, attempt to turn it into a type.
471
- TypeLookupErrorOr<BuiltType> decodeMangledType (NodePointer Node) {
472
- return decodeMangledType (Node, 0 );
475
+ TypeLookupErrorOr<BuiltType> decodeMangledType (NodePointer Node,
476
+ bool forRequirement = true ) {
477
+ return decodeMangledType (Node, 0 , forRequirement);
473
478
}
474
479
475
480
protected:
476
481
static const unsigned MaxDepth = 1024 ;
477
482
478
483
TypeLookupErrorOr<BuiltType> decodeMangledType (NodePointer Node,
479
- unsigned depth) {
484
+ unsigned depth,
485
+ bool forRequirement = true ) {
480
486
if (depth > TypeDecoder::MaxDepth)
481
487
return TypeLookupError (" Mangled type is too complex" );
482
488
@@ -499,7 +505,8 @@ class TypeDecoder {
499
505
if (Node->getNumChildren () < 1 )
500
506
return MAKE_NODE_TYPE_ERROR0 (Node, " no children." );
501
507
502
- return decodeMangledType (Node->getChild (0 ), depth + 1 );
508
+ return decodeMangledType (Node->getChild (0 ), depth + 1 ,
509
+ forRequirement);
503
510
case NodeKind::Class:
504
511
{
505
512
#if SWIFT_OBJC_INTEROP
@@ -543,7 +550,8 @@ class TypeDecoder {
543
550
return MAKE_NODE_TYPE_ERROR0 (genericArgs, " is not TypeList" );
544
551
545
552
for (auto genericArg : *genericArgs) {
546
- auto paramType = decodeMangledType (genericArg, depth + 1 );
553
+ auto paramType = decodeMangledType (genericArg, depth + 1 ,
554
+ /* forRequirement=*/ false );
547
555
if (paramType.isError ())
548
556
return paramType;
549
557
args.push_back (paramType.getType ());
@@ -698,14 +706,16 @@ class TypeDecoder {
698
706
}
699
707
700
708
return Builder.createProtocolCompositionType (Protocols, Superclass,
701
- IsClassBound);
709
+ IsClassBound,
710
+ forRequirement);
702
711
}
703
712
704
713
case NodeKind::Protocol:
705
714
case NodeKind::ProtocolSymbolicReference: {
706
715
if (auto Proto = decodeMangledProtocolType (Node, depth + 1 )) {
707
716
return Builder.createProtocolCompositionType (Proto, BuiltType (),
708
- /* IsClassBound=*/ false );
717
+ /* IsClassBound=*/ false ,
718
+ forRequirement);
709
719
}
710
720
711
721
return MAKE_NODE_TYPE_ERROR0 (Node, " failed to decode protocol type" );
@@ -845,7 +855,8 @@ class TypeDecoder {
845
855
Node->getKind () == NodeKind::EscapingObjCBlock);
846
856
847
857
auto result =
848
- decodeMangledType (Node->getChild (firstChildIdx + 1 ), depth + 1 );
858
+ decodeMangledType (Node->getChild (firstChildIdx + 1 ), depth + 1 ,
859
+ /* forRequirement=*/ false );
849
860
if (result.isError ())
850
861
return result;
851
862
return Builder.createFunctionType (
@@ -962,7 +973,8 @@ class TypeDecoder {
962
973
if (Node->getNumChildren () < 1 )
963
974
return MAKE_NODE_TYPE_ERROR0 (Node, " no children" );
964
975
965
- return decodeMangledType (Node->getChild (0 ), depth + 1 );
976
+ return decodeMangledType (Node->getChild (0 ), depth + 1 ,
977
+ /* forRequirement=*/ false );
966
978
967
979
case NodeKind::Tuple: {
968
980
llvm::SmallVector<BuiltType, 8 > elements;
@@ -994,7 +1006,8 @@ class TypeDecoder {
994
1006
995
1007
// Decode the element type.
996
1008
auto elementType =
997
- decodeMangledType (element->getChild (typeChildIndex), depth + 1 );
1009
+ decodeMangledType (element->getChild (typeChildIndex), depth + 1 ,
1010
+ /* forRequirement=*/ false );
998
1011
if (elementType.isError ())
999
1012
return elementType;
1000
1013
@@ -1012,9 +1025,11 @@ class TypeDecoder {
1012
1025
" fewer children (%zu) than required (2)" ,
1013
1026
Node->getNumChildren ());
1014
1027
1015
- return decodeMangledType (Node->getChild (1 ), depth + 1 );
1028
+ return decodeMangledType (Node->getChild (1 ), depth + 1 ,
1029
+ /* forRequirement=*/ false );
1016
1030
}
1017
- return decodeMangledType (Node->getChild (0 ), depth + 1 );
1031
+ return decodeMangledType (Node->getChild (0 ), depth + 1 ,
1032
+ /* forRequirement=*/ false );
1018
1033
1019
1034
case NodeKind::DependentGenericType: {
1020
1035
if (Node->getNumChildren () < 2 )
@@ -1161,7 +1176,8 @@ return {}; // Not Implemented!
1161
1176
" more substitutions than generic params" );
1162
1177
while (index >= genericParamsAtDepth[paramDepth])
1163
1178
++paramDepth, index = 0 ;
1164
- auto substTy = decodeMangledType (subst, depth + 1 );
1179
+ auto substTy = decodeMangledType (subst, depth + 1 ,
1180
+ /* forRequirement=*/ false );
1165
1181
if (substTy.isError ())
1166
1182
return substTy;
1167
1183
substitutions.emplace_back (
@@ -1243,7 +1259,8 @@ return {}; // Not Implemented!
1243
1259
if (genericsNode->getKind () != NodeKind::TypeList)
1244
1260
break ;
1245
1261
for (auto argNode : *genericsNode) {
1246
- auto arg = decodeMangledType (argNode, depth + 1 );
1262
+ auto arg = decodeMangledType (argNode, depth + 1 ,
1263
+ /* forRequirement=*/ false );
1247
1264
if (arg.isError ())
1248
1265
return arg;
1249
1266
genericArgsBuf.push_back (arg.getType ());
@@ -1479,7 +1496,8 @@ return {}; // Not Implemented!
1479
1496
}
1480
1497
}
1481
1498
1482
- auto paramType = decodeMangledType (node, depth + 1 );
1499
+ auto paramType = decodeMangledType (node, depth + 1 ,
1500
+ /* forRequirement=*/ false );
1483
1501
if (paramType.isError ())
1484
1502
return false ;
1485
1503
@@ -1543,8 +1561,10 @@ return {}; // Not Implemented!
1543
1561
1544
1562
template <typename BuilderType>
1545
1563
inline TypeLookupErrorOr<typename BuilderType::BuiltType>
1546
- decodeMangledType (BuilderType &Builder, NodePointer Node) {
1547
- return TypeDecoder<BuilderType>(Builder).decodeMangledType (Node);
1564
+ decodeMangledType (BuilderType &Builder, NodePointer Node,
1565
+ bool forRequirement = false ) {
1566
+ return TypeDecoder<BuilderType>(Builder)
1567
+ .decodeMangledType (Node, forRequirement);
1548
1568
}
1549
1569
1550
1570
SWIFT_END_INLINE_NAMESPACE
0 commit comments