@@ -1541,12 +1541,9 @@ bool CompilerInstance::loadModuleFile(StringRef FileName) {
1541
1541
}
1542
1542
1543
1543
void registerAll () {
1544
- for (auto *II : LoadedModules) {
1545
- CI.KnownModules [II] = CI.getPreprocessor ()
1546
- .getHeaderSearchInfo ()
1547
- .getModuleMap ()
1548
- .findModule (II->getName ());
1549
- }
1544
+ ModuleMap &MM = CI.getPreprocessor ().getHeaderSearchInfo ().getModuleMap ();
1545
+ for (auto *II : LoadedModules)
1546
+ MM.cacheModuleLoad (*II, MM.findModule (II->getName ()));
1550
1547
LoadedModules.clear ();
1551
1548
}
1552
1549
@@ -1635,14 +1632,11 @@ CompilerInstance::loadModule(SourceLocation ImportLoc,
1635
1632
return LastModuleImportResult;
1636
1633
}
1637
1634
1638
- clang::Module *Module = nullptr ;
1639
-
1640
1635
// If we don't already have information on this module, load the module now.
1641
- llvm::DenseMap<const IdentifierInfo *, clang::Module *>::iterator Known
1642
- = KnownModules.find (Path[0 ].first );
1643
- if (Known != KnownModules.end ()) {
1644
- // Retrieve the cached top-level module.
1645
- Module = Known->second ;
1636
+ ModuleMap &MM = getPreprocessor ().getHeaderSearchInfo ().getModuleMap ();
1637
+ clang::Module *Module = MM.getCachedModuleLoad (*Path[0 ].first );
1638
+ if (Module) {
1639
+ // Nothing to do here, we found it.
1646
1640
} else if (ModuleName == getLangOpts ().CurrentModule ) {
1647
1641
// This is the module we're building.
1648
1642
Module = PP->getHeaderSearchInfo ().lookupModule (
@@ -1656,7 +1650,7 @@ CompilerInstance::loadModule(SourceLocation ImportLoc,
1656
1650
// ModuleBuildFailed = true;
1657
1651
// return ModuleLoadResult();
1658
1652
// }
1659
- Known = KnownModules. insert ( std::make_pair ( Path[0 ].first , Module)). first ;
1653
+ MM. cacheModuleLoad (* Path[0 ].first , Module);
1660
1654
} else {
1661
1655
// Search for a module with the given name.
1662
1656
Module = PP->getHeaderSearchInfo ().lookupModule (ModuleName, true ,
@@ -1750,7 +1744,7 @@ CompilerInstance::loadModule(SourceLocation ImportLoc,
1750
1744
getDiagnostics ().Report (ModuleNameLoc, diag::err_module_prebuilt)
1751
1745
<< ModuleName;
1752
1746
ModuleBuildFailed = true ;
1753
- KnownModules[ Path[0 ].first ] = nullptr ;
1747
+ MM. cacheModuleLoad (* Path[0 ].first , nullptr ) ;
1754
1748
return ModuleLoadResult ();
1755
1749
}
1756
1750
}
@@ -1764,7 +1758,7 @@ CompilerInstance::loadModule(SourceLocation ImportLoc,
1764
1758
// necessarily even have a module map. Since ReadAST already produces
1765
1759
// diagnostics for these two cases, we simply error out here.
1766
1760
ModuleBuildFailed = true ;
1767
- KnownModules[ Path[0 ].first ] = nullptr ;
1761
+ MM. cacheModuleLoad (* Path[0 ].first , nullptr ) ;
1768
1762
return ModuleLoadResult ();
1769
1763
}
1770
1764
@@ -1809,7 +1803,7 @@ CompilerInstance::loadModule(SourceLocation ImportLoc,
1809
1803
" undiagnosed error in compileAndLoadModule" );
1810
1804
if (getPreprocessorOpts ().FailedModules )
1811
1805
getPreprocessorOpts ().FailedModules ->addFailed (ModuleName);
1812
- KnownModules[ Path[0 ].first ] = nullptr ;
1806
+ MM. cacheModuleLoad (* Path[0 ].first , nullptr ) ;
1813
1807
ModuleBuildFailed = true ;
1814
1808
return ModuleLoadResult ();
1815
1809
}
@@ -1832,19 +1826,19 @@ CompilerInstance::loadModule(SourceLocation ImportLoc,
1832
1826
ModuleLoader::HadFatalFailure = true ;
1833
1827
// FIXME: The ASTReader will already have complained, but can we shoehorn
1834
1828
// that diagnostic information into a more useful form?
1835
- KnownModules[ Path[0 ].first ] = nullptr ;
1829
+ MM. cacheModuleLoad (* Path[0 ].first , nullptr ) ;
1836
1830
return ModuleLoadResult ();
1837
1831
1838
1832
case ASTReader::Failure:
1839
1833
ModuleLoader::HadFatalFailure = true ;
1840
1834
// Already complained, but note now that we failed.
1841
- KnownModules[ Path[0 ].first ] = nullptr ;
1835
+ MM. cacheModuleLoad (* Path[0 ].first , nullptr ) ;
1842
1836
ModuleBuildFailed = true ;
1843
1837
return ModuleLoadResult ();
1844
1838
}
1845
1839
1846
1840
// Cache the result of this top-level module lookup for later.
1847
- Known = KnownModules. insert ( std::make_pair ( Path[0 ].first , Module)). first ;
1841
+ MM. cacheModuleLoad (* Path[0 ].first , Module);
1848
1842
}
1849
1843
1850
1844
// If we never found the module, fail.
0 commit comments