@@ -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,12 @@ 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
+ Module * Module = nullptr ;
1656
+ ModuleMap &MM = getPreprocessor (). getHeaderSearchInfo (). getModuleMap ( );
1657
+ if (auto MaybeModule = MM. getCachedModuleLoad (*Path[ 0 ]. first )) {
1658
+ // Use the cached result, which may be nullptr .
1659
+ Module = *MaybeModule ;
1665
1660
} else if (ModuleName == getLangOpts ().CurrentModule ) {
1666
1661
// This is the module we're building.
1667
1662
Module = PP->getHeaderSearchInfo ().lookupModule (
@@ -1675,7 +1670,7 @@ CompilerInstance::loadModule(SourceLocation ImportLoc,
1675
1670
// ModuleBuildFailed = true;
1676
1671
// return ModuleLoadResult();
1677
1672
// }
1678
- Known = KnownModules. insert ( std::make_pair ( Path[0 ].first , Module)). first ;
1673
+ MM. cacheModuleLoad (* Path[0 ].first , Module);
1679
1674
} else {
1680
1675
// Search for a module with the given name.
1681
1676
Module = PP->getHeaderSearchInfo ().lookupModule (ModuleName, true ,
@@ -1769,7 +1764,7 @@ CompilerInstance::loadModule(SourceLocation ImportLoc,
1769
1764
getDiagnostics ().Report (ModuleNameLoc, diag::err_module_prebuilt)
1770
1765
<< ModuleName;
1771
1766
ModuleBuildFailed = true ;
1772
- KnownModules[ Path[0 ].first ] = nullptr ;
1767
+ MM. cacheModuleLoad (* Path[0 ].first , nullptr ) ;
1773
1768
return ModuleLoadResult ();
1774
1769
}
1775
1770
}
@@ -1783,7 +1778,7 @@ CompilerInstance::loadModule(SourceLocation ImportLoc,
1783
1778
// necessarily even have a module map. Since ReadAST already produces
1784
1779
// diagnostics for these two cases, we simply error out here.
1785
1780
ModuleBuildFailed = true ;
1786
- KnownModules[ Path[0 ].first ] = nullptr ;
1781
+ MM. cacheModuleLoad (* Path[0 ].first , nullptr ) ;
1787
1782
return ModuleLoadResult ();
1788
1783
}
1789
1784
@@ -1828,7 +1823,7 @@ CompilerInstance::loadModule(SourceLocation ImportLoc,
1828
1823
" undiagnosed error in compileAndLoadModule" );
1829
1824
if (getPreprocessorOpts ().FailedModules )
1830
1825
getPreprocessorOpts ().FailedModules ->addFailed (ModuleName);
1831
- KnownModules[ Path[0 ].first ] = nullptr ;
1826
+ MM. cacheModuleLoad (* Path[0 ].first , nullptr ) ;
1832
1827
ModuleBuildFailed = true ;
1833
1828
return ModuleLoadResult ();
1834
1829
}
@@ -1851,19 +1846,19 @@ CompilerInstance::loadModule(SourceLocation ImportLoc,
1851
1846
ModuleLoader::HadFatalFailure = true ;
1852
1847
// FIXME: The ASTReader will already have complained, but can we shoehorn
1853
1848
// that diagnostic information into a more useful form?
1854
- KnownModules[ Path[0 ].first ] = nullptr ;
1849
+ MM. cacheModuleLoad (* Path[0 ].first , nullptr ) ;
1855
1850
return ModuleLoadResult ();
1856
1851
1857
1852
case ASTReader::Failure:
1858
1853
ModuleLoader::HadFatalFailure = true ;
1859
1854
// Already complained, but note now that we failed.
1860
- KnownModules[ Path[0 ].first ] = nullptr ;
1855
+ MM. cacheModuleLoad (* Path[0 ].first , nullptr ) ;
1861
1856
ModuleBuildFailed = true ;
1862
1857
return ModuleLoadResult ();
1863
1858
}
1864
1859
1865
1860
// Cache the result of this top-level module lookup for later.
1866
- Known = KnownModules. insert ( std::make_pair ( Path[0 ].first , Module)). first ;
1861
+ MM. cacheModuleLoad (* Path[0 ].first , Module);
1867
1862
}
1868
1863
1869
1864
// If we never found the module, fail.
0 commit comments