Skip to content

Commit f230abf

Browse files
authored
[Serialization] Remove unused "force non-cross-reference" feature (#17686)
This was originally added to support "derived" top-level declarations, which in practice was just '==' implementations for enums. Now that those are members, we don't have the notion of derived top-level declarations anymore, and neither is there anything that would normally be a cross-reference that we want to force to be serialized directly. No functionality change (because this was unused).
1 parent 01dea28 commit f230abf

File tree

2 files changed

+17
-43
lines changed

2 files changed

+17
-43
lines changed

lib/Serialization/Serialization.cpp

Lines changed: 15 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -618,17 +618,13 @@ DeclContextID Serializer::addDeclContextRef(const DeclContext *DC) {
618618
return id;
619619
}
620620

621-
DeclID Serializer::addDeclRef(const Decl *D, bool forceSerialization,
622-
bool allowTypeAliasXRef) {
621+
DeclID Serializer::addDeclRef(const Decl *D, bool allowTypeAliasXRef) {
623622
if (!D)
624623
return 0;
625624

626-
DeclIDAndForce &id = DeclAndTypeIDs[D];
627-
if (id.first != 0) {
628-
if (forceSerialization && !id.second)
629-
id.second = true;
630-
return id.first;
631-
}
625+
DeclID &id = DeclAndTypeIDs[D];
626+
if (id != 0)
627+
return id;
632628

633629
assert((!isDeclXRef(D) || isa<ValueDecl>(D) || isa<OperatorDecl>(D) ||
634630
isa<PrecedenceGroupDecl>(D)) &&
@@ -642,9 +638,9 @@ DeclID Serializer::addDeclRef(const Decl *D, bool forceSerialization,
642638
D->getModuleContext() == M) &&
643639
"cannot cross-reference typealiases directly (use the NameAliasType)");
644640

645-
id = { ++LastDeclID, forceSerialization };
641+
id = ++LastDeclID;
646642
DeclsAndTypesToWrite.push(D);
647-
return id.first;
643+
return id;
648644
}
649645

650646
serialization::TypeID Serializer::addTypeRef(Type ty) {
@@ -657,12 +653,12 @@ serialization::TypeID Serializer::addTypeRef(Type ty) {
657653
#endif
658654

659655
auto &id = DeclAndTypeIDs[ty];
660-
if (id.first != 0)
661-
return id.first;
656+
if (id != 0)
657+
return id;
662658

663-
id = { ++LastTypeID, true };
659+
id = ++LastTypeID;
664660
DeclsAndTypesToWrite.push(ty);
665-
return id.first;
661+
return id;
666662
}
667663

668664
IdentifierID Serializer::addDeclBaseNameRef(DeclBaseName ident) {
@@ -1577,8 +1573,7 @@ void Serializer::writeNormalConformance(
15771573
Type type, TypeDecl *typeDecl) {
15781574
data.push_back(addDeclRef(assocType));
15791575
data.push_back(addTypeRef(type));
1580-
data.push_back(addDeclRef(typeDecl, /*forceSerialization*/false,
1581-
/*allowTypeAliasXRef*/true));
1576+
data.push_back(addDeclRef(typeDecl, /*allowTypeAliasXRef*/true));
15821577
++numTypeWitnesses;
15831578
return false;
15841579
});
@@ -2171,18 +2166,6 @@ DEF_VERIFY_ATTR(Destructor)
21712166
static void verifyAttrSerializable(const Decl *D) {}
21722167
#endif
21732168

2174-
static bool isForced(const Decl *D,
2175-
const llvm::DenseMap<Serializer::DeclTypeUnion,
2176-
Serializer::DeclIDAndForce> &table) {
2177-
if (table.lookup(D).second)
2178-
return true;
2179-
for (const DeclContext *DC = D->getDeclContext(); !DC->isModuleScopeContext();
2180-
DC = DC->getParent())
2181-
if (table.lookup(getDeclForContext(DC)).second)
2182-
return true;
2183-
return false;
2184-
}
2185-
21862169
static inline unsigned getOptionalOrZero(const llvm::Optional<unsigned> &X) {
21872170
if (X.hasValue())
21882171
return X.getValue();
@@ -2379,7 +2362,7 @@ bool Serializer::isDeclXRef(const Decl *D) const {
23792362
assert(isa<GenericTypeParamDecl>(D) && "unexpected decl kind");
23802363
return false;
23812364
}
2382-
return !isForced(D, DeclAndTypeIDs);
2365+
return true;
23832366
}
23842367

23852368
void Serializer::writeDeclContext(const DeclContext *DC) {
@@ -2639,7 +2622,7 @@ void Serializer::writeDecl(const Decl *D) {
26392622

26402623
PrettyStackTraceDecl trace("serializing", D);
26412624

2642-
auto id = DeclAndTypeIDs[D].first;
2625+
auto id = DeclAndTypeIDs[D];
26432626
assert(id != 0 && "decl or type not referenced properly");
26442627
(void)id;
26452628

@@ -3607,7 +3590,7 @@ static TypeAliasDecl *findTypeAliasForBuiltin(ASTContext &Ctx, Type T) {
36073590
void Serializer::writeType(Type ty) {
36083591
using namespace decls_block;
36093592

3610-
auto id = DeclAndTypeIDs[ty].first;
3593+
auto id = DeclAndTypeIDs[ty];
36113594
assert(id != 0 && "type not referenced properly");
36123595
(void)id;
36133596

@@ -3635,7 +3618,6 @@ void Serializer::writeType(Type ty) {
36353618
unsigned abbrCode = DeclTypeAbbrCodes[BuiltinAliasTypeLayout::Code];
36363619
BuiltinAliasTypeLayout::emitRecord(Out, ScratchRecord, abbrCode,
36373620
addDeclRef(typeAlias,
3638-
/*forceSerialization*/false,
36393621
/*allowTypeAliasXRef*/true),
36403622
TypeID());
36413623
break;
@@ -3647,9 +3629,7 @@ void Serializer::writeType(Type ty) {
36473629
unsigned abbrCode = DeclTypeAbbrCodes[NameAliasTypeLayout::Code];
36483630
NameAliasTypeLayout::emitRecord(
36493631
Out, ScratchRecord, abbrCode,
3650-
addDeclRef(typeAlias,
3651-
/*forceSerialization*/false,
3652-
/*allowTypeAliasXRef*/true),
3632+
addDeclRef(typeAlias, /*allowTypeAliasXRef*/true),
36533633
addTypeRef(alias->getParent()),
36543634
addTypeRef(alias->getSinglyDesugaredType()),
36553635
addSubstitutionMapRef(alias->getSubstitutionMap()));
@@ -3968,7 +3948,6 @@ void Serializer::writeType(Type ty) {
39683948
unsigned abbrCode = DeclTypeAbbrCodes[UnboundGenericTypeLayout::Code];
39693949
UnboundGenericTypeLayout::emitRecord(Out, ScratchRecord, abbrCode,
39703950
addDeclRef(generic->getDecl(),
3971-
/*forceSerialization*/false,
39723951
/*allowTypeAliasXRef*/true),
39733952
addTypeRef(generic->getParent()));
39743953
break;

lib/Serialization/Serialization.h

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,9 @@ class Serializer {
8383
}
8484
};
8585

86-
// FIXME: This should be a PointerIntPair, but there's a bug in
87-
// PointerIntPair when the number of free bits is greater than 32.
88-
using DeclIDAndForce = std::pair<DeclID, bool>;
89-
9086
private:
9187
/// A map from Types and Decls to their serialized IDs.
92-
llvm::DenseMap<DeclTypeUnion, DeclIDAndForce> DeclAndTypeIDs;
88+
llvm::DenseMap<DeclTypeUnion, DeclID> DeclAndTypeIDs;
9389

9490
/// A map from Identifiers to their serialized IDs.
9591
llvm::DenseMap<Identifier, IdentifierID> IdentifierIDs;
@@ -462,8 +458,7 @@ class Serializer {
462458
/// The Decl will be scheduled for serialization if necessary.
463459
///
464460
/// \returns The ID for the given Decl in this module.
465-
DeclID addDeclRef(const Decl *D, bool forceSerialization = false,
466-
bool allowTypeAliasXRef = false);
461+
DeclID addDeclRef(const Decl *D, bool allowTypeAliasXRef = false);
467462

468463
/// Records the use of the given DeclContext.
469464
///

0 commit comments

Comments
 (0)