Skip to content

Commit 0fcbe72

Browse files
jrose-appleDavide Italiano
authored andcommitted
[Serialization] Remove the last use of Identifiers for SIL names
The string-keyed tables don't actually need Identifier keys on the serialization side -- no reason to persist these in the ASTContext's string table either.
1 parent e082901 commit 0fcbe72

File tree

8 files changed

+37
-31
lines changed

8 files changed

+37
-31
lines changed

include/swift/SIL/SILDefaultWitnessTable.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,11 @@ class SILDefaultWitnessTable : public llvm::ilist_node<SILDefaultWitnessTable>,
119119
const ProtocolDecl *Protocol,
120120
ArrayRef<Entry> entries);
121121

122-
Identifier getIdentifier() const;
122+
/// Get a name that uniquely identifies this default witness table.
123+
///
124+
/// Note that this is /not/ valid as a symbol name; it is only guaranteed to
125+
/// be unique among default witness tables, not all symbols.
126+
std::string getUniqueName() const;
123127

124128
/// Get the linkage of the default witness table.
125129
SILLinkage getLinkage() const { return Linkage; }

include/swift/SIL/SILWitnessTable.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -226,10 +226,6 @@ class SILWitnessTable : public llvm::ilist_node<SILWitnessTable>,
226226
/// object file level.
227227
StringRef getName() const { return Name; }
228228

229-
/// Return the symbol name of the witness table that will be propagated to the
230-
/// object file as an Identifier.
231-
Identifier getIdentifier() const;
232-
233229
/// Returns true if this witness table is a declaration.
234230
bool isDeclaration() const { return IsDeclaration; }
235231

lib/SIL/SILDefaultWitnessTable.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,9 @@ convertToDefinition(ArrayRef<Entry> entries) {
9595
}
9696
}
9797

