[clang-tools-extra] [clangd] [Modules] Support Reusable Modules Builder (PR #106683)
kadir çetinkaya via cfe-commits
cfe-commits at lists.llvm.org
Mon Oct 21 08:17:34 PDT 2024
================
@@ -85,19 +85,20 @@ class PrerequisiteModules {
/// different versions and different source files.
class ModulesBuilder {
----------------
kadircet wrote:
can we just introduce a new helper class
```cpp
class ModulesBuilder {
...
private:
class ModuleFileCache;
std::unique_ptr<ModuleFileCache> MFCache;
};
```
in `ModulesBuilder.cpp`:
```cpp
class ModuleFileCache {
private:
std::mutex CacheMu;
StringMap<std::weak_ptr<ModuleFile>> Cache;
public:
// Returns cahed `ModuleName` if one exists and it's up-to-date per BuiltModuleFiles.
// It's a prereq for BuiltModuleFiles to contain all the prereqs of ModuleName (i.e. this function is not recursive)
std::shared_ptr<ModuleFile> getOrBuildModule(llvm::StringRef ModuleName,
const GlobalCompilationDatabase &CDB,
const ThreadsafeFS &TFS, ProjectModules &MDB,
PathRef ModuleFilesPrefix,
StandalonePrerequisiteModules &BuiltModuleFiles);
};
```
Afterwards we can keep most of the logic as-is. we just need to update `buildModuleFile` to take in a `ModuleFileCache&` as a parameter and call `ModuleFileCache::getOrBuildModule` instead of building one itself.
We also need to verify freshness of a module-file we're going to return from cache in `getOrBuildModule`, we can do so efficiently by only verifying the sources that are directly part of `ModuleName` and not the transitive closure (we can assume all the deps were already checked when putting `BuiltModuleFiles` together).
You can store a pointer to `ModuleFileCache` in `ModuleFile` to trigger deletion from map on destruction of `ModuleFile`s.
https://github.com/llvm/llvm-project/pull/106683
More information about the cfe-commits
mailing list