@@ -1786,8 +1786,7 @@ ModuleDecl *ClangImporter::Implementation::loadModuleClang(
17861786 if (!clangModule)
17871787 return nullptr ;
17881788
1789- return finishLoadingClangModule (importLoc, clangModule,
1790- /* preferOverlay=*/ false );
1789+ return finishLoadingClangModule (clangModule, importLoc);
17911790}
17921791
17931792ModuleDecl *
@@ -1807,59 +1806,30 @@ ModuleDecl *ClangImporter::Implementation::loadModule(
18071806}
18081807
18091808ModuleDecl *ClangImporter::Implementation::finishLoadingClangModule (
1810- SourceLoc importLoc, const clang::Module *clangModule, bool findOverlay ) {
1809+ const clang::Module *clangModule, SourceLoc importLoc ) {
18111810 assert (clangModule);
18121811
18131812 // Bump the generation count.
18141813 bumpGeneration ();
18151814
1816- auto &cacheEntry = ModuleWrappers[clangModule];
1817- ModuleDecl *result;
1818- ClangModuleUnit *wrapperUnit;
1819- if ((wrapperUnit = cacheEntry.getPointer ())) {
1820- result = wrapperUnit->getParentModule ();
1821- if (!cacheEntry.getInt ()) {
1822- // Force load overlays for all imported modules.
1823- // FIXME: This forces the creation of wrapper modules for all imports as
1824- // well, and may do unnecessary work.
1825- cacheEntry.setInt (true );
1826- (void ) namelookup::getAllImports (result);
1827- }
1828- } else {
1829- // Build the representation of the Clang module in Swift.
1830- // FIXME: The name of this module could end up as a key in the ASTContext,
1831- // but that's not correct for submodules.
1832- Identifier name = SwiftContext.getIdentifier ((*clangModule).Name );
1833- result = ModuleDecl::create (name, SwiftContext);
1834- result->setIsSystemModule (clangModule->IsSystem );
1835- result->setIsNonSwiftModule ();
1836- result->setHasResolvedImports ();
1837-
1838- wrapperUnit =
1839- new (SwiftContext) ClangModuleUnit (*result, *this , clangModule);
1840- result->addFile (*wrapperUnit);
1841- SwiftContext.getClangModuleLoader ()
1842- ->findOverlayFiles (importLoc, result, wrapperUnit);
1843- cacheEntry.setPointerAndInt (wrapperUnit, true );
1844-
1845- // Force load overlays for all imported modules.
1846- // FIXME: This forces the creation of wrapper modules for all imports as
1847- // well, and may do unnecessary work.
1815+ // Force load overlays for all imported modules.
1816+ // FIXME: This forces the creation of wrapper modules for all imports as
1817+ // well, and may do unnecessary work.
1818+ ClangModuleUnit *wrapperUnit = getWrapperForModule (clangModule, importLoc);
1819+ ModuleDecl *result = wrapperUnit->getParentModule ();
1820+ if (!ModuleWrappers[clangModule].getInt ()) {
1821+ ModuleWrappers[clangModule].setInt (true );
18481822 (void ) namelookup::getAllImports (result);
18491823 }
18501824
18511825 if (clangModule->isSubModule ()) {
1852- finishLoadingClangModule (importLoc, clangModule->getTopLevelModule (), true );
1826+ finishLoadingClangModule (clangModule->getTopLevelModule (), importLoc );
18531827 } else {
18541828 ModuleDecl *&loaded = SwiftContext.LoadedModules [result->getName ()];
18551829 if (!loaded)
18561830 loaded = result;
18571831 }
18581832
1859- if (findOverlay)
1860- if (ModuleDecl *overlay = wrapperUnit->getOverlayModule ())
1861- result = overlay;
1862-
18631833 return result;
18641834}
18651835
@@ -1883,8 +1853,7 @@ void ClangImporter::Implementation::handleDeferredImports(SourceLoc diagLoc) {
18831853 // officially supported with bridging headers: app targets and unit tests
18841854 // only. Unfortunately that's not enforced.
18851855 for (size_t i = 0 ; i < ImportedHeaderExports.size (); ++i) {
1886- (void )finishLoadingClangModule (diagLoc, ImportedHeaderExports[i],
1887- /* preferOverlay=*/ true );
1856+ (void )finishLoadingClangModule (ImportedHeaderExports[i], diagLoc);
18881857 }
18891858}
18901859
@@ -2025,7 +1994,7 @@ ClangImporter::Implementation::~Implementation() {
20251994}
20261995
20271996ClangModuleUnit *ClangImporter::Implementation::getWrapperForModule (
2028- const clang::Module *underlying) {
1997+ const clang::Module *underlying, SourceLoc diagLoc ) {
20291998 auto &cacheEntry = ModuleWrappers[underlying];
20301999 if (ClangModuleUnit *cached = cacheEntry.getPointer ())
20312000 return cached;
@@ -2040,7 +2009,7 @@ ClangModuleUnit *ClangImporter::Implementation::getWrapperForModule(
20402009 auto file = new (SwiftContext) ClangModuleUnit (*wrapper, *this ,
20412010 underlying);
20422011 wrapper->addFile (*file);
2043- SwiftContext.getClangModuleLoader ()->findOverlayFiles (SourceLoc () , wrapper, file);
2012+ SwiftContext.getClangModuleLoader ()->findOverlayFiles (diagLoc , wrapper, file);
20442013 cacheEntry.setPointer (file);
20452014
20462015 return file;
0 commit comments