Skip to content

Commit 5c092e7

Browse files
committed
SerializeLoc: use decl_locs_block consistently. NFC
1 parent 29ab49f commit 5c092e7

File tree

3 files changed

+18
-13
lines changed

3 files changed

+18
-13
lines changed

lib/Serialization/ModuleFile.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1293,13 +1293,13 @@ bool ModuleFile::readDeclLocsBlock(llvm::BitstreamCursor &cursor) {
12931293
unsigned kind = cursor.readRecord(entry.ID, scratch, &blobData);
12941294

12951295
switch (kind) {
1296-
case sourceinfo_block::BASIC_DECL_LOCS:
1296+
case decl_locs_block::BASIC_DECL_LOCS:
12971297
BasicDeclLocsData = blobData;
12981298
break;
1299-
case sourceinfo_block::TEXT_DATA:
1299+
case decl_locs_block::TEXT_DATA:
13001300
SourceLocsTextData = blobData;
13011301
break;
1302-
case sourceinfo_block::DECL_USRS:
1302+
case decl_locs_block::DECL_USRS:
13031303
DeclUSRsTable = readDeclUSRsTable(scratch, blobData);
13041304
break;
13051305
default:

lib/Serialization/SerializeDoc.cpp

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ class DeclUSRsTableWriter {
565565
return None;
566566
}
567567
void emitUSRsRecord(llvm::BitstreamWriter &out) {
568-
sourceinfo_block::DeclUSRSLayout USRsList(out);
568+
decl_locs_block::DeclUSRSLayout USRsList(out);
569569
SmallVector<uint64_t, 8> scratch;
570570
llvm::SmallString<32> hashTableBlob;
571571
uint32_t tableOffset;
@@ -593,7 +593,7 @@ class StringWriter {
593593
}
594594

595595
void emitSourceFilesRecord(llvm::BitstreamWriter &Out) {
596-
sourceinfo_block::TextDataLayout TextBlob(Out);
596+
decl_locs_block::TextDataLayout TextBlob(Out);
597597
SmallVector<uint64_t, 8> scratch;
598598
TextBlob.emit(scratch, Buffer);
599599
}
@@ -625,7 +625,7 @@ writer.write<uint32_t>(data.X.Column);
625625
#undef WRITE_LINE_COLUMN
626626
}
627627

628-
Optional<uint32_t> calculateUSRId(Decl *D) {
628+
Optional<uint32_t> calculateNewUSRId(Decl *D) {
629629
llvm::SmallString<512> Buffer;
630630
llvm::raw_svector_ostream OS(Buffer);
631631
if (ide::printDeclUSR(D, OS))
@@ -698,10 +698,15 @@ Result.X.Column = Locs->X.Column;
698698
return false;
699699
if (!shouldSerializeSourceLoc(D))
700700
return true;
701-
auto USR = calculateUSRId(D);
701+
// If we cannot get loc data for D, don't proceed.
702702
auto LocData = getLocData(D);
703-
if (!USR.hasValue() || !LocData.hasValue())
703+
if (!LocData.hasValue())
704704
return true;
705+
// If we have handled this USR before, don't proceed.
706+
auto USR = calculateNewUSRId(D);
707+
if (!USR.hasValue())
708+
return true;
709+
// OK, we get a new USR, now append the associated source location data.
705710
assert(*USR * sizeof(DeclLocationsTableData) == Buffer.size() &&
706711
"USR id is used as an index to access basic location array");
707712
appendToBuffer(*LocData);
@@ -713,7 +718,7 @@ static void emitBasicLocsRecord(llvm::BitstreamWriter &Out,
713718
ModuleOrSourceFile MSF, DeclUSRsTableWriter &USRWriter,
714719
StringWriter &FWriter) {
715720
assert(MSF);
716-
const sourceinfo_block::BasicDeclLocsLayout DeclLocsList(Out);
721+
const decl_locs_block::BasicDeclLocsLayout DeclLocsList(Out);
717722
BasicDeclLocsTableWriter Writer(USRWriter, FWriter);
718723
if (auto *SF = MSF.dyn_cast<SourceFile*>()) {
719724
SF->walk(Writer);
@@ -749,9 +754,9 @@ class SourceInfoSerializer : public SerializerBase {
749754
BLOCK_RECORD(control_block, TARGET);
750755

751756
BLOCK(DECL_LOCS_BLOCK);
752-
BLOCK_RECORD(sourceinfo_block, BASIC_DECL_LOCS);
753-
BLOCK_RECORD(sourceinfo_block, DECL_USRS);
754-
BLOCK_RECORD(sourceinfo_block, TEXT_DATA);
757+
BLOCK_RECORD(decl_locs_block, BASIC_DECL_LOCS);
758+
BLOCK_RECORD(decl_locs_block, DECL_USRS);
759+
BLOCK_RECORD(decl_locs_block, TEXT_DATA);
755760

756761
#undef BLOCK
757762
#undef BLOCK_RECORD

lib/Serialization/SourceInfoFormat.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ const uint32_t SWIFTSOURCEINFO_HASH_SEED = 5387;
6363
/// to make backwards-compatible changes using the LLVM bitcode format.
6464
///
6565
/// \sa DECL_LOCS_BLOCK_ID
66-
namespace sourceinfo_block {
66+
namespace decl_locs_block {
6767
enum RecordKind {
6868
BASIC_DECL_LOCS = 1,
6969
DECL_USRS,

0 commit comments

Comments
 (0)