@@ -1736,10 +1736,8 @@ ModuleDecl *ClangImporter::Implementation::loadModuleClang(
1736
1736
auto &diagClient = static_cast <ClangDiagnosticConsumer &>(rawDiagClient);
1737
1737
1738
1738
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 {
1743
1741
auto importRAII =
1744
1742
diagClient.handleImport (clangPath.front ().first , importLoc);
1745
1743
@@ -1765,17 +1763,24 @@ ModuleDecl *ClangImporter::Implementation::loadModuleClang(
1765
1763
clangFEOpts.IndexStorePath = preservedIndexStorePathOption;
1766
1764
}
1767
1765
1768
- if (result && makeVisible)
1766
+ if (result && (visibility == clang::Module::AllVisible)) {
1769
1767
getClangPreprocessor ().makeModuleVisible (result, clangImportLoc);
1768
+ }
1770
1769
return result;
1771
1770
};
1772
1771
1773
1772
// Now load the top-level module, so that we can check if the submodule
1774
1773
// exists without triggering a fatal error.
1775
- clangModule = loadModule (clangPath.front (), false );
1774
+ clangModule = loadModule (clangPath.front (), clang::Module::AllVisible );
1776
1775
if (!clangModule)
1777
1776
return nullptr ;
1778
1777
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
+
1779
1784
// Verify that the submodule exists.
1780
1785
clang::Module *submodule = clangModule;
1781
1786
for (auto &component : path.slice (1 )) {
@@ -1787,7 +1792,8 @@ ModuleDecl *ClangImporter::Implementation::loadModuleClang(
1787
1792
// put the Clang AST in a fatal error state if it /doesn't/ exist.
1788
1793
if (!submodule && component.Item .str () == " Private" &&
1789
1794
(&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);
1791
1797
}
1792
1798
1793
1799
if (!submodule) {
@@ -1797,7 +1803,7 @@ ModuleDecl *ClangImporter::Implementation::loadModuleClang(
1797
1803
}
1798
1804
1799
1805
// Finally, load the submodule and make it visible.
1800
- clangModule = loadModule (clangPath, true );
1806
+ clangModule = loadModule (clangPath, clang::Module::AllVisible );
1801
1807
if (!clangModule)
1802
1808
return nullptr ;
1803
1809
0 commit comments