Skip to content

Commit e469d97

Browse files
Harlan Haskinsjrose-apple
authored andcommitted
[ModuleInterface] Error for out-of-date modules in the resource-dir (#24139)
If we're loading a .swiftmodule from the resource dir adjacent to the compiler, defer to the serialized loader instead of falling back. This is mainly to support development of Swift, where one might change the module format version but forget to recompile the standard library. If that happens, don't fall back and silently recompile the standard library -- instead, error like we used to. rdar://49926152 (cherry picked from commit 24c35f3)
1 parent f1d5154 commit e469d97

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

lib/Frontend/ParseableInterfaceModuleLoader.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -845,6 +845,12 @@ class ParseableInterfaceModuleLoaderImpl {
845845
return scratch.str();
846846
}
847847

848+
bool isInResourceDir(StringRef path) {
849+
StringRef resourceDir = ctx.SearchPathOpts.RuntimeLibraryPath;
850+
if (resourceDir.empty()) return false;
851+
return path.startswith(resourceDir);
852+
}
853+
848854
/// Finds the most appropriate .swiftmodule, whose dependencies are up to
849855
/// date, that we can load for the provided .swiftinterface file.
850856
llvm::ErrorOr<DiscoveredModule> discoverUpToDateModuleForInterface(
@@ -950,6 +956,21 @@ class ParseableInterfaceModuleLoaderImpl {
950956
<< modulePath
951957
<< "; deferring to serialized module loader\n");
952958
return std::make_error_code(std::errc::not_supported);
959+
} else if (isInResourceDir(modulePath) &&
960+
loadMode == ModuleLoadingMode::PreferSerialized) {
961+
// Special-case here: If we're loading a .swiftmodule from the resource
962+
// dir adjacent to the compiler, defer to the serialized loader instead
963+
// of falling back. This is mainly to support development of Swift,
964+
// where one might change the module format version but forget to
965+
// recompile the standard library. If that happens, don't fall back
966+
// and silently recompile the standard library -- instead, error like
967+
// we used to.
968+
LLVM_DEBUG(llvm::dbgs() << "Found out-of-date module in the "
969+
"resource-dir at "
970+
<< modulePath
971+
<< "; deferring to serialized module loader "
972+
"to diagnose\n");
973+
return std::make_error_code(std::errc::not_supported);
953974
} else {
954975
LLVM_DEBUG(llvm::dbgs() << "Found out-of-date module at "
955976
<< modulePath << "\n");

0 commit comments

Comments
 (0)