Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
[cxxmodules] Also load STL/libc as a core module
Without modules, many STL and libc headers are automatically
provided by ROOT via the attached ROOT PCH. This means that
we don't need to have autloading or explicit includes for STL
or libc headers when running with the PCH attached. This leads
to making user code like this working in ROOT:

```C++
// no includes here that provides assert
int foo() {
  assert(false);
}
```

However, as the modules don't come with this big PCH, we
are now suddenly in the situation where we can't resolve
things such as `assert`. We also can't rely on the
normal autoloading of ROOT as those declarations were
actually never autoloaded, but just provided by the PCH.

To simulate this behavior with modules, we automatically load
those headers that we expect to have in the ROOT PCH
(which are probably the STL and libc headers).
  • Loading branch information
Teemperor committed Nov 14, 2017
commit 72ab9612a750292a5767861d17616e4e431024a3
13 changes: 12 additions & 1 deletion core/metacling/src/TCling.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1101,19 +1101,30 @@ static void LoadCoreModules(cling::Interpreter &interp)

clang::HeaderSearch &headerSearch = CI.getPreprocessor().getHeaderSearchInfo();
clang::ModuleMap &moduleMap = headerSearch.getModuleMap();
// List of core modules we can load, but it's ok if they are missing because
// the system doesn't have these modules.
std::vector<std::string> optionalCoreModuleNames = {"stl", "libc"};

// List of core modules we need to load.
std::vector<std::string> neededCoreModuleNames = {"Core", "RIO"};
std::vector<std::string> missingCoreModuleNames;

std::vector<clang::Module *> coreModules;

// Lookup the optional core modules in the modulemap by name.
for (std::string moduleName : optionalCoreModuleNames) {
clang::Module *module = moduleMap.findModule(moduleName);
// Don't report an error here, the module is optional.
if (module)
coreModules.push_back(module);
}
// Lookup the core modules in the modulemap by name.
for (std::string moduleName : neededCoreModuleNames) {
clang::Module *module = moduleMap.findModule(moduleName);
if (module) {
coreModules.push_back(module);
} else {
// If we can't find a module, we record that to report it later.
// If we can't find a needed module, we record that to report it later.
missingCoreModuleNames.push_back(moduleName);
}
}
Expand Down