Skip to content

Commit 5961b9a

Browse files
committed
[Dependency Scanning] Only reuse serialized scanner caches with matching scanning context hash
1 parent 48387ee commit 5961b9a

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

include/swift/DependencyScan/SerializedModuleDependencyCacheFormat.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ using MetadataLayout = BCRecordLayout<
116116
METADATA, // ID
117117
BCFixed<16>, // Inter-Module Dependency graph format major version
118118
BCFixed<16>, // Inter-Module Dependency graph format minor version
119-
BCBlob // Compiler version string
119+
BCBlob // Scanner Invocation Context Hash
120120
>;
121121

122122
// After the metadata record, we have zero or more identifier records,

lib/DependencyScan/ModuleDependencyCacheSerialization.cpp

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class ModuleDependenciesCacheDeserializer {
5757
// These return true if there was an error.
5858
bool readSignature();
5959
bool enterGraphBlock();
60-
bool readMetadata();
60+
bool readMetadata(StringRef scannerContextHash);
6161
bool readGraph(ModuleDependenciesCache &cache);
6262

6363
std::optional<std::string> getIdentifier(unsigned n);
@@ -143,7 +143,7 @@ bool ModuleDependenciesCacheDeserializer::enterGraphBlock() {
143143

144144
/// Read in the serialized file's format version, error/exit if not matching
145145
/// current version.
146-
bool ModuleDependenciesCacheDeserializer::readMetadata() {
146+
bool ModuleDependenciesCacheDeserializer::readMetadata(StringRef scannerContextHash) {
147147
using namespace graph_block;
148148

149149
auto entry = Cursor.advance();
@@ -165,12 +165,14 @@ bool ModuleDependenciesCacheDeserializer::readMetadata() {
165165
return true;
166166

167167
unsigned majorVersion, minorVersion;
168-
169168
MetadataLayout::readRecord(Scratch, majorVersion, minorVersion);
170169
if (majorVersion != MODULE_DEPENDENCY_CACHE_FORMAT_VERSION_MAJOR ||
171-
minorVersion != MODULE_DEPENDENCY_CACHE_FORMAT_VERSION_MINOR) {
170+
minorVersion != MODULE_DEPENDENCY_CACHE_FORMAT_VERSION_MINOR)
171+
return true;
172+
173+
std::string readScannerContextHash = BlobData.str();
174+
if (readScannerContextHash != scannerContextHash)
172175
return true;
173-
}
174176

175177
return false;
176178
}
@@ -815,7 +817,7 @@ bool ModuleDependenciesCacheDeserializer::readInterModuleDependenciesCache(
815817
if (enterGraphBlock())
816818
return true;
817819

818-
if (readMetadata())
820+
if (readMetadata(cache.scannerContextHash))
819821
return true;
820822

821823
if (readGraph(cache))
@@ -1123,7 +1125,7 @@ class ModuleDependenciesCacheSerializer {
11231125
void writeSignature();
11241126
void writeBlockInfoBlock();
11251127

1126-
void writeMetadata();
1128+
void writeMetadata(StringRef scanningContextHash);
11271129
void writeIdentifiers();
11281130
void writeArraysOfIdentifiers();
11291131

@@ -1210,14 +1212,13 @@ void ModuleDependenciesCacheSerializer::writeSignature() {
12101212
Out.Emit((unsigned)c, 8);
12111213
}
12121214

1213-
void ModuleDependenciesCacheSerializer::writeMetadata() {
1215+
void ModuleDependenciesCacheSerializer::writeMetadata(StringRef scanningContextHash) {
12141216
using namespace graph_block;
1215-
12161217
MetadataLayout::emitRecord(Out, ScratchRecord,
12171218
AbbrCodes[MetadataLayout::Code],
12181219
MODULE_DEPENDENCY_CACHE_FORMAT_VERSION_MAJOR,
12191220
MODULE_DEPENDENCY_CACHE_FORMAT_VERSION_MINOR,
1220-
version::getSwiftFullVersion());
1221+
scanningContextHash);
12211222
}
12221223

12231224
void ModuleDependenciesCacheSerializer::writeIdentifiers() {
@@ -1896,7 +1897,7 @@ void ModuleDependenciesCacheSerializer::writeInterModuleDependenciesCache(
18961897
collectStringsAndArrays(cache);
18971898

18981899
// Write the version information
1899-
writeMetadata();
1900+
writeMetadata(cache.scannerContextHash);
19001901

19011902
// Write the strings
19021903
writeIdentifiers();

0 commit comments

Comments
 (0)