98-
Identifier SILDefaultWitnessTable::getIdentifier() const {
98+
std::string SILDefaultWitnessTable::getUniqueName() const {
9999
Mangle::ASTMangler Mangler;
100-
std::string name = Mangler.mangleTypeAsUSR(getProtocol()->getDeclaredType());
101-
return Mod.getASTContext().getIdentifier(name);
100+
return Mangler.mangleTypeAsUSR(getProtocol()->getDeclaredType());
102101
}
103102

104103
SILDefaultWitnessTable::~SILDefaultWitnessTable() {

lib/SIL/SILWitnessTable.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,6 @@ void SILWitnessTable::convertToDefinition(
151151
}
152152
}
153153

154-
Identifier SILWitnessTable::getIdentifier() const {
155-
return Mod.getASTContext().getIdentifier(Name);
156-
}
157-
158154
bool SILWitnessTable::conformanceIsSerialized(ProtocolConformance *conformance) {
159155
// Serialize witness tables for conformances synthesized by
160156
// the ClangImporter.

lib/Serialization/DeserializeSIL.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3130,7 +3130,7 @@ SILDeserializer::lookupDefaultWitnessTable(SILDefaultWitnessTable *existingWt) {
31303130

31313131
// Use the mangled name of the protocol to lookup the partially
31323132
// deserialized value from the default witness table list.
3133-
auto iter = DefaultWitnessTableList->find(existingWt->getIdentifier().str());
3133+
auto iter = DefaultWitnessTableList->find(existingWt->getUniqueName());
31343134
if (iter == DefaultWitnessTableList->end())
31353135
return nullptr;
31363136

lib/Serialization/Serialization.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -703,21 +703,22 @@ IdentifierID Serializer::addDeclBaseNameRef(DeclBaseName ident) {
703703
}
704704
}
705705

706-
IdentifierID Serializer::addUniquedStringRef(StringRef str) {
706+
std::pair<StringRef, IdentifierID> Serializer::addUniquedString(StringRef str) {
707707
if (str.empty())
708-
return 0;
708+
return {str, 0};
709709

710710
decltype(UniquedStringIDs)::iterator iter;
711711
bool isNew;
712712
std::tie(iter, isNew) =
713713
UniquedStringIDs.insert({str, LastUniquedStringID + 1});
714714

715715
if (!isNew)
716-
return iter->getValue();
716+
return {iter->getKey(), iter->getValue()};
717717

718+
++LastUniquedStringID;
718719
// Note that we use the string data stored in the StringMap.
719720
StringsToWrite.push_back(iter->getKey());
720-
return ++LastUniquedStringID;
721+
return {iter->getKey(), LastUniquedStringID};
721722
}
722723

723724
IdentifierID Serializer::addModuleRef(const ModuleDecl *M) {

lib/Serialization/Serialization.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,11 +464,22 @@ class Serializer {
464464
/// \returns The ID for the given DeclBaseName in this module.
465465
IdentifierID addDeclBaseNameRef(DeclBaseName ident);
466466

467+
/// Records the use of the given string, which will only be stored once in
468+
/// the resulting module file.
469+
///
470+
/// \returns A pair containing the copy of the string now owned by the
471+
/// Serializer and the ID for the string in this module.
472+
/// \sa addUniquedStringRef
473+
std::pair<StringRef, IdentifierID> addUniquedString(StringRef str);
474+
467475
/// Records the use of the given string, which will only be stored once in
468476
/// the resulting module file.
469477
///
470478
/// \returns The ID for the given string in this module.
471-
IdentifierID addUniquedStringRef(StringRef str);
479+
/// \sa addUniquedString
480+
IdentifierID addUniquedStringRef(StringRef str) {
481+
return addUniquedString(str).second;
482+
}
472483

473484
/// Records the use of the given Decl.
474485
///

lib/Serialization/SerializeSIL.cpp

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ namespace {
9595
Serializer &S;
9696

9797
public:
98-
using key_type = Identifier;
98+
using key_type = StringRef;
9999
using key_type_ref = key_type;
100100
using data_type = DeclID;
101101
using data_type_ref = const data_type &;
@@ -107,7 +107,7 @@ namespace {
107107
hash_value_type ComputeHash(key_type_ref key) {
108108
assert(!key.empty());
109109
// FIXME: DJB seed=0, audit whether the default seed could be used.
110-
return llvm::djbHash(key.str(), 0);
110+
return llvm::djbHash(key, 0);
111111
}
112112

113113
std::pair<unsigned, unsigned> EmitKeyDataLength(raw_ostream &out,
@@ -117,7 +117,7 @@ namespace {
117117
}
118118

119119
void EmitKey(raw_ostream &out, key_type_ref key, unsigned len) {
120-
uint32_t keyID = S.addUniquedStringRef(key.str());
120+
uint32_t keyID = S.addUniquedStringRef(key);
121121
endian::write<uint32_t>(out, keyID, little);
122122
}
123123

@@ -131,7 +131,6 @@ namespace {
131131
using TypeID = serialization::TypeID;
132132

133133
Serializer &S;
134-
ASTContext &Ctx;
135134

136135
llvm::BitstreamWriter &Out;
137136

@@ -259,9 +258,8 @@ namespace {
259258
IdentifierID addSILFunctionRef(SILFunction *F);
260259

261260
public:
262-
SILSerializer(Serializer &S, ASTContext &Ctx,
263-
llvm::BitstreamWriter &Out, bool serializeAll)
264-
: S(S), Ctx(Ctx), Out(Out), ShouldSerializeAll(serializeAll) {}
261+
SILSerializer(Serializer &S, llvm::BitstreamWriter &Out, bool serializeAll)
262+
: S(S), Out(Out), ShouldSerializeAll(serializeAll) {}
265263

266264
void writeSILModule(const SILModule *SILMod);
267265
};
@@ -349,7 +347,7 @@ void SILSerializer::writeSILFunction(const SILFunction &F, bool DeclOnly) {
349347
ValueIDs.clear();
350348
InstID = 0;
351349

352-
FuncTable[Ctx.getIdentifier(F.getName())] = NextFuncID++;
350+
FuncTable[F.getName()] = NextFuncID++;
353351
Funcs.push_back(Out.GetCurrentBitNo());
354352
unsigned abbrCode = SILAbbrCodes[SILFunctionLayout::Code];
355353
TypeID FnID = S.addTypeRef(F.getLoweredType().getASTType());
@@ -2133,7 +2131,7 @@ void SILSerializer::writeIndexTables() {
21332131
}
21342132

21352133
void SILSerializer::writeSILGlobalVar(const SILGlobalVariable &g) {
2136-
GlobalVarList[Ctx.getIdentifier(g.getName())] = NextGlobalVarID++;
2134+
GlobalVarList[g.getName()] = NextGlobalVarID++;
21372135
GlobalVarOffset.push_back(Out.GetCurrentBitNo());
21382136
TypeID TyID = S.addTypeRef(g.getLoweredType().getASTType());
21392137
DeclID dID = S.addDeclRef(g.getDecl());
@@ -2152,7 +2150,7 @@ void SILSerializer::writeSILVTable(const SILVTable &vt) {
21522150
if (!ShouldSerializeAll &&
21532151
vt.getClass()->getEffectiveAccess() < swift::AccessLevel::Public)
21542152
return;
2155-
VTableList[vt.getClass()->getName()] = NextVTableID++;
2153+
VTableList[vt.getClass()->getName().str()] = NextVTableID++;
21562154
VTableOffset.push_back(Out.GetCurrentBitNo());
21572155
VTableLayout::emitRecord(Out, ScratchRecord, SILAbbrCodes[VTableLayout::Code],
21582156
S.addDeclRef(vt.getClass()),
@@ -2204,7 +2202,7 @@ void SILSerializer::writeSILProperty(const SILProperty &prop) {
22042202
}
22052203

22062204
void SILSerializer::writeSILWitnessTable(const SILWitnessTable &wt) {
2207-
WitnessTableList[wt.getIdentifier()] = NextWitnessTableID++;
2205+
WitnessTableList[wt.getName()] = NextWitnessTableID++;
22082206
WitnessTableOffset.push_back(Out.GetCurrentBitNo());
22092207

22102208
WitnessTableLayout::emitRecord(
@@ -2282,7 +2280,8 @@ writeSILDefaultWitnessTable(const SILDefaultWitnessTable &wt) {
22822280
if (wt.isDeclaration())
22832281
return;
22842282

2285-
DefaultWitnessTableList[wt.getIdentifier()] = NextDefaultWitnessTableID++;
2283+
StringRef name = S.addUniquedString(wt.getUniqueName()).first;
2284+
DefaultWitnessTableList[name] = NextDefaultWitnessTableID++;
22862285
DefaultWitnessTableOffset.push_back(Out.GetCurrentBitNo());
22872286

22882287
DefaultWitnessTableLayout::emitRecord(
@@ -2482,6 +2481,6 @@ void Serializer::writeSIL(const SILModule *SILMod, bool serializeAllSIL) {
24822481
if (!SILMod)
24832482
return;
24842483

2485-
SILSerializer SILSer(*this, M->getASTContext(), Out, serializeAllSIL);
2484+
SILSerializer SILSer(*this, Out, serializeAllSIL);
24862485
SILSer.writeSILModule(SILMod);
24872486
}

0 commit comments

Comments
 (0)