22
22
#include " swift/Basic/LLVM.h"
23
23
24
24
#include " swift/ABI/MetadataValues.h"
25
+ #include " swift/AST/InvertibleProtocolKind.h"
25
26
#include " swift/AST/LayoutConstraintKind.h"
26
27
#include " swift/AST/RequirementKind.h"
27
28
#include " swift/Basic/OptionSet.h"
@@ -422,10 +423,13 @@ getObjCClassOrProtocolName(NodePointer node) {
422
423
#endif
423
424
424
425
template <typename BuiltType, typename BuiltRequirement,
426
+ typename BuiltInverseRequirement,
425
427
typename BuiltLayoutConstraint, typename BuilderType>
426
- void decodeRequirement (NodePointer node,
427
- llvm::SmallVectorImpl<BuiltRequirement> &requirements,
428
- BuilderType &Builder) {
428
+ void decodeRequirement (
429
+ NodePointer node,
430
+ llvm::SmallVectorImpl<BuiltRequirement> &requirements,
431
+ llvm::SmallVectorImpl<BuiltInverseRequirement> &inverseRequirements,
432
+ BuilderType &Builder) {
429
433
for (auto &child : *node) {
430
434
if (child->getKind () == Demangle::Node::Kind::DependentGenericParamCount ||
431
435
child->getKind () == Demangle::Node::Kind::DependentGenericParamPackMarker)
@@ -451,9 +455,40 @@ void decodeRequirement(NodePointer node,
451
455
return ;
452
456
} else if (child->getKind () ==
453
457
Demangle::Node::Kind::DependentGenericInverseConformanceRequirement) {
454
- // FIXME(kavon): this is unimplemented! We should build a PCT here with
455
- // the inverse in it.
456
- return ;
458
+ // Type child
459
+ auto constraintNode = child->getChild (1 );
460
+ if (constraintNode->getKind () != Demangle::Node::Kind::Type ||
461
+ constraintNode->getNumChildren () != 1 )
462
+ return ;
463
+
464
+ // Protocol child
465
+ auto protocolNode = constraintNode->getChild (0 );
466
+ if (protocolNode->getKind () != Demangle::Node::Kind::Protocol ||
467
+ protocolNode->getNumChildren () != 2 )
468
+ return ;
469
+
470
+ auto moduleNode = protocolNode->getChild (0 );
471
+ if (moduleNode->getKind () != Demangle::Node::Kind::Module ||
472
+ moduleNode->getText () != " Swift" )
473
+ return ;
474
+
475
+ auto protocolNameNode = protocolNode->getChild (1 );
476
+ if (protocolNameNode->getKind () != Demangle::Node::Kind::Identifier)
477
+ return ;
478
+
479
+ auto protocolName = protocolNameNode->getText ();
480
+ using OptInvertibleKind = std::optional<InvertibleProtocolKind>;
481
+ auto protocolKind = llvm::StringSwitch<OptInvertibleKind>(protocolName)
482
+ #define INVERTIBLE_PROTOCOL_WITH_NAME (Id, Name ) \
483
+ .Case (Name, InvertibleProtocolKind::Id)
484
+ #include " swift/AST/KnownProtocols.def"
485
+ .Default (std::nullopt);
486
+ if (!protocolKind)
487
+ return ;
488
+
489
+ inverseRequirements.push_back (
490
+ Builder.createInverseRequirement (subjectType, *protocolKind));
491
+ continue ;
457
492
}
458
493
459
494
@@ -538,6 +573,7 @@ class TypeDecoder {
538
573
using Field = typename BuilderType::BuiltSILBoxField;
539
574
using BuiltSubstitution = typename BuilderType::BuiltSubstitution;
540
575
using BuiltRequirement = typename BuilderType::BuiltRequirement;
576
+ using BuiltInverseRequirement = typename BuilderType::BuiltInverseRequirement;
541
577
using BuiltLayoutConstraint = typename BuilderType::BuiltLayoutConstraint;
542
578
using BuiltGenericSignature = typename BuilderType::BuiltGenericSignature;
543
579
using BuiltSubstitutionMap = typename BuilderType::BuiltSubstitutionMap;
@@ -800,16 +836,19 @@ class TypeDecoder {
800
836
return protocolType;
801
837
802
838
llvm::SmallVector<BuiltRequirement, 8 > requirements;
839
+ llvm::SmallVector<BuiltInverseRequirement, 8 > inverseRequirements;
803
840
804
841
auto *reqts = Node->getChild (1 );
805
842
if (reqts->getKind () != NodeKind::ConstrainedExistentialRequirementList)
806
843
return MAKE_NODE_TYPE_ERROR0 (reqts, " is not requirement list" );
807
844
808
- decodeRequirement<BuiltType, BuiltRequirement, BuiltLayoutConstraint,
809
- BuilderType>(reqts, requirements, Builder);
845
+ decodeRequirement<BuiltType, BuiltRequirement, BuiltInverseRequirement,
846
+ BuiltLayoutConstraint, BuilderType>(
847
+ reqts, requirements, inverseRequirements, Builder);
810
848
811
849
return Builder.createConstrainedExistentialType (protocolType.getType (),
812
- requirements);
850
+ requirements,
851
+ inverseRequirements);
813
852
}
814
853
case NodeKind::ConstrainedExistentialSelf:
815
854
return Builder.createGenericTypeParameterType (/* depth*/ 0 , /* index*/ 0 );
@@ -1280,6 +1319,7 @@ class TypeDecoder {
1280
1319
llvm::SmallVector<Field, 4 > fields;
1281
1320
llvm::SmallVector<BuiltSubstitution, 4 > substitutions;
1282
1321
llvm::SmallVector<BuiltRequirement, 4 > requirements;
1322
+ llvm::SmallVector<BuiltInverseRequirement, 8 > inverseRequirements;
1283
1323
llvm::SmallVector<BuiltType, 4 > genericParams;
1284
1324
1285
1325
if (Node->getNumChildren () < 1 )
@@ -1332,10 +1372,10 @@ class TypeDecoder {
1332
1372
}
1333
1373
1334
1374
// Decode requirements.
1335
- decodeRequirement<BuiltType, BuiltRequirement, BuiltLayoutConstraint ,
1336
- BuilderType>(dependentGenericSignatureNode,
1337
- requirements,
1338
- Builder);
1375
+ decodeRequirement<BuiltType, BuiltRequirement, BuiltInverseRequirement ,
1376
+ BuiltLayoutConstraint, BuilderType>(
1377
+ dependentGenericSignatureNode, requirements, inverseRequirements ,
1378
+ Builder);
1339
1379
1340
1380
// Decode substitutions.
1341
1381
for (unsigned i = 0 , e = substNode->getNumChildren (); i < e; ++i) {
@@ -1373,7 +1413,8 @@ class TypeDecoder {
1373
1413
}
1374
1414
1375
1415
return Builder.createSILBoxTypeWithLayout (fields, substitutions,
1376
- requirements);
1416
+ requirements,
1417
+ inverseRequirements);
1377
1418
}
1378
1419
case NodeKind::SugaredOptional: {
1379
1420
if (Node->getNumChildren () < 1 )
0 commit comments