@@ -1719,6 +1719,35 @@ ModuleFile::getSubstitutionMapChecked(serialization::SubstitutionMapID id) {
17191719 return substitutions;
17201720}
17211721
1722+ bool ModuleFile::readInheritedProtocols (
1723+ SmallVectorImpl<ProtocolDecl *> &inherited) {
1724+ using namespace decls_block ;
1725+
1726+ BCOffsetRAII lastRecordOffset (DeclTypeCursor);
1727+
1728+ llvm::BitstreamEntry entry =
1729+ fatalIfUnexpected (DeclTypeCursor.advance (AF_DontPopBlockAtEnd));
1730+ if (entry.Kind != llvm::BitstreamEntry::Record)
1731+ return false ;
1732+
1733+ SmallVector<uint64_t , 8 > scratch;
1734+ unsigned recordID =
1735+ fatalIfUnexpected (DeclTypeCursor.readRecord (entry.ID , scratch));
1736+ if (recordID != INHERITED_PROTOCOLS)
1737+ return false ;
1738+
1739+ lastRecordOffset.reset ();
1740+
1741+ ArrayRef<uint64_t > inheritedIDs;
1742+ InheritedProtocolsLayout::readRecord (scratch, inheritedIDs);
1743+
1744+ llvm::transform (inheritedIDs, std::back_inserter (inherited),
1745+ [&](uint64_t protocolID) {
1746+ return cast<ProtocolDecl>(getDecl (protocolID));
1747+ });
1748+ return true ;
1749+ }
1750+
17221751bool ModuleFile::readDefaultWitnessTable (ProtocolDecl *proto) {
17231752 using namespace decls_block ;
17241753
@@ -3187,6 +3216,21 @@ class DeclDeserializer {
31873216 decl.get <ExtensionDecl *>()->setInherited (inherited);
31883217 }
31893218
3219+ void handleInherited (ProtocolDecl *P,
3220+ ArrayRef<ProtocolDecl *> inherited) {
3221+ SmallVector<InheritedEntry, 2 > inheritedTypes;
3222+ llvm::transform (inherited, std::back_inserter (inheritedTypes), [](auto *I) {
3223+ return InheritedEntry (TypeLoc::withoutLoc (I->getDeclaredInterfaceType ()),
3224+ /* isUnchecked=*/ false ,
3225+ /* isRetroactive=*/ false ,
3226+ /* isPreconcurrency=*/ false );
3227+ });
3228+
3229+ P->setInherited (ctx.AllocateCopy (inheritedTypes));
3230+ ctx.evaluator .cacheOutput (InheritedProtocolsRequest{P},
3231+ ctx.AllocateCopy (inherited));
3232+ }
3233+
31903234public:
31913235 DeclDeserializer (ModuleFile &MF, Serialized<Decl *> &declOrOffset)
31923236 : MF(MF), ctx(MF.getContext()), declOrOffset(declOrOffset) {}
@@ -4425,21 +4469,21 @@ class DeclDeserializer {
44254469 IdentifierID nameID;
44264470 DeclContextID contextID;
44274471 bool isImplicit, isClassBounded, isObjC, hasSelfOrAssocTypeRequirements;
4472+ TypeID superclassID;
44284473 uint8_t rawAccessLevel;
4429- unsigned numInheritedTypes;
4430- ArrayRef<uint64_t > rawInheritedAndDependencyIDs;
4474+ ArrayRef<uint64_t > dependencyIDs;
44314475
44324476 decls_block::ProtocolLayout::readRecord (scratch, nameID, contextID,
44334477 isImplicit, isClassBounded, isObjC,
44344478 hasSelfOrAssocTypeRequirements,
4435- rawAccessLevel, numInheritedTypes,
4436- rawInheritedAndDependencyIDs);
4479+ superclassID,
4480+ rawAccessLevel,
4481+ dependencyIDs);
44374482
44384483 Identifier name = MF.getIdentifier (nameID);
44394484 PrettySupplementalDeclNameTrace trace (name);
44404485
4441- for (TypeID dependencyID :
4442- rawInheritedAndDependencyIDs.slice (numInheritedTypes)) {
4486+ for (TypeID dependencyID : dependencyIDs) {
44434487 auto dependency = MF.getTypeChecked (dependencyID);
44444488 if (!dependency) {
44454489 return llvm::make_error<TypeError>(
@@ -4457,6 +4501,8 @@ class DeclDeserializer {
44574501 /* TrailingWhere=*/ nullptr );
44584502 declOrOffset = proto;
44594503
4504+ proto->setSuperclass (MF.getType (superclassID));
4505+
44604506 ctx.evaluator .cacheOutput (ProtocolRequiresClassRequest{proto},
44614507 std::move (isClassBounded));
44624508 ctx.evaluator .cacheOutput (HasSelfOrAssociatedTypeRequirementsRequest{proto},
@@ -4467,14 +4513,17 @@ class DeclDeserializer {
44674513 else
44684514 return MF.diagnoseFatal ();
44694515
4516+ SmallVector<ProtocolDecl *, 2 > inherited;
4517+ if (!MF.readInheritedProtocols (inherited))
4518+ return MF.diagnoseFatal ();
4519+
4520+ handleInherited (proto, inherited);
4521+
44704522 auto genericParams = MF.maybeReadGenericParams (DC);
44714523 assert (genericParams && " protocol with no generic parameters?" );
44724524 ctx.evaluator .cacheOutput (GenericParamListRequest{proto},
44734525 std::move (genericParams));
44744526
4475- handleInherited (proto,
4476- rawInheritedAndDependencyIDs.slice (0 , numInheritedTypes));
4477-
44784527 if (isImplicit)
44794528 proto->setImplicit ();
44804529 proto->setIsObjC (isObjC);
0 commit comments