Skip to content

Commit f4569a6

Browse files
[Module] Simplify explicit clang module loading
When using explicit module build, there is no need to check top level module map to see if the module exists or not, since dependency scanning already pulled in all needed modules. Furthermore, when using clang include tree, the module maps are not available through FS for this search. Just directly try to load modules when using explicit module build.
1 parent cc01780 commit f4569a6

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

lib/ClangImporter/ClangImporter.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1964,12 +1964,16 @@ ModuleDecl *ClangImporter::Implementation::loadModuleClang(
19641964
auto &clangHeaderSearch = getClangPreprocessor().getHeaderSearchInfo();
19651965
auto realModuleName = SwiftContext.getRealModuleName(path.front().Item).str();
19661966

1967-
// Look up the top-level module first, to see if it exists at all.
1968-
clang::Module *clangModule = clangHeaderSearch.lookupModule(
1969-
realModuleName, /*ImportLoc=*/clang::SourceLocation(),
1970-
/*AllowSearch=*/true, /*AllowExtraModuleMapSearch=*/true);
1971-
if (!clangModule)
1972-
return nullptr;
1967+
// For explicit module build, module should always exist but module map might
1968+
// not be exist. Go straight to module loader.
1969+
if (Instance->getInvocation().getLangOpts()->ImplicitModules) {
1970+
// Look up the top-level module first, to see if it exists at all.
1971+
clang::Module *clangModule = clangHeaderSearch.lookupModule(
1972+
realModuleName, /*ImportLoc=*/clang::SourceLocation(),
1973+
/*AllowSearch=*/true, /*AllowExtraModuleMapSearch=*/true);
1974+
if (!clangModule)
1975+
return nullptr;
1976+
}
19731977

19741978
// Convert the Swift import path over to a Clang import path.
19751979
SmallVector<std::pair<clang::IdentifierInfo *, clang::SourceLocation>, 4>
@@ -2024,7 +2028,7 @@ ModuleDecl *ClangImporter::Implementation::loadModuleClang(
20242028

20252029
// Now load the top-level module, so that we can check if the submodule
20262030
// exists without triggering a fatal error.
2027-
clangModule = loadModule(clangPath.front(), clang::Module::AllVisible);
2031+
auto clangModule = loadModule(clangPath.front(), clang::Module::AllVisible);
20282032
if (!clangModule)
20292033
return nullptr;
20302034

0 commit comments

Comments
 (0)