Skip to content

Commit 36cfd10

Browse files
committed
Cosmetic changes
1 parent a9a044c commit 36cfd10

File tree

4 files changed

+27
-12
lines changed

4 files changed

+27
-12
lines changed

include/swift/AST/Module.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -728,6 +728,7 @@ class ModuleDecl : public DeclContext, public TypeDecl {
728728
return ReverseFullNameIterator(this);
729729
}
730730

731+
/// Calls \p callback for each source file of the module.
731732
void collectBasicSourceFileInfo(
732733
llvm::function_ref<void(const BasicSourceFileInfo &)> callback);
733734

lib/Serialization/ModuleFile.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -968,11 +968,15 @@ void ModuleFile::collectBasicSourceFileInfo(
968968
auto *Cursor = Core->SourceFileListData.bytes_begin();
969969
auto *End = Core->SourceFileListData.bytes_end();
970970
while (Cursor < End) {
971+
// FilePath (byte offset in 'SourceLocsTextData').
971972
auto fileID = endian::readNext<uint32_t, little, unaligned>(Cursor);
973+
// InterfaceHash (fixed length string).
972974
auto fpStr = StringRef{reinterpret_cast<const char *>(Cursor),
973975
Fingerprint::DIGEST_LENGTH};
974976
Cursor += Fingerprint::DIGEST_LENGTH;
977+
// LastModified (seconds since epoch).
975978
auto timestamp = endian::readNext<uint64_t, little, unaligned>(Cursor);
979+
// FileSize (num of bytes).
976980
auto fileSize = endian::readNext<uint64_t, little, unaligned>(Cursor);
977981

978982
assert(fileID < Core->SourceLocsTextData.size());

lib/Serialization/SerializeDoc.cpp

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -790,7 +790,7 @@ static void emitFileListRecord(llvm::BitstreamWriter &Out,
790790
struct SourceFileListWriter {
791791
StringWriter &FWriter;
792792

793-
llvm::SmallString<1024> Buffer;
793+
llvm::SmallString<0> Buffer;
794794
llvm::StringSet<> seenFilenames;
795795

796796
void emitSourceFileInfo(const BasicSourceFileInfo &info) {
@@ -803,29 +803,39 @@ static void emitFileListRecord(llvm::BitstreamWriter &Out,
803803
return;
804804

805805
auto fileID = FWriter.getTextOffset(absolutePath);
806-
auto timestamp = std::chrono::duration_cast<std::chrono::seconds>(info.LastModified.time_since_epoch()).count();
806+
auto fingerprintStr = info.InterfaceHash.getRawValue();
807+
auto timestamp = std::chrono::duration_cast<std::chrono::seconds>(
808+
info.LastModified.time_since_epoch())
809+
.count();
807810

808811
llvm::raw_svector_ostream out(Buffer);
809812
endian::Writer writer(out, little);
813+
// FilePath.
810814
writer.write<uint32_t>(fileID);
811-
out << info.InterfaceHash.getRawValue();
815+
// InterfaceHash (fixed length string).
816+
assert(fingerprintStr.size() == Fingerprint::DIGEST_LENGTH);
817+
out << fingerprintStr;
818+
// LastModified.
812819
writer.write<uint64_t>(timestamp);
820+
// FileSize.
813821
writer.write<uint64_t>(info.FileSize);
814822
}
815823

816-
SourceFileListWriter(StringWriter &FWriter) : FWriter(FWriter) {}
824+
SourceFileListWriter(StringWriter &FWriter) : FWriter(FWriter) {
825+
Buffer.reserve(1024);
826+
}
817827
} writer(FWriter);
818828

819829
if (SourceFile *SF = MSF.dyn_cast<SourceFile *>()) {
820830
BasicSourceFileInfo info;
821-
SmallString<128> stash;
822831
if (info.populate(SF))
823832
return;
824833
writer.emitSourceFileInfo(info);
825834
} else {
826835
auto *M = MSF.get<ModuleDecl *>();
827-
M->collectBasicSourceFileInfo(
828-
[&](const BasicSourceFileInfo &info) { writer.emitSourceFileInfo(info); });
836+
M->collectBasicSourceFileInfo([&](const BasicSourceFileInfo &info) {
837+
writer.emitSourceFileInfo(info);
838+
});
829839
}
830840

831841
const decl_locs_block::SourceFileListLayout FileList(Out);

lib/Serialization/SourceInfoFormat.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,16 +75,16 @@ namespace decl_locs_block {
7575
SOURCE_FILE_LIST,
7676
};
7777

78+
using SourceFileListLayout = BCRecordLayout<
79+
SOURCE_FILE_LIST, // record ID
80+
BCBlob // An array of fixed size 'BasicSourceFileInfo' data.
81+
>;
82+
7883
using BasicDeclLocsLayout = BCRecordLayout<
7984
BASIC_DECL_LOCS, // record ID
8085
BCBlob // an array of fixed size location data
8186
>;
8287

83-
using SourceFileListLayout = BCRecordLayout<
84-
SOURCE_FILE_LIST, // record ID
85-
BCBlob // An array of string offsets in TextDataLayout
86-
>;
87-
8888
using DeclUSRSLayout = BCRecordLayout<
8989
DECL_USRS, // record ID
9090
BCVBR<16>, // table offset within the blob (an llvm::OnDiskHashTable)

0 commit comments

Comments
 (0)