Skip to content

Commit c80b6f6

Browse files
committed
[ClangImporter] Only copy submodule imports for top-level modules
Since only top-level Swift modules ever contain code, setting imports for submodule wrappers has no effect.
1 parent 928cc6c commit c80b6f6

File tree

1 file changed

+32
-30
lines changed

1 file changed

+32
-30
lines changed

lib/ClangImporter/ClangImporter.cpp

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2842,37 +2842,39 @@ ClangModuleUnit *ClangImporter::Implementation::getWrapperForModule(
28422842
// of the clang submodules, we need to add the imports of all the
28432843
// transitive submodules, since we don't know at this point of the
28442844
// compilation which submodules will contain relevant macros.
2845-
llvm::SmallVector<const clang::Module *, 32> SubmoduleWorklist;
2846-
llvm::DenseSet<ImportPath> Imported;
2847-
SubmoduleWorklist.push_back(underlying);
2848-
std::string underlyingSwiftModuleName =
2849-
isCxxStdModule(underlying)
2850-
? static_cast<std::string>(SwiftContext.Id_CxxStdlib)
2851-
: underlying->getFullModuleName();
2852-
ImportPath::Builder underlyingImportPath(SwiftContext,
2853-
underlyingSwiftModuleName, '.');
2854-
Imported.insert(underlyingImportPath.get());
2855-
for (auto UI : implicitImportInfo.AdditionalUnloadedImports)
2856-
Imported.insert(UI.module.getImportPath());
2857-
assert(implicitImportInfo.AdditionalImports.empty());
2858-
2859-
while (!SubmoduleWorklist.empty()) {
2860-
const clang::Module *CurrModule = SubmoduleWorklist.pop_back_val();
2861-
for (auto *I : CurrModule->Imports) {
2862-
std::string swiftModuleName =
2863-
isCxxStdModule(I)
2864-
? static_cast<std::string>(SwiftContext.Id_CxxStdlib)
2865-
: I->getFullModuleName();
2866-
ImportPath::Builder importPath(SwiftContext, swiftModuleName, '.');
2867-
if (Imported.count(importPath.get()))
2868-
continue;
2869-
UnloadedImportedModule importedModule(importPath.copyTo(SwiftContext),
2870-
ImportKind::Module);
2871-
Imported.insert(importedModule.getImportPath());
2872-
implicitImportInfo.AdditionalUnloadedImports.push_back(importedModule);
2845+
if (!underlying->isSubModule()) {
2846+
llvm::SmallVector<const clang::Module *, 32> SubmoduleWorklist;
2847+
llvm::DenseSet<ImportPath> Imported;
2848+
SubmoduleWorklist.push_back(underlying);
2849+
std::string underlyingSwiftModuleName =
2850+
isCxxStdModule(underlying)
2851+
? static_cast<std::string>(SwiftContext.Id_CxxStdlib)
2852+
: underlying->getFullModuleName();
2853+
ImportPath::Builder underlyingImportPath(SwiftContext,
2854+
underlyingSwiftModuleName, '.');
2855+
Imported.insert(underlyingImportPath.get());
2856+
for (auto UI : implicitImportInfo.AdditionalUnloadedImports)
2857+
Imported.insert(UI.module.getImportPath());
2858+
assert(implicitImportInfo.AdditionalImports.empty());
2859+
2860+
while (!SubmoduleWorklist.empty()) {
2861+
const clang::Module *CurrModule = SubmoduleWorklist.pop_back_val();
2862+
for (auto *I : CurrModule->Imports) {
2863+
std::string swiftModuleName =
2864+
isCxxStdModule(I)
2865+
? static_cast<std::string>(SwiftContext.Id_CxxStdlib)
2866+
: I->getFullModuleName();
2867+
ImportPath::Builder importPath(SwiftContext, swiftModuleName, '.');
2868+
if (Imported.count(importPath.get()))
2869+
continue;
2870+
UnloadedImportedModule importedModule(importPath.copyTo(SwiftContext),
2871+
ImportKind::Module);
2872+
Imported.insert(importedModule.getImportPath());
2873+
implicitImportInfo.AdditionalUnloadedImports.push_back(importedModule);
2874+
}
2875+
for (auto *Submodule : CurrModule->submodules())
2876+
SubmoduleWorklist.push_back(Submodule);
28732877
}
2874-
for (auto *Submodule : CurrModule->submodules())
2875-
SubmoduleWorklist.push_back(Submodule);
28762878
}
28772879

28782880
ClangModuleUnit *file = nullptr;

0 commit comments

Comments
 (0)