Skip to content

Commit b6cf719

Browse files
author
Harlan Haskins
committed
[ModuleInterfaces] Add adjacent swiftmodule to dependencies
If there’s a `.swiftmodule` corresponding to the `.swiftinterface` we’re loading, but it’s out of date or otherwise unusable, still make it a dependency of the cached module. The general assumption with cached modules is that, by virtue of them being in the cache, they have a more up-to-date view of the world than the adjacent compiled module. However, if a new `.swiftmodule` comes along that’s totally valid, we should consider it as having a newer view of the world than the cached one, so we should use it instead. Fixes rdar://51959788
1 parent 33df36d commit b6cf719

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

lib/Frontend/ParseableInterfaceModuleLoader.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@ class swift::ParseableInterfaceBuilder {
284284
const SourceLoc diagnosticLoc;
285285
DependencyTracker *const dependencyTracker;
286286
CompilerInvocation subInvocation;
287+
SmallVector<StringRef, 3> extraDependencies;
287288

288289
void configureSubInvocationInputsAndOutputs(StringRef OutPath) {
289290
auto &SubFEOpts = subInvocation.getFrontendOptions();
@@ -397,6 +398,8 @@ class swift::ParseableInterfaceBuilder {
397398
auto DTDeps = SubInstance.getDependencyTracker()->getDependencies();
398399
SmallVector<StringRef, 16> InitialDepNames(DTDeps.begin(), DTDeps.end());
399400
InitialDepNames.push_back(interfacePath);
401+
InitialDepNames.insert(InitialDepNames.end(),
402+
extraDependencies.begin(), extraDependencies.end());
400403
llvm::StringSet<> AllDepNames;
401404
SmallString<128> Scratch;
402405

@@ -487,6 +490,12 @@ class swift::ParseableInterfaceBuilder {
487490
return subInvocation;
488491
}
489492

493+
/// Ensures the requested file name is added as a dependency of the resulting
494+
/// module.
495+
void addExtraDependency(StringRef path) {
496+
extraDependencies.push_back(path);
497+
}
498+
490499
bool buildSwiftModule(StringRef OutPath, bool ShouldSerializeDeps,
491500
std::unique_ptr<llvm::MemoryBuffer> *ModuleBuffer) {
492501
bool SubError = false;
@@ -672,6 +681,15 @@ struct ModuleRebuildInfo {
672681
.missingDependencies.push_back(depPath);
673682
}
674683

684+
/// Determines if we saw the given module path and registered is as out of
685+
/// date.
686+
bool sawOutOfDateModule(StringRef modulePath) {
687+
for (auto &mod : outOfDateModules)
688+
if (mod.path == modulePath)
689+
return true;
690+
return false;
691+
}
692+
675693
const char *invalidModuleReason(serialization::Status status) {
676694
using namespace serialization;
677695
switch (status) {
@@ -1319,6 +1337,14 @@ class ParseableInterfaceModuleLoaderImpl {
13191337
interfacePath);
13201338
}
13211339

1340+
// If we found an out-of-date .swiftmodule, we still want to add it as
1341+
// a dependency of the .swiftinterface. That way if it's updated, but
1342+
// the .swiftinterface remains the same, we invalidate the cache and
1343+
// check the new .swiftmodule, because it likely has more information
1344+
// about the state of the world.
1345+
if (rebuildInfo.sawOutOfDateModule(modulePath))
1346+
builder.addExtraDependency(modulePath);
1347+
13221348
if (builder.buildSwiftModule(cachedOutputPath, /*shouldSerializeDeps*/true,
13231349
&moduleBuffer))
13241350
return std::make_error_code(std::errc::invalid_argument);

0 commit comments

Comments
 (0)