@@ -177,6 +177,10 @@ class ImportResolver final : public DeclVisitor<ImportResolver> {
177177 // / much, much smaller than \c crossImportableModules.
178178 SmallVector<AttributedImport<ImportedModule>, 16 > crossImportDeclaringModules;
179179
180+ // / The underlying clang module of the source file's parent module, if
181+ // / imported.
182+ ModuleDecl *underlyingClangModule = nullptr ;
183+
180184 // / The index of the next module in \c visibleModules that should be
181185 // / cross-imported.
182186 size_t nextModuleToCrossImport = 0 ;
@@ -193,6 +197,10 @@ class ImportResolver final : public DeclVisitor<ImportResolver> {
193197 return boundImports;
194198 }
195199
200+ // / Retrieve the underlying clang module which will be cached if it was loaded
201+ // / when resolving imports.
202+ ModuleDecl *getUnderlyingClangModule () const { return underlyingClangModule; }
203+
196204private:
197205 // We only need to visit import decls.
198206 void visitImportDecl (ImportDecl *ID);
@@ -287,6 +295,7 @@ void swift::performImportResolution(SourceFile &SF) {
287295 resolver.visit (D);
288296
289297 SF.setImports (resolver.getFinishedImports ());
298+ SF.setImportedUnderlyingModule (resolver.getUnderlyingClangModule ());
290299
291300 SF.ASTStage = SourceFile::ImportsResolved;
292301 verify (SF);
@@ -396,8 +405,10 @@ ImportResolver::getModule(ImportPath::Module modulePath) {
396405 // for clang overlays as well.
397406 if (ctx.getRealModuleName (moduleID.Item ) == loadingModule->getName () &&
398407 modulePath.size () == 1 ) {
399- if (auto importer = ctx.getClangModuleLoader ())
400- return importer->loadModule (moduleID.Loc , modulePath);
408+ if (auto importer = ctx.getClangModuleLoader ()) {
409+ underlyingClangModule = importer->loadModule (moduleID.Loc , modulePath);
410+ return underlyingClangModule;
411+ }
401412 return nullptr ;
402413 }
403414
0 commit comments