Skip to content

Commit ed8032c

Browse files
[ClangImporter] Allow direct explicit load when implicit module is enabled
Improve clang importor so it can directly load explicit module even implicit module is enabled. This is a special configuration used by lldb because lldb sometimes need to load additional modules when binding external types. This provide the path in clang importer that can load explicit module without locating the clang module map, while fallback to module map lookup when implicit module is needed.
1 parent af036fe commit ed8032c

File tree

1 file changed

+6
-17
lines changed

1 file changed

+6
-17
lines changed

lib/ClangImporter/ClangImporter.cpp

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2261,10 +2261,6 @@ bool ClangImporter::canImportModule(ImportPath::Module modulePath,
22612261
clang::Module *
22622262
ClangImporter::Implementation::lookupModule(StringRef moduleName) {
22632263
auto &clangHeaderSearch = getClangPreprocessor().getHeaderSearchInfo();
2264-
if (getClangASTContext().getLangOpts().ImplicitModules)
2265-
return clangHeaderSearch.lookupModule(
2266-
moduleName, /*ImportLoc=*/clang::SourceLocation(),
2267-
/*AllowSearch=*/true, /*AllowExtraModuleMapSearch=*/true);
22682264

22692265
// Explicit module. Try load from modulemap.
22702266
auto &PP = Instance->getPreprocessor();
@@ -2282,8 +2278,13 @@ ClangImporter::Implementation::lookupModule(StringRef moduleName) {
22822278
// If not, try load it.
22832279
auto &PrebuiltModules = Instance->getHeaderSearchOpts().PrebuiltModuleFiles;
22842280
auto moduleFile = PrebuiltModules.find(moduleName);
2285-
if (moduleFile == PrebuiltModules.end())
2281+
if (moduleFile == PrebuiltModules.end()) {
2282+
if (getClangASTContext().getLangOpts().ImplicitModules)
2283+
return clangHeaderSearch.lookupModule(
2284+
moduleName, /*ImportLoc=*/clang::SourceLocation(),
2285+
/*AllowSearch=*/true, /*AllowExtraModuleMapSearch=*/true);
22862286
return nullptr;
2287+
}
22872288

22882289
clang::serialization::ModuleFile *Loaded = nullptr;
22892290
if (!Instance->loadModuleFile(moduleFile->second, Loaded))
@@ -2293,20 +2294,8 @@ ClangImporter::Implementation::lookupModule(StringRef moduleName) {
22932294

22942295
ModuleDecl *ClangImporter::Implementation::loadModuleClang(
22952296
SourceLoc importLoc, ImportPath::Module path) {
2296-
auto &clangHeaderSearch = getClangPreprocessor().getHeaderSearchInfo();
22972297
auto realModuleName = SwiftContext.getRealModuleName(path.front().Item).str();
22982298

2299-
// For explicit module build, module should always exist but module map might
2300-
// not be exist. Go straight to module loader.
2301-
if (Instance->getInvocation().getLangOpts().ImplicitModules) {
2302-
// Look up the top-level module first, to see if it exists at all.
2303-
clang::Module *clangModule = clangHeaderSearch.lookupModule(
2304-
realModuleName, /*ImportLoc=*/clang::SourceLocation(),
2305-
/*AllowSearch=*/true, /*AllowExtraModuleMapSearch=*/true);
2306-
if (!clangModule)
2307-
return nullptr;
2308-
}
2309-
23102299
// Convert the Swift import path over to a Clang import path.
23112300
SmallVector<std::pair<clang::IdentifierInfo *, clang::SourceLocation>, 4>
23122301
clangPath;

0 commit comments

Comments
 (0)