@@ -991,42 +991,37 @@ void ModuleFile::readAssociatedTypes(
991991 }
992992}
993993
994- // / Advances past any records that might be part of a protocol requirement
995- // / signature, which consists of generic requirements together with protocol
996- // / typealias records.
997- static llvm::Error skipRequirementSignature (llvm::BitstreamCursor &Cursor) {
994+ void ModuleFile::readPrimaryAssociatedTypes (
995+ SmallVectorImpl<AssociatedTypeDecl *> &assocTypes,
996+ llvm::BitstreamCursor &Cursor) {
998997 using namespace decls_block ;
999998
1000999 BCOffsetRAII lastRecordOffset (Cursor);
1000+ SmallVector<uint64_t , 8 > scratch;
1001+ StringRef blobData;
10011002
10021003 while (true ) {
1003- Expected<llvm::BitstreamEntry> maybeEntry =
1004- Cursor.advance (AF_DontPopBlockAtEnd);
1005- if (!maybeEntry)
1006- return maybeEntry.takeError ();
1007- llvm::BitstreamEntry entry = maybeEntry.get ();
1004+ lastRecordOffset.reset ();
1005+
1006+ llvm::BitstreamEntry entry =
1007+ fatalIfUnexpected (Cursor.advance (AF_DontPopBlockAtEnd));
10081008 if (entry.Kind != llvm::BitstreamEntry::Record)
10091009 break ;
10101010
1011- Expected<unsigned > maybeRecordID = Cursor.skipRecord (entry.ID );
1012- if (!maybeRecordID)
1013- return maybeRecordID.takeError ();
1014- switch (maybeRecordID.get ()) {
1015- case REQUIREMENT_SIGNATURE:
1011+ scratch.clear ();
1012+ unsigned recordID = fatalIfUnexpected (
1013+ Cursor.readRecord (entry.ID , scratch, &blobData));
1014+ if (recordID != PRIMARY_ASSOCIATED_TYPE)
10161015 break ;
10171016
1018- default :
1019- // This record is not a generic requirement.
1020- return llvm::Error::success ();
1021- }
1017+ DeclID declID;
1018+ PrimaryAssociatedTypeLayout::readRecord (scratch, declID);
10221019
1023- lastRecordOffset. reset ( );
1020+ assocTypes. push_back (cast<AssociatedTypeDecl>( getDecl (declID)) );
10241021 }
1025- return llvm::Error::success ();
10261022}
10271023
1028- // / Advances past any lazy associated type member records.
1029- static llvm::Error skipAssociatedTypeMembers (llvm::BitstreamCursor &Cursor) {
1024+ static llvm::Error skipRecords (llvm::BitstreamCursor &Cursor, unsigned kind) {
10301025 using namespace decls_block ;
10311026
10321027 BCOffsetRAII lastRecordOffset (Cursor);
@@ -1043,20 +1038,39 @@ static llvm::Error skipAssociatedTypeMembers(llvm::BitstreamCursor &Cursor) {
10431038 Expected<unsigned > maybeRecordID = Cursor.skipRecord (entry.ID );
10441039 if (!maybeRecordID)
10451040 return maybeRecordID.takeError ();
1046- switch (maybeRecordID.get ()) {
1047- case ASSOCIATED_TYPE:
1048- break ;
1049-
1050- default :
1051- // This record is not an associated type.
1041+ if (maybeRecordID.get () != kind)
10521042 return llvm::Error::success ();
1053- }
10541043
10551044 lastRecordOffset.reset ();
10561045 }
1046+
10571047 return llvm::Error::success ();
10581048}
10591049
1050+ // / Advances past any records that might be part of a protocol requirement
1051+ // / signature, which consists of generic requirements together with protocol
1052+ // / typealias records.
1053+ static llvm::Error skipRequirementSignature (llvm::BitstreamCursor &Cursor) {
1054+ using namespace decls_block ;
1055+
1056+ return skipRecords (Cursor, REQUIREMENT_SIGNATURE);
1057+ }
1058+
1059+ // / Advances past any lazy associated type member records.
1060+ static llvm::Error skipAssociatedTypeMembers (llvm::BitstreamCursor &Cursor) {
1061+ using namespace decls_block ;
1062+
1063+ return skipRecords (Cursor, ASSOCIATED_TYPE);
1064+ }
1065+
1066+ // / Advances past any lazy primary associated type member records.
1067+ static llvm::Error skipPrimaryAssociatedTypeMembers (
1068+ llvm::BitstreamCursor &Cursor) {
1069+ using namespace decls_block ;
1070+
1071+ return skipRecords (Cursor, PRIMARY_ASSOCIATED_TYPE);
1072+ }
1073+
10601074GenericSignature ModuleFile::getGenericSignature (
10611075 serialization::GenericSignatureID ID) {
10621076 auto signature = getGenericSignatureChecked (ID);
@@ -3749,16 +3763,21 @@ class DeclDeserializer {
37493763 proto->setImplicit ();
37503764 proto->setIsObjC (isObjC);
37513765
3752- proto->setLazyRequirementSignature (&MF,
3753- MF.DeclTypeCursor .GetCurrentBitNo ());
3766+ proto->setLazyRequirementSignature (
3767+ &MF, MF.DeclTypeCursor .GetCurrentBitNo ());
37543768 if (llvm::Error Err = skipRequirementSignature (MF.DeclTypeCursor ))
37553769 MF.fatal (std::move (Err));
37563770
3757- proto->setLazyAssociatedTypeMembers (&MF,
3758- MF.DeclTypeCursor .GetCurrentBitNo ());
3771+ proto->setLazyAssociatedTypeMembers (
3772+ &MF, MF.DeclTypeCursor .GetCurrentBitNo ());
37593773 if (llvm::Error Err = skipAssociatedTypeMembers (MF.DeclTypeCursor ))
37603774 MF.fatal (std::move (Err));
37613775
3776+ proto->setLazyPrimaryAssociatedTypeMembers (
3777+ &MF, MF.DeclTypeCursor .GetCurrentBitNo ());
3778+ if (llvm::Error Err = skipPrimaryAssociatedTypeMembers (MF.DeclTypeCursor ))
3779+ MF.fatal (std::move (Err));
3780+
37623781 proto->setMemberLoader (&MF, MF.DeclTypeCursor .GetCurrentBitNo ());
37633782
37643783 return proto;
@@ -6987,6 +7006,14 @@ void ModuleFile::loadAssociatedTypes(const ProtocolDecl *decl,
69877006 readAssociatedTypes (assocTypes, DeclTypeCursor);
69887007}
69897008
7009+ void ModuleFile::loadPrimaryAssociatedTypes (const ProtocolDecl *decl,
7010+ uint64_t contextData,
7011+ SmallVectorImpl<AssociatedTypeDecl *> &assocTypes) {
7012+ BCOffsetRAII restoreOffset (DeclTypeCursor);
7013+ fatalIfNotSuccess (DeclTypeCursor.JumpToBit (contextData));
7014+ readPrimaryAssociatedTypes (assocTypes, DeclTypeCursor);
7015+ }
7016+
69907017static Optional<ForeignErrorConvention::Kind>
69917018decodeRawStableForeignErrorConventionKind (uint8_t kind) {
69927019 switch (kind) {
0 commit comments