[Serialization] Allow rebuilding modules from the resource dir on SDK mismatch

Modules loaded from the resource dir are not usually rebuilt from the
swiftinterface as it would indicate a configuration problem. Lift that
behavior for SDK mismatch and still rebuild them.

This use case applies when a toolchain is used with a different SDK than
the one use to build the modules in the toolchain.

rdar://106101760
This commit is contained in:
Alexis Laferrière
2023-03-06 09:48:38 -08:00
parent 1b86261a74
commit 109e93cb88
2 changed files with 19 additions and 1 deletions

View File

@@ -790,7 +790,9 @@ class ModuleInterfaceLoaderImpl {
UsableModulePath = adjacentMod;
return std::make_error_code(std::errc::not_supported);
} else if (isInResourceDir(adjacentMod) &&
loadMode == ModuleLoadingMode::PreferSerialized) {
loadMode == ModuleLoadingMode::PreferSerialized &&
rebuildInfo.getOrInsertCandidateModule(adjacentMod).serializationStatus !=
serialization::Status::SDKMismatch) {
// Special-case here: 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,
@@ -798,6 +800,8 @@ class ModuleInterfaceLoaderImpl {
// recompile the standard library. If that happens, don't fall back
// and silently recompile the standard library -- instead, error like
// we used to.
// Still accept modules built with a different SDK, allowing the use
// of one toolchain against a different SDK.
LLVM_DEBUG(llvm::dbgs() << "Found out-of-date module in the "
"resource-dir at "
<< adjacentMod