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

@@ -1848,12 +1848,27 @@ ASTContext::getLoadedModules() const {
}
ModuleDecl *ASTContext::getLoadedModule(Identifier ModuleName) const {
return getImpl().LoadedModules.lookup(ModuleName);
// Look up a loaded module using an actual module name (physical name
// on disk). If the -module-alias option is used, the module name that
// appears in source code will be different from the real module name
// on disk, otherwise the 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)
// will be loaded and returned.
auto realName = getRealModuleName(ModuleName);
return getImpl().LoadedModules.lookup(realName);
}
void ASTContext::addLoadedModule(ModuleDecl *M) {
assert(M);
getImpl().LoadedModules[M->getName()] = M;
// Add a loaded module using an actual module name (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)
// will be loaded and added to the map.
getImpl().LoadedModules[M->getRealName()] = M;
}
void ASTContext::registerGenericSignatureBuilder(