clang-tools 22.0.0git
clang::clangd::TUScheduler::HeaderIncluderCache Class Reference

A map from header files to an opened "proxy" file that includes them. More...

Public Member Functions

 HeaderIncluderCache ()
void update (PathRef MainFile, llvm::ArrayRef< std::string > Headers)
void remove (PathRef MainFile)
std::string get (PathRef Header) const
 Get the mainfile associated with Header, or the empty string if none.
size_t getUsedBytes () const

Detailed Description

A map from header files to an opened "proxy" file that includes them.

If you open the header, the compile command from the proxy file is used.

This inclusion information could also naturally live in the index, but there are advantages to using open files instead:

  • it's easier to achieve a stable choice of proxy, which is important to avoid invalidating the preamble
  • context-sensitive flags for libraries with multiple configurations (e.g. C++ stdlib sensitivity to -std version)
  • predictable behavior, e.g. guarantees that go-to-def landing on a header will have a suitable command available
  • fewer scaling problems to solve (project include graphs are big!)

Implementation details:

  • We only record this for mainfiles where the command was trustworthy (i.e. not inferred). This avoids a bad inference "infecting" other files.
  • Once we've picked a proxy file for a header, we stick with it until the proxy file is invalidated and a new candidate proxy file is built. Switching proxies is expensive, as the compile flags will (probably) change and therefore we'll end up rebuilding the header's preamble.
  • We don't capture the actual compile command, but just the filename we should query to get it. This avoids getting out of sync with the CDB.

All methods are threadsafe. In practice, update() comes from preamble threads, remove()s mostly from the main thread, and get() from ASTWorker. Writes are rare and reads are cheap, so we don't expect much contention.

Definition at line 248 of file TUScheduler.cpp.

Constructor & Destructor Documentation

◆ HeaderIncluderCache()

clang::clangd::TUScheduler::HeaderIncluderCache::HeaderIncluderCache ( )
inline

Definition at line 305 of file TUScheduler.cpp.

Member Function Documentation

◆ get()

std::string clang::clangd::TUScheduler::HeaderIncluderCache::get ( PathRef Header) const
inline

Get the mainfile associated with Header, or the empty string if none.

Definition at line 336 of file TUScheduler.cpp.

◆ getUsedBytes()

size_t clang::clangd::TUScheduler::HeaderIncluderCache::getUsedBytes ( ) const
inline

Definition at line 341 of file TUScheduler.cpp.

◆ remove()

void clang::clangd::TUScheduler::HeaderIncluderCache::remove ( PathRef MainFile)
inline

Definition at line 324 of file TUScheduler.cpp.

◆ update()

void clang::clangd::TUScheduler::HeaderIncluderCache::update ( PathRef MainFile,
llvm::ArrayRef< std::string > Headers )
inline

Definition at line 311 of file TUScheduler.cpp.


The documentation for this class was generated from the following file: