Skip to content

Commit 4fb0287

Browse files
authored
Merge pull request swiftlang#33261 from CodaFi/truss-theory
Miscellaneous Minor Clang Module Loading Refactorings
2 parents 6ae04f7 + a0af6e5 commit 4fb0287

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

lib/ClangImporter/ClangImporter.cpp

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1736,10 +1736,8 @@ ModuleDecl *ClangImporter::Implementation::loadModuleClang(
17361736
auto &diagClient = static_cast<ClangDiagnosticConsumer &>(rawDiagClient);
17371737

17381738
auto loadModule = [&](clang::ModuleIdPath path,
1739-
bool makeVisible) -> clang::ModuleLoadResult {
1740-
clang::Module::NameVisibilityKind visibility =
1741-
makeVisible ? clang::Module::AllVisible : clang::Module::Hidden;
1742-
1739+
clang::Module::NameVisibilityKind visibility)
1740+
-> clang::ModuleLoadResult {
17431741
auto importRAII =
17441742
diagClient.handleImport(clangPath.front().first, importLoc);
17451743

@@ -1765,17 +1763,24 @@ ModuleDecl *ClangImporter::Implementation::loadModuleClang(
17651763
clangFEOpts.IndexStorePath = preservedIndexStorePathOption;
17661764
}
17671765

1768-
if (result && makeVisible)
1766+
if (result && (visibility == clang::Module::AllVisible)) {
17691767
getClangPreprocessor().makeModuleVisible(result, clangImportLoc);
1768+
}
17701769
return result;
17711770
};
17721771

17731772
// Now load the top-level module, so that we can check if the submodule
17741773
// exists without triggering a fatal error.
1775-
clangModule = loadModule(clangPath.front(), false);
1774+
clangModule = loadModule(clangPath.front(), clang::Module::AllVisible);
17761775
if (!clangModule)
17771776
return nullptr;
17781777

1778+
// If we're asked to import the top-level module then we're done here.
1779+
auto *topSwiftModule = finishLoadingClangModule(clangModule, importLoc);
1780+
if (path.size() == 1) {
1781+
return topSwiftModule;
1782+
}
1783+
17791784
// Verify that the submodule exists.
17801785
clang::Module *submodule = clangModule;
17811786
for (auto &component : path.slice(1)) {
@@ -1787,7 +1792,8 @@ ModuleDecl *ClangImporter::Implementation::loadModuleClang(
17871792
// put the Clang AST in a fatal error state if it /doesn't/ exist.
17881793
if (!submodule && component.Item.str() == "Private" &&
17891794
(&component) == (&path[1])) {
1790-
submodule = loadModule(llvm::makeArrayRef(clangPath).slice(0, 2), false);
1795+
submodule = loadModule(llvm::makeArrayRef(clangPath).slice(0, 2),
1796+
clang::Module::Hidden);
17911797
}
17921798

17931799
if (!submodule) {
@@ -1797,7 +1803,7 @@ ModuleDecl *ClangImporter::Implementation::loadModuleClang(
17971803
}
17981804

17991805
// Finally, load the submodule and make it visible.
1800-
clangModule = loadModule(clangPath, true);
1806+
clangModule = loadModule(clangPath, clang::Module::AllVisible);
18011807
if (!clangModule)
18021808
return nullptr;
18031809

lib/ClangImporter/DWARFImporter.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,9 @@ ModuleDecl *ClangImporter::Implementation::loadModuleDWARF(
118118
decl->addFile(*wrapperUnit);
119119

120120
// Force load overlay modules for all imported modules.
121-
(void) namelookup::getAllImports(decl);
121+
assert(namelookup::getAllImports(decl).size() == 1 &&
122+
namelookup::getAllImports(decl).front().importedModule == decl &&
123+
"DWARF module depends on additional modules?");
122124

123125
// Register the module with the ASTContext so it is available for lookups.
124126
if (!SwiftContext.getLoadedModule(name))

0 commit comments

Comments
 (0)