@@ -1560,12 +1560,9 @@ bool CompilerInstance::loadModuleFile(StringRef FileName) {
1560
1560
}
1561
1561
1562
1562
void registerAll () {
1563
- for (auto *II : LoadedModules) {
1564
- CI.KnownModules [II] = CI.getPreprocessor ()
1565
- .getHeaderSearchInfo ()
1566
- .getModuleMap ()
1567
- .findModule (II->getName ());
1568
- }
1563
+ ModuleMap &MM = CI.getPreprocessor ().getHeaderSearchInfo ().getModuleMap ();
1564
+ for (auto *II : LoadedModules)
1565
+ MM.cacheModuleLoad (*II, MM.findModule (II->getName ()));
1569
1566
LoadedModules.clear ();
1570
1567
}
1571
1568
@@ -1654,14 +1651,11 @@ CompilerInstance::loadModule(SourceLocation ImportLoc,
1654
1651
return LastModuleImportResult;
1655
1652
}
1656
1653
1657
- clang::Module *Module = nullptr ;
1658
-
1659
1654
// If we don't already have information on this module, load the module now.
1660
- llvm::DenseMap<const IdentifierInfo *, clang::Module *>::iterator Known
1661
- = KnownModules.find (Path[0 ].first );
1662
- if (Known != KnownModules.end ()) {
1663
- // Retrieve the cached top-level module.
1664
- Module = Known->second ;
1655
+ ModuleMap &MM = getPreprocessor ().getHeaderSearchInfo ().getModuleMap ();
1656
+ clang::Module *Module = MM.getCachedModuleLoad (*Path[0 ].first );
1657
+ if (Module) {
1658
+ // Nothing to do here, we found it.
1665
1659
} else if (ModuleName == getLangOpts ().CurrentModule ) {
1666
1660
// This is the module we're building.
1667
1661
Module = PP->getHeaderSearchInfo ().lookupModule (
@@ -1675,7 +1669,7 @@ CompilerInstance::loadModule(SourceLocation ImportLoc,
1675
1669
// ModuleBuildFailed = true;
1676
1670
// return ModuleLoadResult();
1677
1671
// }
1678
- Known = KnownModules. insert ( std::make_pair ( Path[0 ].first , Module)). first ;
1672
+ MM. cacheModuleLoad (* Path[0 ].first , Module);
1679
1673
} else {
1680
1674
// Search for a module with the given name.
1681
1675
Module = PP->getHeaderSearchInfo ().lookupModule (ModuleName, true ,
@@ -1769,7 +1763,7 @@ CompilerInstance::loadModule(SourceLocation ImportLoc,
1769
1763
getDiagnostics ().Report (ModuleNameLoc, diag::err_module_prebuilt)
1770
1764
<< ModuleName;
1771
1765
ModuleBuildFailed = true ;
1772
- KnownModules[ Path[0 ].first ] = nullptr ;
1766
+ MM. cacheModuleLoad (* Path[0 ].first , nullptr ) ;
1773
1767
return ModuleLoadResult ();
1774
1768
}
1775
1769
}
@@ -1783,7 +1777,7 @@ CompilerInstance::loadModule(SourceLocation ImportLoc,
1783
1777
// necessarily even have a module map. Since ReadAST already produces
1784
1778
// diagnostics for these two cases, we simply error out here.
1785
1779
ModuleBuildFailed = true ;
1786
- KnownModules[ Path[0 ].first ] = nullptr ;
1780
+ MM. cacheModuleLoad (* Path[0 ].first , nullptr ) ;
1787
1781
return ModuleLoadResult ();
1788
1782
}
1789
1783
@@ -1828,7 +1822,7 @@ CompilerInstance::loadModule(SourceLocation ImportLoc,
1828
1822
" undiagnosed error in compileAndLoadModule" );
1829
1823
if (getPreprocessorOpts ().FailedModules )
1830
1824
getPreprocessorOpts ().FailedModules ->addFailed (ModuleName);
1831
- KnownModules[ Path[0 ].first ] = nullptr ;
1825
+ MM. cacheModuleLoad (* Path[0 ].first , nullptr ) ;
1832
1826
ModuleBuildFailed = true ;
1833
1827
return ModuleLoadResult ();
1834
1828
}
@@ -1851,19 +1845,19 @@ CompilerInstance::loadModule(SourceLocation ImportLoc,
1851
1845
ModuleLoader::HadFatalFailure = true ;
1852
1846
// FIXME: The ASTReader will already have complained, but can we shoehorn
1853
1847
// that diagnostic information into a more useful form?
1854
- KnownModules[ Path[0 ].first ] = nullptr ;
1848
+ MM. cacheModuleLoad (* Path[0 ].first , nullptr ) ;
1855
1849
return ModuleLoadResult ();
1856
1850
1857
1851
case ASTReader::Failure:
1858
1852
ModuleLoader::HadFatalFailure = true ;
1859
1853
// Already complained, but note now that we failed.
1860
- KnownModules[ Path[0 ].first ] = nullptr ;
1854
+ MM. cacheModuleLoad (* Path[0 ].first , nullptr ) ;
1861
1855
ModuleBuildFailed = true ;
1862
1856
return ModuleLoadResult ();
1863
1857
}
1864
1858
1865
1859
// Cache the result of this top-level module lookup for later.
1866
- Known = KnownModules. insert ( std::make_pair ( Path[0 ].first , Module)). first ;
1860
+ MM. cacheModuleLoad (* Path[0 ].first , Module);
1867
1861
}
1868
1862
1869
1863
// If we never found the module, fail.
0 commit comments