ExplicitModuleLoader: teach the module loader to accept forwarding modules

Since -emit-module-from-interface now emits forwarding modules, explicit module
loader should be able to accept forwarding modules and unbox their actual binary
contents.
This commit is contained in:
Xi Ge
2020-07-19 16:08:32 -07:00
parent 8af488ed76
commit 9a33ac63a5
2 changed files with 51 additions and 0 deletions

View File

@@ -1654,6 +1654,31 @@ std::error_code ExplicitSwiftModuleLoader::findModuleFilesInDirectory(
moduleInfo.modulePath);
return moduleBuf.getError();
}
assert(moduleBuf);
const bool isForwardingModule = !serialization::isSerializedAST(moduleBuf
.get()->getBuffer());
// If the module is a forwarding module, read the actual content from the path
// encoded in the forwarding module as the actual module content.
if (isForwardingModule) {
auto forwardingModule = ForwardingModule::load(*moduleBuf.get());
if (forwardingModule) {
moduleBuf = fs.getBufferForFile(forwardingModule->underlyingModulePath);
if (!moduleBuf) {
// We cannot read the module content, diagnose.
Ctx.Diags.diagnose(SourceLoc(), diag::error_opening_explicit_module_file,
moduleInfo.modulePath);
return moduleBuf.getError();
}
} else {
// We cannot read the module content, diagnose.
Ctx.Diags.diagnose(SourceLoc(), diag::error_opening_explicit_module_file,
moduleInfo.modulePath);
return forwardingModule.getError();
}
}
assert(moduleBuf);
// Move the opened module buffer to the caller.
*ModuleBuffer = std::move(moduleBuf.get());
// Open .swiftdoc file