Skip to content

Commit e67108a

Browse files
committed
Preload modules which are not in the index.
1 parent c21e1f4 commit e67108a

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

core/metacling/src/TCling.cxx

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1076,14 +1076,17 @@ static bool IsFromRootCling() {
10761076
}
10771077

10781078
/// Checks if there is an ASTFile on disk for the given module \c M.
1079-
static bool HasASTFileOnDisk(clang::Module *M, const clang::Preprocessor &PP)
1079+
static bool HasASTFileOnDisk(clang::Module *M, const clang::Preprocessor &PP, std::string *FullFileName = nullptr)
10801080
{
10811081
const HeaderSearchOptions &HSOpts = PP.getHeaderSearchInfo().getHeaderSearchOpts();
10821082

10831083
std::string ModuleFileName;
10841084
if (!HSOpts.PrebuiltModulePaths.empty())
10851085
// Load the module from *only* in the prebuilt module path.
10861086
ModuleFileName = PP.getHeaderSearchInfo().getModuleFileName(M->Name, /*ModuleMapPath*/"", /*UsePrebuiltPath*/ true);
1087+
if (FullFileName)
1088+
*FullFileName = ModuleFileName;
1089+
10871090
return !ModuleFileName.empty();
10881091
}
10891092

@@ -1170,6 +1173,34 @@ static void RegisterCommonCxxModules(cling::Interpreter &clingInterp)
11701173
LoadModules(FIXMEModules, clingInterp);
11711174

11721175
loadGlobalModuleIndex(SourceLocation(), clingInterp);
1176+
clang::CompilerInstance &CI = *clingInterp.getCI();
1177+
if (GlobalModuleIndex *GlobalIndex = CI.getModuleManager()->getGlobalIndex()) {
1178+
llvm::StringSet<> KnownModuleFileNames;
1179+
GlobalIndex->getKnownModuleFileNames(KnownModuleFileNames);
1180+
1181+
clang::Preprocessor &PP = CI.getPreprocessor();
1182+
ModuleMap &MMap = PP.getHeaderSearchInfo().getModuleMap();
1183+
for (auto I = MMap.module_begin(), E = MMap.module_end(); I != E; ++I) {
1184+
clang::Module *M = I->second;
1185+
assert(M);
1186+
1187+
// We want to load only already created modules.
1188+
std::string FullASTFilePath;
1189+
if (!HasASTFileOnDisk(M, PP, &FullASTFilePath))
1190+
continue;
1191+
1192+
if (KnownModuleFileNames.count(FullASTFilePath))
1193+
continue;
1194+
1195+
if (!M->IsMissingRequirement) {
1196+
if (gDebug > 2)
1197+
::Info("TCling::__RegisterCommonCxxModules", "Preloading %s because it is not in GMI. \n",
1198+
M->Name.data());
1199+
1200+
LoadModule(M->Name, clingInterp);
1201+
}
1202+
}
1203+
}
11731204
}
11741205

11751206
// Check that the gROOT macro was exported by any core module.

interpreter/llvm/src/tools/clang/include/clang/Serialization/GlobalModuleIndex.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ namespace serialization {
4545
using llvm::SmallVector;
4646
using llvm::SmallVectorImpl;
4747
using llvm::StringRef;
48+
using llvm::StringSet;
4849
using serialization::ModuleFile;
4950

5051
/// \brief A global index for a set of module files, providing information about
@@ -160,6 +161,8 @@ class GlobalModuleIndex {
160161
/// have been indexed.
161162
void getKnownModules(SmallVectorImpl<ModuleFile *> &ModuleFiles);
162163

164+
void getKnownModuleFileNames(StringSet<> &ModuleFiles);
165+
163166
/// \brief Retrieve the set of module files on which the given module file
164167
/// directly depends.
165168
void getModuleDependencies(ModuleFile *File,

interpreter/llvm/src/tools/clang/lib/Serialization/GlobalModuleIndex.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,13 @@ GlobalModuleIndex::getKnownModules(SmallVectorImpl<ModuleFile *> &ModuleFiles) {
269269
}
270270
}
271271

272+
void GlobalModuleIndex::getKnownModuleFileNames(StringSet<> &ModuleFiles) {
273+
ModuleFiles.clear();
274+
for (unsigned I = 0, N = Modules.size(); I != N; ++I) {
275+
ModuleFiles[Modules[I].FileName];
276+
}
277+
}
278+
272279
void GlobalModuleIndex::getModuleDependencies(
273280
ModuleFile *File,
274281
SmallVectorImpl<ModuleFile *> &Dependencies) {

0 commit comments

Comments
 (0)