Skip to content

Commit 24c35f3

Browse files
author
Harlan Haskins
authored
[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
1 parent bd1ce98 commit 24c35f3

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
@@ -839,6 +839,12 @@ class ParseableInterfaceModuleLoaderImpl {
839839
return scratch.str();
840840
}
841841

842+
bool isInResourceDir(StringRef path) {
843+
StringRef resourceDir = ctx.SearchPathOpts.RuntimeLibraryPath;
844+
if (resourceDir.empty()) return false;
845+
return path.startswith(resourceDir);
846+
}
847+
842848
/// Finds the most appropriate .swiftmodule, whose dependencies are up to
843849
/// date, that we can load for the provided .swiftinterface file.
844850
llvm::ErrorOr<DiscoveredModule> discoverUpToDateModuleForInterface(
@@ -944,6 +950,21 @@ class ParseableInterfaceModuleLoaderImpl {
944950
<< modulePath
945951
<< "; deferring to serialized module loader\n");
946952
return std::make_error_code(std::errc::not_supported);
953+
} else if (isInResourceDir(modulePath) &&
954+
loadMode == ModuleLoadingMode::PreferSerialized) {
955+
// Special-case here: If we're loading a .swiftmodule from the resource
956+
// dir adjacent to the compiler, defer to the serialized loader instead
957+
// of falling back. This is mainly to support development of Swift,
958+
// where one might change the module format version but forget to
959+
// recompile the standard library. If that happens, don't fall back
960+
// and silently recompile the standard library -- instead, error like
961+
// we used to.
962+
LLVM_DEBUG(llvm::dbgs() << "Found out-of-date module in the "
963+
"resource-dir at "
964+
<< modulePath
965+
<< "; deferring to serialized module loader "
966+
"to diagnose\n");
967+
return std::make_error_code(std::errc::not_supported);
947968
} else {
948969
LLVM_DEBUG(llvm::dbgs() << "Found out-of-date module at "
949970
<< modulePath << "\n");

0 commit comments

Comments
 (0)