[clang-tools-extra] [clangd] [C++20] [Modules] Add scanning cache (PR #125988)

Chuanqi Xu via cfe-commits cfe-commits at lists.llvm.org
Thu Feb 6 19:44:51 PST 2025


ChuanqiXu9 wrote:

> instead of introducing a new concept of `ProjectModulesCache` and requiring each `ProjectModules` implementation to know about it and work with it; what about introducing a:
> 
> ```c++
> class CachingProjectModules : public ProjectModules {
> public:
>   CachingProjectModules(GlobalCompilationDatabase &CDB);
>   // Implements rest of the operations with a cache overlay.
>   ...;
>   // Whenever cache is invalid/empty, queries `CDB` for underlying `ProjectModules`
>   // and updates/builds a cache using it.
> };
> ```
> 
> into `ModulesBuilder.cpp` and have an instance of this in `ModulesBuilderImpl`? That way we can centralize how the caching will work and won't need to maintain multiple implementations that play with it.
> 
> As for cache validation, i think it's fine to invalidate based on file contents and whenever there's a mismatch we can query `CDB` again.
> 
> WDYT?

It sounds good but it has a small problem that:

- Now the ScanningProjectModules are owned by different calls to `ModulesBuilder::buildPrerequisiteModulesFor`. So we don't need to care about thread safety in ScanningProjectModules. And if we make it the underlying ProjectModules, we need to care about the thead safety and then we would have a centralized scanner. It is not bad but it might be a bigger change.

https://github.com/llvm/llvm-project/pull/125988


More information about the cfe-commits mailing list