clang-tools  14.0.0git
Background.cpp
Go to the documentation of this file.
1 //===-- Background.cpp - Build an index in a background thread ------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #include "index/Background.h"
10 #include "Compiler.h"
11 #include "Config.h"
12 #include "Headers.h"
13 #include "ParsedAST.h"
14 #include "SourceCode.h"
15 #include "Symbol.h"
16 #include "URI.h"
18 #include "index/FileIndex.h"
19 #include "index/Index.h"
20 #include "index/IndexAction.h"
21 #include "index/MemIndex.h"
22 #include "index/Ref.h"
23 #include "index/Relation.h"
24 #include "index/Serialization.h"
25 #include "index/SymbolCollector.h"
26 #include "support/Context.h"
27 #include "support/Logger.h"
28 #include "support/Path.h"
29 #include "support/Threading.h"
30 #include "support/ThreadsafeFS.h"
31 #include "support/Trace.h"
32 #include "clang/Basic/SourceLocation.h"
33 #include "clang/Basic/SourceManager.h"
34 #include "clang/Driver/Types.h"
35 #include "llvm/ADT/ArrayRef.h"
36 #include "llvm/ADT/DenseSet.h"
37 #include "llvm/ADT/Hashing.h"
38 #include "llvm/ADT/STLExtras.h"
39 #include "llvm/ADT/ScopeExit.h"
40 #include "llvm/ADT/StringMap.h"
41 #include "llvm/ADT/StringRef.h"
42 #include "llvm/ADT/StringSet.h"
43 #include "llvm/Support/Error.h"
44 #include "llvm/Support/Path.h"
45 #include "llvm/Support/Threading.h"
46 #include "llvm/Support/xxhash.h"
47 
48 #include <algorithm>
49 #include <atomic>
50 #include <chrono>
51 #include <condition_variable>
52 #include <cstddef>
53 #include <memory>
54 #include <mutex>
55 #include <numeric>
56 #include <queue>
57 #include <random>
58 #include <string>
59 #include <thread>
60 #include <utility>
61 #include <vector>
62 
63 namespace clang {
64 namespace clangd {
65 namespace {
66 
67 // We cannot use vfs->makeAbsolute because Cmd.FileName is either absolute or
68 // relative to Cmd.Directory, which might not be the same as current working
69 // directory.
70 llvm::SmallString<128> getAbsolutePath(const tooling::CompileCommand &Cmd) {
71  llvm::SmallString<128> AbsolutePath;
72  if (llvm::sys::path::is_absolute(Cmd.Filename)) {
73  AbsolutePath = Cmd.Filename;
74  } else {
75  AbsolutePath = Cmd.Directory;
76  llvm::sys::path::append(AbsolutePath, Cmd.Filename);
77  llvm::sys::path::remove_dots(AbsolutePath, true);
78  }
79  return AbsolutePath;
80 }
81 
82 bool shardIsStale(const LoadedShard &LS, llvm::vfs::FileSystem *FS) {
83  auto Buf = FS->getBufferForFile(LS.AbsolutePath);
84  if (!Buf) {
85  elog("Background-index: Couldn't read {0} to validate stored index: {1}",
86  LS.AbsolutePath, Buf.getError().message());
87  // There is no point in indexing an unreadable file.
88  return false;
89  }
90  return digest(Buf->get()->getBuffer()) != LS.Digest;
91 }
92 
93 } // namespace
94 
96  const ThreadsafeFS &TFS, const GlobalCompilationDatabase &CDB,
97  BackgroundIndexStorage::Factory IndexStorageFactory, Options Opts)
98  : SwapIndex(std::make_unique<MemIndex>()), TFS(TFS), CDB(CDB),
99  ContextProvider(std::move(Opts.ContextProvider)),
100  IndexedSymbols(IndexContents::All),
101  Rebuilder(this, &IndexedSymbols, Opts.ThreadPoolSize),
102  IndexStorageFactory(std::move(IndexStorageFactory)),
103  Queue(std::move(Opts.OnProgress)),
104  CommandsChanged(
105  CDB.watch([&](const std::vector<std::string> &ChangedFiles) {
106  enqueue(ChangedFiles);
107  })) {
108  assert(Opts.ThreadPoolSize > 0 && "Thread pool size can't be zero.");
109  assert(this->IndexStorageFactory && "Storage factory can not be null!");
110  for (unsigned I = 0; I < Opts.ThreadPoolSize; ++I) {
111  ThreadPool.runAsync("background-worker-" + llvm::Twine(I + 1),
112  [this, Ctx(Context::current().clone())]() mutable {
113  WithContext BGContext(std::move(Ctx));
114  Queue.work([&] { Rebuilder.idle(); });
115  });
116  }
117 }
118 
120  stop();
121  ThreadPool.wait();
122 }
123 
124 BackgroundQueue::Task BackgroundIndex::changedFilesTask(
125  const std::vector<std::string> &ChangedFiles) {
126  BackgroundQueue::Task T([this, ChangedFiles] {
127  trace::Span Tracer("BackgroundIndexEnqueue");
128 
129  llvm::Optional<WithContext> WithProvidedContext;
130  if (ContextProvider)
131  WithProvidedContext.emplace(ContextProvider(/*Path=*/""));
132 
133  // We're doing this asynchronously, because we'll read shards here too.
134  log("Enqueueing {0} commands for indexing", ChangedFiles.size());
135  SPAN_ATTACH(Tracer, "files", int64_t(ChangedFiles.size()));
136 
137  auto NeedsReIndexing = loadProject(std::move(ChangedFiles));
138  // Run indexing for files that need to be updated.
139  std::shuffle(NeedsReIndexing.begin(), NeedsReIndexing.end(),
140  std::mt19937(std::random_device{}()));
141  std::vector<BackgroundQueue::Task> Tasks;
142  Tasks.reserve(NeedsReIndexing.size());
143  for (const auto &File : NeedsReIndexing)
144  Tasks.push_back(indexFileTask(std::move(File)));
145  Queue.append(std::move(Tasks));
146  });
147 
148  T.QueuePri = LoadShards;
149  T.ThreadPri = llvm::ThreadPriority::Default;
150  return T;
151 }
152 
153 static llvm::StringRef filenameWithoutExtension(llvm::StringRef Path) {
154  Path = llvm::sys::path::filename(Path);
155  return Path.drop_back(llvm::sys::path::extension(Path).size());
156 }
157 
158 BackgroundQueue::Task BackgroundIndex::indexFileTask(std::string Path) {
159  std::string Tag = filenameWithoutExtension(Path).str();
160  uint64_t Key = llvm::xxHash64(Path);
161  BackgroundQueue::Task T([this, Path(std::move(Path))] {
162  llvm::Optional<WithContext> WithProvidedContext;
163  if (ContextProvider)
164  WithProvidedContext.emplace(ContextProvider(Path));
165  auto Cmd = CDB.getCompileCommand(Path);
166  if (!Cmd)
167  return;
168  if (auto Error = index(std::move(*Cmd)))
169  elog("Indexing {0} failed: {1}", Path, std::move(Error));
170  });
171  T.QueuePri = IndexFile;
172  T.Tag = std::move(Tag);
173  T.Key = Key;
174  return T;
175 }
176 
177 void BackgroundIndex::boostRelated(llvm::StringRef Path) {
178  if (isHeaderFile(Path))
179  Queue.boost(filenameWithoutExtension(Path), IndexBoostedFile);
180 }
181 
182 /// Given index results from a TU, only update symbols coming from files that
183 /// are different or missing from than \p ShardVersionsSnapshot. Also stores new
184 /// index information on IndexStorage.
185 void BackgroundIndex::update(
186  llvm::StringRef MainFile, IndexFileIn Index,
187  const llvm::StringMap<ShardVersion> &ShardVersionsSnapshot,
188  bool HadErrors) {
189  // Keys are URIs.
190  llvm::StringMap<std::pair<Path, FileDigest>> FilesToUpdate;
191  // Note that sources do not contain any information regarding missing headers,
192  // since we don't even know what absolute path they should fall in.
193  for (const auto &IndexIt : *Index.Sources) {
194  const auto &IGN = IndexIt.getValue();
195  auto AbsPath = URI::resolve(IGN.URI, MainFile);
196  if (!AbsPath) {
197  elog("Failed to resolve URI: {0}", AbsPath.takeError());
198  continue;
199  }
200  const auto DigestIt = ShardVersionsSnapshot.find(*AbsPath);
201  // File has different contents, or indexing was successful this time.
202  if (DigestIt == ShardVersionsSnapshot.end() ||
203  DigestIt->getValue().Digest != IGN.Digest ||
204  (DigestIt->getValue().HadErrors && !HadErrors))
205  FilesToUpdate[IGN.URI] = {std::move(*AbsPath), IGN.Digest};
206  }
207 
208  // Shard slabs into files.
209  FileShardedIndex ShardedIndex(std::move(Index));
210 
211  // Build and store new slabs for each updated file.
212  for (const auto &FileIt : FilesToUpdate) {
213  auto Uri = FileIt.first();
214  auto IF = ShardedIndex.getShard(Uri);
215  assert(IF && "no shard for file in Index.Sources?");
216  PathRef Path = FileIt.getValue().first;
217 
218  // Only store command line hash for main files of the TU, since our
219  // current model keeps only one version of a header file.
220  if (Path != MainFile)
221  IF->Cmd.reset();
222 
223  // We need to store shards before updating the index, since the latter
224  // consumes slabs.
225  // FIXME: Also skip serializing the shard if it is already up-to-date.
226  if (auto Error = IndexStorageFactory(Path)->storeShard(Path, *IF))
227  elog("Failed to write background-index shard for file {0}: {1}", Path,
228  std::move(Error));
229 
230  {
231  std::lock_guard<std::mutex> Lock(ShardVersionsMu);
232  const auto &Hash = FileIt.getValue().second;
233  auto DigestIt = ShardVersions.try_emplace(Path);
234  ShardVersion &SV = DigestIt.first->second;
235  // Skip if file is already up to date, unless previous index was broken
236  // and this one is not.
237  if (!DigestIt.second && SV.Digest == Hash && SV.HadErrors && !HadErrors)
238  continue;
239  SV.Digest = Hash;
240  SV.HadErrors = HadErrors;
241 
242  // This can override a newer version that is added in another thread, if
243  // this thread sees the older version but finishes later. This should be
244  // rare in practice.
245  IndexedSymbols.update(
246  Uri, std::make_unique<SymbolSlab>(std::move(*IF->Symbols)),
247  std::make_unique<RefSlab>(std::move(*IF->Refs)),
248  std::make_unique<RelationSlab>(std::move(*IF->Relations)),
249  Path == MainFile);
250  }
251  }
252 }
253 
254 llvm::Error BackgroundIndex::index(tooling::CompileCommand Cmd) {
255  trace::Span Tracer("BackgroundIndex");
256  SPAN_ATTACH(Tracer, "file", Cmd.Filename);
257  auto AbsolutePath = getAbsolutePath(Cmd);
258 
259  auto FS = TFS.view(Cmd.Directory);
260  auto Buf = FS->getBufferForFile(AbsolutePath);
261  if (!Buf)
262  return llvm::errorCodeToError(Buf.getError());
263  auto Hash = digest(Buf->get()->getBuffer());
264 
265  // Take a snapshot of the versions to avoid locking for each file in the TU.
266  llvm::StringMap<ShardVersion> ShardVersionsSnapshot;
267  {
268  std::lock_guard<std::mutex> Lock(ShardVersionsMu);
269  ShardVersionsSnapshot = ShardVersions;
270  }
271 
272  vlog("Indexing {0} (digest:={1})", Cmd.Filename, llvm::toHex(Hash));
273  ParseInputs Inputs;
274  Inputs.TFS = &TFS;
275  Inputs.CompileCommand = std::move(Cmd);
276  IgnoreDiagnostics IgnoreDiags;
278  if (!CI)
279  return error("Couldn't build compiler invocation");
280 
281  auto Clang =
282  prepareCompilerInstance(std::move(CI), /*Preamble=*/nullptr,
283  std::move(*Buf), std::move(FS), IgnoreDiags);
284  if (!Clang)
285  return error("Couldn't build compiler instance");
286 
287  SymbolCollector::Options IndexOpts;
288  // Creates a filter to not collect index results from files with unchanged
289  // digests.
290  IndexOpts.FileFilter = [&ShardVersionsSnapshot](const SourceManager &SM,
291  FileID FID) {
292  const auto *F = SM.getFileEntryForID(FID);
293  if (!F)
294  return false; // Skip invalid files.
295  auto AbsPath = getCanonicalPath(F, SM);
296  if (!AbsPath)
297  return false; // Skip files without absolute path.
298  auto Digest = digestFile(SM, FID);
299  if (!Digest)
300  return false;
301  auto D = ShardVersionsSnapshot.find(*AbsPath);
302  if (D != ShardVersionsSnapshot.end() && D->second.Digest == Digest &&
303  !D->second.HadErrors)
304  return false; // Skip files that haven't changed, without errors.
305  return true;
306  };
307  IndexOpts.CollectMainFileRefs = true;
308 
309  IndexFileIn Index;
311  IndexOpts, [&](SymbolSlab S) { Index.Symbols = std::move(S); },
312  [&](RefSlab R) { Index.Refs = std::move(R); },
313  [&](RelationSlab R) { Index.Relations = std::move(R); },
314  [&](IncludeGraph IG) { Index.Sources = std::move(IG); });
315 
316  // We're going to run clang here, and it could potentially crash.
317  // We could use CrashRecoveryContext to try to make indexing crashes nonfatal,
318  // but the leaky "recovery" is pretty scary too in a long-running process.
319  // If crashes are a real problem, maybe we should fork a child process.
320 
321  const FrontendInputFile &Input = Clang->getFrontendOpts().Inputs.front();
322  if (!Action->BeginSourceFile(*Clang, Input))
323  return error("BeginSourceFile() failed");
324  if (llvm::Error Err = Action->Execute())
325  return Err;
326 
327  Action->EndSourceFile();
328 
329  Index.Cmd = Inputs.CompileCommand;
330  assert(Index.Symbols && Index.Refs && Index.Sources &&
331  "Symbols, Refs and Sources must be set.");
332 
333  log("Indexed {0} ({1} symbols, {2} refs, {3} files)",
334  Inputs.CompileCommand.Filename, Index.Symbols->size(),
335  Index.Refs->numRefs(), Index.Sources->size());
336  SPAN_ATTACH(Tracer, "symbols", int(Index.Symbols->size()));
337  SPAN_ATTACH(Tracer, "refs", int(Index.Refs->numRefs()));
338  SPAN_ATTACH(Tracer, "sources", int(Index.Sources->size()));
339 
340  bool HadErrors = Clang->hasDiagnostics() &&
341  Clang->getDiagnostics().hasUncompilableErrorOccurred();
342  if (HadErrors) {
343  log("Failed to compile {0}, index may be incomplete", AbsolutePath);
344  for (auto &It : *Index.Sources)
345  It.second.Flags |= IncludeGraphNode::SourceFlag::HadErrors;
346  }
347  update(AbsolutePath, std::move(Index), ShardVersionsSnapshot, HadErrors);
348 
349  Rebuilder.indexedTU();
350  return llvm::Error::success();
351 }
352 
353 // Restores shards for \p MainFiles from index storage. Then checks staleness of
354 // those shards and returns a list of TUs that needs to be indexed to update
355 // staleness.
356 std::vector<std::string>
357 BackgroundIndex::loadProject(std::vector<std::string> MainFiles) {
358  // Drop files where background indexing is disabled in config.
359  if (ContextProvider)
360  llvm::erase_if(MainFiles, [&](const std::string &TU) {
361  // Load the config for each TU, as indexing may be selectively enabled.
362  WithContext WithProvidedContext(ContextProvider(TU));
363  return Config::current().Index.Background ==
365  });
366  Rebuilder.startLoading();
367  // Load shards for all of the mainfiles.
368  const std::vector<LoadedShard> Result =
369  loadIndexShards(MainFiles, IndexStorageFactory, CDB);
370  size_t LoadedShards = 0;
371  {
372  // Update in-memory state.
373  std::lock_guard<std::mutex> Lock(ShardVersionsMu);
374  for (auto &LS : Result) {
375  if (!LS.Shard)
376  continue;
377  auto SS =
378  LS.Shard->Symbols
379  ? std::make_unique<SymbolSlab>(std::move(*LS.Shard->Symbols))
380  : nullptr;
381  auto RS = LS.Shard->Refs
382  ? std::make_unique<RefSlab>(std::move(*LS.Shard->Refs))
383  : nullptr;
384  auto RelS =
385  LS.Shard->Relations
386  ? std::make_unique<RelationSlab>(std::move(*LS.Shard->Relations))
387  : nullptr;
388  ShardVersion &SV = ShardVersions[LS.AbsolutePath];
389  SV.Digest = LS.Digest;
390  SV.HadErrors = LS.HadErrors;
391  ++LoadedShards;
392 
393  IndexedSymbols.update(URI::create(LS.AbsolutePath).toString(),
394  std::move(SS), std::move(RS), std::move(RelS),
395  LS.CountReferences);
396  }
397  }
398  Rebuilder.loadedShard(LoadedShards);
399  Rebuilder.doneLoading();
400 
401  auto FS = TFS.view(/*CWD=*/llvm::None);
402  llvm::DenseSet<PathRef> TUsToIndex;
403  // We'll accept data from stale shards, but ensure the files get reindexed
404  // soon.
405  for (auto &LS : Result) {
406  if (!shardIsStale(LS, FS.get()))
407  continue;
408  PathRef TUForFile = LS.DependentTU;
409  assert(!TUForFile.empty() && "File without a TU!");
410 
411  // FIXME: Currently, we simply schedule indexing on a TU whenever any of
412  // its dependencies needs re-indexing. We might do it smarter by figuring
413  // out a minimal set of TUs that will cover all the stale dependencies.
414  // FIXME: Try looking at other TUs if no compile commands are available
415  // for this TU, i.e TU was deleted after we performed indexing.
416  TUsToIndex.insert(TUForFile);
417  }
418 
419  return {TUsToIndex.begin(), TUsToIndex.end()};
420 }
421 
423  IndexedSymbols.profile(MT.child("slabs"));
424  // We don't want to mix memory used by index and symbols, so call base class.
426 }
427 } // namespace clangd
428 } // namespace clang
clang::clangd::BackgroundQueue::Task
A work item on the thread pool's queue.
Definition: Background.h:72
clang::clangd::MemoryTree::child
MemoryTree & child(llvm::StringLiteral Name)
No copy of the Name.
Definition: MemoryTree.h:41
Headers.h
IndexAction.h
Background.h
clang::clangd::digest
FileDigest digest(llvm::StringRef Content)
Definition: SourceCode.cpp:562
clang::clangd::prepareCompilerInstance
std::unique_ptr< CompilerInstance > prepareCompilerInstance(std::unique_ptr< clang::CompilerInvocation > CI, const PrecompiledPreamble *Preamble, std::unique_ptr< llvm::MemoryBuffer > Buffer, llvm::IntrusiveRefCntPtr< llvm::vfs::FileSystem > VFS, DiagnosticConsumer &DiagsClient)
Definition: Compiler.cpp:110
clang::clangd::Config::BackgroundPolicy::Skip
@ Skip
clang::clangd::AsyncTaskRunner::wait
void wait() const
Definition: Threading.h:111
clang::clangd::Path
std::string Path
A typedef to represent a file path.
Definition: Path.h:26
clang::clangd::IndexFileIn
Definition: Serialization.h:42
clang::clangd::Config::Index
struct clang::clangd::Config::@3 Index
Controls background-index behavior.
Tracer
std::unique_ptr< trace::EventTracer > Tracer
Definition: TraceTests.cpp:164
clang::clangd::error
llvm::Error error(std::error_code EC, const char *Fmt, Ts &&... Vals)
Definition: Logger.h:80
Path.h
clang::clangd::Context::current
static const Context & current()
Returns the context for the current thread, creating it if needed.
Definition: Context.cpp:27
clang::clangd::BackgroundQueue::append
void append(std::vector< Task >)
Definition: BackgroundQueue.cpp:101
clang::clangd::SwapIndex
Definition: Index.h:161
Index.h
CI
std::unique_ptr< CompilerInvocation > CI
Definition: TUScheduler.cpp:454
clang::clangd::URI::create
static llvm::Expected< URI > create(llvm::StringRef AbsolutePath, llvm::StringRef Scheme)
Creates a URI for a file in the given scheme.
Definition: URI.cpp:211
Ctx
Context Ctx
Definition: TUScheduler.cpp:458
clang::clangd::BackgroundIndexRebuilder::doneLoading
void doneLoading()
Definition: BackgroundRebuild.cpp:89
Trace.h
clang::clangd::BackgroundQueue::work
void work(std::function< void()> OnIdle=nullptr)
Definition: BackgroundQueue.cpp:21
clang::clangd::BackgroundIndexRebuilder::indexedTU
void indexedTU()
Definition: BackgroundRebuild.cpp:59
clang::clangd::GlobalCompilationDatabase::getCompileCommand
virtual llvm::Optional< tooling::CompileCommand > getCompileCommand(PathRef File) const =0
If there are any known-good commands for building this file, returns one.
clang::clangd::GlobalCompilationDatabase
Provides compilation arguments used for parsing C and C++ files.
Definition: GlobalCompilationDatabase.h:36
Action
llvm::unique_function< void()> Action
Definition: TUScheduler.cpp:600
clang::clangd::loadIndexShards
std::vector< LoadedShard > loadIndexShards(llvm::ArrayRef< Path > MainFiles, BackgroundIndexStorage::Factory &IndexStorageFactory, const GlobalCompilationDatabase &CDB)
Loads all shards for the TU MainFile from Storage.
Definition: BackgroundIndexLoader.cpp:123
ThreadsafeFS.h
Inputs
ParseInputs Inputs
Definition: TUScheduler.cpp:455
clang::clangd::URI::resolve
static llvm::Expected< std::string > resolve(const URI &U, llvm::StringRef HintPath="")
Resolves the absolute path of U.
Definition: URI.cpp:247
clang::clangd::MemoryTree::addUsage
void addUsage(size_t Increment)
Increases size of current node by Increment.
Definition: MemoryTree.h:58
Relation.h
MemIndex.h
clang::clangd::BackgroundIndexRebuilder::idle
void idle()
Definition: BackgroundRebuild.cpp:70
ns1::ns2::D
@ D
Definition: CategoricalFeature.h:3
clang::clangd::BackgroundIndex::boostRelated
void boostRelated(llvm::StringRef Path)
Boosts priority of indexing related to Path.
Definition: Background.cpp:177
clang::clangd::getCanonicalPath
llvm::Optional< std::string > getCanonicalPath(const FileEntry *F, const SourceManager &SourceMgr)
Get the canonical path of F.
Definition: SourceCode.cpp:514
clang::clangd::MemoryTree
A tree that can be used to represent memory usage of nested components while preserving the hierarchy...
Definition: MemoryTree.h:32
clang::clangd::BackgroundQueue::boost
void boost(llvm::StringRef Tag, unsigned NewPriority)
Definition: BackgroundQueue.cpp:116
Logger.h
Threading.h
clang::clangd::IndexContents
IndexContents
Describes what data is covered by an index.
Definition: Index.h:91
clang::clangd::FileSymbols::update
void update(llvm::StringRef Key, std::unique_ptr< SymbolSlab > Symbols, std::unique_ptr< RefSlab > Refs, std::unique_ptr< RelationSlab > Relations, bool CountReferences)
Updates all slabs associated with the Key.
Definition: FileIndex.cpp:242
SPAN_ATTACH
#define SPAN_ATTACH(S, Name, Expr)
Attach a key-value pair to a Span event.
Definition: Trace.h:164
Serialization.h
clang::clangd::vlog
void vlog(const char *Fmt, Ts &&... Vals)
Definition: Logger.h:73
clang::clangd::FileSymbols::profile
void profile(MemoryTree &MT) const
Definition: FileIndex.cpp:400
clang::clangd::MemIndex
MemIndex is a naive in-memory index suitable for a small set of symbols.
Definition: MemIndex.h:20
FileIndex.h
clang::clangd::WithContext
WithContext replaces Context::current() with a provided scope.
Definition: Context.h:187
clang::clangd::BackgroundIndex::enqueue
void enqueue(const std::vector< std::string > &ChangedFiles)
Definition: Background.h:158
Symbol.h
clang::clangd::Config::Background
BackgroundPolicy Background
Whether this TU should be indexed.
Definition: Config.h:85
clang::clangd::log
void log(const char *Fmt, Ts &&... Vals)
Definition: Logger.h:68
clang::clangd::buildCompilerInvocation
std::unique_ptr< CompilerInvocation > buildCompilerInvocation(const ParseInputs &Inputs, clang::DiagnosticConsumer &D, std::vector< std::string > *CC1Args)
Builds compiler invocation that could be used to build AST or preamble.
Definition: Compiler.cpp:84
clang::clangd::BackgroundIndex::Options
Definition: Background.h:136
SourceCode.h
Index
const SymbolIndex * Index
Definition: Dexp.cpp:99
Config.h
Compiler.h
clang::clangd::isHeaderFile
bool isHeaderFile(llvm::StringRef FileName, llvm::Optional< LangOptions > LangOpts)
Infers whether this is a header from the FileName and LangOpts (if presents).
Definition: SourceCode.cpp:1159
clang::clangd::BackgroundIndexStorage::Factory
llvm::unique_function< BackgroundIndexStorage *(PathRef)> Factory
Definition: Background.h:58
clang::clangd::IncludeGraphNode::SourceFlag::HadErrors
@ HadErrors
BackgroundIndexLoader.h
clang::clangd::PathRef
llvm::StringRef PathRef
A typedef to represent a ref to file path.
Definition: Path.h:29
clang::clangd::ThreadsafeFS
Wrapper for vfs::FileSystem for use in multithreaded programs like clangd.
Definition: ThreadsafeFS.h:28
clang::clangd::ThreadsafeFS::view
llvm::IntrusiveRefCntPtr< llvm::vfs::FileSystem > view(llvm::NoneType CWD) const
Obtain a vfs::FileSystem with an arbitrary initial working directory.
Definition: ThreadsafeFS.h:34
clang::clangd::AsyncTaskRunner::runAsync
void runAsync(const llvm::Twine &Name, llvm::unique_function< void()> Action)
Definition: Threading.cpp:73
clang::clangd::digestFile
llvm::Optional< FileDigest > digestFile(const SourceManager &SM, FileID FID)
Definition: SourceCode.cpp:572
Ref.h
clang
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Definition: ApplyReplacements.h:27
clang::clangd::BackgroundIndex::BackgroundIndex
BackgroundIndex(const ThreadsafeFS &, const GlobalCompilationDatabase &CDB, BackgroundIndexStorage::Factory IndexStorageFactory, Options Opts)
Creates a new background index and starts its threads.
Definition: Background.cpp:95
clang::clangd::Config::current
static const Config & current()
Returns the Config of the current Context, or an empty configuration.
Definition: Config.cpp:17
clang::clangd::SwapIndex::estimateMemoryUsage
size_t estimateMemoryUsage() const override
Returns estimated size of index (in bytes).
Definition: Index.cpp:90
clang::clangd::IncludeGraph
llvm::StringMap< IncludeGraphNode > IncludeGraph
Definition: Headers.h:90
SM
const SourceManager & SM
Definition: IncludeCleaner.cpp:108
clang::clangd::BackgroundQueue::Task::QueuePri
unsigned QueuePri
Definition: Background.h:77
SymbolCollector.h
MainFile
std::string MainFile
Definition: HeadersTests.cpp:136
URI.h
clang::clangd::BackgroundIndexRebuilder::loadedShard
void loadedShard(size_t ShardCount)
Definition: BackgroundRebuild.cpp:84
clang::clangd::BackgroundIndex::stop
void stop()
Definition: Background.h:168
clang::clangd::elog
void elog(const char *Fmt, Ts &&... Vals)
Definition: Logger.h:62
Tag
HTMLTag Tag
Definition: HTMLGenerator.cpp:90
clang::clangd::BackgroundIndex::profile
void profile(MemoryTree &MT) const
Definition: Background.cpp:422
IgnoreDiags
IgnoringDiagConsumer IgnoreDiags
Definition: HeadersTests.cpp:139
clang::clangd::filenameWithoutExtension
static llvm::StringRef filenameWithoutExtension(llvm::StringRef Path)
Definition: Background.cpp:153
clang::clangd::BackgroundIndex::~BackgroundIndex
~BackgroundIndex()
Definition: Background.cpp:119
Clang
std::unique_ptr< CompilerInstance > Clang
Definition: HeadersTests.cpp:140
clang::clangd::createStaticIndexingAction
std::unique_ptr< FrontendAction > createStaticIndexingAction(SymbolCollector::Options Opts, std::function< void(SymbolSlab)> SymbolsCallback, std::function< void(RefSlab)> RefsCallback, std::function< void(RelationSlab)> RelationsCallback, std::function< void(IncludeGraph)> IncludeGraphCallback)
Definition: IndexAction.cpp:214
clang::clangd::BackgroundIndexRebuilder::startLoading
void startLoading()
Definition: BackgroundRebuild.cpp:78
Context.h
ParsedAST.h
clang::clangd::trace::Span
Records an event whose duration is the lifetime of the Span object.
Definition: Trace.h:143