Skip to content

Commit c9f3b08

Browse files
committed
[Serialization] Stop using DeclID et al for "the next available ID".
This is effectively fallout from 36a44cf where we switched representations of DeclID and friends, but when I went to add ++ and -- to llvm::PointerEmbeddedInt I realized it wasn't really intended to be mutated in place, i.e. it doesn't make sense to increment a DeclID. Represent counters as plain integers instead that get converted to DeclID when they are first used.
1 parent 473ffe5 commit c9f3b08

File tree

3 files changed

+23
-32
lines changed

3 files changed

+23
-32
lines changed

lib/Serialization/Serialization.cpp

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -268,8 +268,7 @@ DeclID Serializer::addLocalDeclContextRef(const DeclContext *DC) {
268268
if (id != 0)
269269
return id;
270270

271-
LastLocalDeclContextID = LastLocalDeclContextID + 1;
272-
id = LastLocalDeclContextID;
271+
id = ++LastLocalDeclContextID;
273272
LocalDeclContextsToWrite.push(DC);
274273
return id;
275274
}
@@ -294,8 +293,7 @@ DeclContextID Serializer::addDeclContextRef(const DeclContext *DC) {
294293
if (id)
295294
return id;
296295

297-
LastDeclContextID = LastDeclContextID + 1;
298-
id = LastDeclContextID;
296+
id = ++LastDeclContextID;
299297
DeclContextsToWrite.push(DC);
300298

301299
return id;
@@ -327,8 +325,7 @@ DeclID Serializer::addDeclRef(const Decl *D, bool forceSerialization) {
327325
if (paramList)
328326
GenericContexts[paramList] = D;
329327

330-
LastDeclID = LastDeclID + 1;
331-
id = { LastDeclID, forceSerialization };
328+
id = { ++LastDeclID, forceSerialization };
332329
DeclsAndTypesToWrite.push(D);
333330
return id.first;
334331
}
@@ -341,8 +338,7 @@ TypeID Serializer::addTypeRef(Type ty) {
341338
if (id.first != 0)
342339
return id.first;
343340

344-
LastTypeID = LastTypeID + 1;
345-
id = { LastTypeID, true };
341+
id = { ++LastTypeID, true };
346342
DeclsAndTypesToWrite.push(ty);
347343
return id.first;
348344
}
@@ -355,8 +351,7 @@ IdentifierID Serializer::addIdentifierRef(Identifier ident) {
355351
if (id != 0)
356352
return id;
357353

358-
LastIdentifierID = LastIdentifierID + 1;
359-
id = LastIdentifierID;
354+
id = ++LastIdentifierID;
360355
IdentifiersToWrite.push_back(ident);
361356
return id;
362357
}
@@ -385,8 +380,7 @@ NormalConformanceID Serializer::addConformanceRef(
385380
if (conformanceID)
386381
return conformanceID;
387382

388-
LastNormalConformanceID = LastNormalConformanceID + 1;
389-
conformanceID = LastNormalConformanceID;
383+
conformanceID = ++LastNormalConformanceID;
390384
NormalConformancesToWrite.push(conformance);
391385

392386
return conformanceID;

lib/Serialization/Serialization.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -178,25 +178,26 @@ class Serializer {
178178
SmallVector<DeclID, 2> KnownProtocolAdopters[NumKnownProtocols];
179179

180180
/// The last assigned DeclID for decls from this module.
181-
DeclID LastDeclID = 0;
181+
uint32_t /*DeclID*/ LastDeclID = 0;
182182

183183
/// The last assigned DeclContextID for decl contexts from this module.
184-
DeclContextID LastDeclContextID = 0;
184+
uint32_t /*DeclContextID*/ LastDeclContextID = 0;
185185

186186
/// The last assigned DeclContextID for local decl contexts from this module.
187-
DeclContextID LastLocalDeclContextID = 0;
187+
uint32_t /*DeclContextID*/ LastLocalDeclContextID = 0;
188188

189189
/// The last assigned NormalConformanceID for decl contexts from this module.
190-
NormalConformanceID LastNormalConformanceID = 0;
190+
uint32_t /*NormalConformanceID*/ LastNormalConformanceID = 0;
191191

192192
/// The last assigned DeclID for types from this module.
193-
TypeID LastTypeID = 0;
193+
uint32_t /*TypeID*/ LastTypeID = 0;
194194

195195
/// The last assigned IdentifierID for types from this module.
196196
///
197197
/// Note that special module IDs must not be valid IdentifierIDs, except that
198198
/// 0 will always represent the empty identifier.
199-
IdentifierID LastIdentifierID = serialization::NUM_SPECIAL_MODULES - 1;
199+
uint32_t /*IdentifierID*/ LastIdentifierID =
200+
serialization::NUM_SPECIAL_MODULES - 1;
200201

201202
/// Returns the record code for serializing the given vector of offsets.
202203
///

lib/Serialization/SerializeSIL.cpp

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ namespace {
115115
SmallVector<uint64_t, 64> ScratchRecord;
116116

117117
/// In case we want to encode the relative of InstID vs ValueID.
118-
ValueID InstID = 0;
118+
uint32_t /*ValueID*/ InstID = 0;
119119

120120
llvm::DenseMap<const ValueBase*, ValueID> ValueIDs;
121121
ValueID addValueRef(const ValueBase *Val);
@@ -128,25 +128,25 @@ namespace {
128128
Table FuncTable;
129129
std::vector<BitOffset> Funcs;
130130
/// The current function ID.
131-
DeclID FuncID = 1;
131+
uint32_t /*DeclID*/ NextFuncID = 1;
132132

133133
/// Maps class name to a VTable ID.
134134
Table VTableList;
135135
/// Holds the list of VTables.
136136
std::vector<BitOffset> VTableOffset;
137-
DeclID VTableID = 1;
137+
uint32_t /*DeclID*/ NextVTableID = 1;
138138

139139
/// Maps global variable name to an ID.
140140
Table GlobalVarList;
141141
/// Holds the list of SIL global variables.
142142
std::vector<BitOffset> GlobalVarOffset;
143-
DeclID GlobalVarID = 1;
143+
uint32_t /*DeclID*/ NextGlobalVarID = 1;
144144

145145
/// Maps witness table identifier to an ID.
146146
Table WitnessTableList;
147147
/// Holds the list of WitnessTables.
148148
std::vector<BitOffset> WitnessTableOffset;
149-
DeclID WitnessTableID = 1;
149+
uint32_t /*DeclID*/ NextWitnessTableID = 1;
150150

151151
/// Give each SILBasicBlock a unique ID.
152152
llvm::DenseMap<const SILBasicBlock*, unsigned> BasicBlockMap;
@@ -224,8 +224,7 @@ void SILSerializer::writeSILFunction(const SILFunction &F, bool DeclOnly) {
224224
ValueIDs.clear();
225225
InstID = 0;
226226

227-
FuncTable[Ctx.getIdentifier(F.getName())] = FuncID;
228-
FuncID = FuncID + 1;
227+
FuncTable[Ctx.getIdentifier(F.getName())] = NextFuncID++;
229228
Funcs.push_back(Out.GetCurrentBitNo());
230229
unsigned abbrCode = SILAbbrCodes[SILFunctionLayout::Code];
231230
TypeID FnID = S.addTypeRef(F.getLoweredType().getSwiftType());
@@ -1444,7 +1443,7 @@ void SILSerializer::writeSILInstruction(const SILInstruction &SI) {
14441443
// Non-void values get registered in the value table.
14451444
if (SI.hasValue()) {
14461445
addValueRef(&SI);
1447-
InstID = InstID + 1;
1446+
++InstID;
14481447
}
14491448
}
14501449

@@ -1504,8 +1503,7 @@ void SILSerializer::writeIndexTables() {
15041503
}
15051504

15061505
void SILSerializer::writeSILGlobalVar(const SILGlobalVariable &g) {
1507-
GlobalVarList[Ctx.getIdentifier(g.getName())] = GlobalVarID;
1508-
GlobalVarID = GlobalVarID + 1;
1506+
GlobalVarList[Ctx.getIdentifier(g.getName())] = NextGlobalVarID++;
15091507
GlobalVarOffset.push_back(Out.GetCurrentBitNo());
15101508
TypeID TyID = S.addTypeRef(g.getLoweredType().getSwiftType());
15111509
DeclID dID = S.addDeclRef(g.getDecl());
@@ -1518,8 +1516,7 @@ void SILSerializer::writeSILGlobalVar(const SILGlobalVariable &g) {
15181516
}
15191517

15201518
void SILSerializer::writeSILVTable(const SILVTable &vt) {
1521-
VTableList[vt.getClass()->getName()] = VTableID;
1522-
VTableID = VTableID + 1;
1519+
VTableList[vt.getClass()->getName()] = NextVTableID++;
15231520
VTableOffset.push_back(Out.GetCurrentBitNo());
15241521
VTableLayout::emitRecord(Out, ScratchRecord, SILAbbrCodes[VTableLayout::Code],
15251522
S.addDeclRef(vt.getClass()));
@@ -1538,8 +1535,7 @@ void SILSerializer::writeSILVTable(const SILVTable &vt) {
15381535
}
15391536

15401537
void SILSerializer::writeSILWitnessTable(const SILWitnessTable &wt) {
1541-
WitnessTableList[wt.getIdentifier()] = WitnessTableID;
1542-
WitnessTableID = WitnessTableID + 1;
1538+
WitnessTableList[wt.getIdentifier()] = NextWitnessTableID++;
15431539
WitnessTableOffset.push_back(Out.GetCurrentBitNo());
15441540

15451541
WitnessTableLayout::emitRecord(

0 commit comments

Comments
 (0)