Load modules using real names if module aliases are used

rdar://83591943
This commit is contained in:
elsh
2021-09-30 14:05:45 -07:00
parent 140c02466a
commit 55b9fa11d8
5 changed files with 65 additions and 10 deletions

View File

@@ -533,7 +533,14 @@ SerializedModuleLoaderBase::findModule(ImportPath::Element moduleID,
std::unique_ptr<llvm::MemoryBuffer> *moduleDocBuffer,
std::unique_ptr<llvm::MemoryBuffer> *moduleSourceInfoBuffer,
bool skipBuildingInterface, bool &isFramework, bool &isSystemModule) {
SmallString<32> moduleName(moduleID.Item.str());
// Find a module with an actual, physical name on disk, in case
// -module-alias is used (otherwise same).
//
// For example, if '-module-alias Foo=Bar' is passed in to the frontend,
// and a source file has 'import Foo', a module called Bar (real name)
// should be searched.
StringRef moduleNameRef = Ctx.getRealModuleName(moduleID.Item).str();
SmallString<32> moduleName(moduleNameRef);
SerializedModuleBaseName genericBaseName(moduleName);
auto genericModuleFileName =
@@ -1156,7 +1163,6 @@ bool MemoryBufferSerializedModuleLoader::canImportModule(
assert(!(mIt->second.userVersion.empty()));
return mIt->second.userVersion >= version;
}
ModuleDecl *
SerializedModuleLoaderBase::loadModule(SourceLoc importLoc,
ImportPath::Module path) {
@@ -1220,13 +1226,14 @@ MemoryBufferSerializedModuleLoader::loadModule(SourceLoc importLoc,
return nullptr;
auto moduleID = path[0];
auto moduleName = Ctx.getRealModuleName(moduleID.Item).str();
// See if we find it in the registered memory buffers.
// FIXME: Right now this works only with access paths of length 1.
// Once submodules are designed, this needs to support suffix
// matching and a search path.
auto bufIter = MemoryBuffers.find(moduleID.Item.str());
auto bufIter = MemoryBuffers.find(moduleName);
if (bufIter == MemoryBuffers.end())
return nullptr;