Lines Matching +full:cancel +full:- +full:in +full:- +full:progress

1 //===--- TUScheduler.cpp -----------------------------------------*-C++-*-===//
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
13 // relevant file. Any request gets queued in FIFO order to be processed by that
20 // ASTWorker processes the file in two parts, a preamble and a main-file
29 // In the presence of stale (non-compatible) preambles, ASTWorker won't publish
32 // preamble. In such cases it will block until new preamble is built.
37 // versions of the file, in case of multiple requests it will only build the
38 // last one and skip requests in between. Unless client force requested
57 #include "clang-include-cleaner/Record.h"
102 // Tracks latency (in seconds) of FS operations done during a preamble build.
162 if (It == LRU.end() || !It->second)
164 return It->second->getUsedBytes();
167 /// Store the value in the pool, possibly removing the last used AST.
168 /// The value should not be in the pool when this function is called.
184 /// Returns the cached value for \p K, or std::nullopt if the value is not in
195 AccessMetric->record(1, "miss");
199 AccessMetric->record(1, "hit");
200 std::unique_ptr<ParsedAST> V = std::move(Existing->second);
217 /// Items sorted in LRU order, i.e. first item is the most recently accessed
225 /// This inclusion information could also naturally live in the index, but there
227 /// - it's easier to achieve a *stable* choice of proxy, which is important
229 /// - context-sensitive flags for libraries with multiple configurations
230 /// (e.g. C++ stdlib sensitivity to -std version)
231 /// - predictable behavior, e.g. guarantees that go-to-def landing on a header
233 /// - fewer scaling problems to solve (project include graphs are big!)
236 /// - We only record this for mainfiles where the command was trustworthy
238 /// - Once we've picked a proxy file for a header, we stick with it until the
242 /// - We don't capture the actual compile command, but just the filename we
245 /// All methods are threadsafe. In practice, update() comes from preamble
255 // Circular-linked-list of associations with the same mainFile.
267 Association *Next = Current->Next;
268 Current->Next = nullptr;
289 First->Next = Prev;
310 // Headers not in the list will have their associations removed.
314 Association *&First = It.first->second;
317 First = associate(It.first->first(), Headers);
399 ID = Throttler->acquire(Filename, [&] {
408 // - if resources are not yet obtained, stop trying to get them.
409 // - if resources were obtained, release them.
412 Throttler->release(ID);
426 /// inputs. If RunSync is true, preambles are built synchronously in update()
458 // dead-lock as we are blocking the caller thread, while builds continue
461 return !NextReq || NextReq->WantDiags != WantDiagnostics::Yes;
489 if (!Throttle->satisfied()) {
495 ReqCV.wait(Lock, [&] { return Throttle->satisfied() || Done; });
507 WithContext Guard(std::move(CurrentReq->Ctx));
555 /// non-null.
641 /// are always for newer versions of the file, as the callback gets called in
667 // Did the main-file content of the document change?
668 // If so, we're allowed to cancel certain invalidated preceding reads.
699 /// Should the first task in the queue be skipped instead of run?
755 /// Guards the callback that publishes results of AST-related computations
759 // out-of-order callbacks for publishing results of onMainAST callback.
772 /// A smart-pointer-like class that points to an active ASTWorker.
773 /// In destructor, signals to the underlying ASTWorker that no new requests will
780 assert(this->Worker);
791 Worker->stop();
799 ASTWorker *operator->() {
825 Tasks->runAsync("ASTWorker:" + llvm::sys::path::filename(FileName),
826 [Worker]() { Worker->run(); });
827 Tasks->runAsync("PreambleWorker:" + llvm::sys::path::filename(FileName),
828 [Worker]() { Worker->PreamblePeer.run(); });
870 // "PreparingBuild" status to inform users, it is non-trivial given the
924 // Remove the old AST if it's still in cache.
1008 // Run the user-provided action.
1034 // to opt in. Use an env var to preserve backwards compatibility of the
1073 LatestBuild->Version, Inputs.Version, FileName);
1079 FileName, Inputs.Version, LatestBuild->Version);
1100 if (isReliable(LatestBuild->CompileCommand))
1101 HeaderIncluders.update(FileName, LatestBuild->Includes.allHeaders());
1140 // more up-to-date diagnostics, and avoids diagnostics going backwards (we
1141 // may have already emitted staler-preamble diagnostics for the new
1145 // Report diagnostics with the new preamble to ensure progress. Otherwise
1196 // FIXME: the AST could actually change if non-preamble includes changed,
1216 auto RebuildDuration = DebouncePolicy::clock::now() - RebuildStartTime;
1218 // Try to record the AST-build time, to inform future update debouncing.
1219 // This is best-effort only: if the lock is held, don't bother.
1222 // Do not let RebuildTimes grow beyond its small-size (i.e.
1263 // queue raced ahead while we were waiting on the preamble. In that case the
1294 // the in-flight requests. We used this information for debugging purposes
1298 Result.UsedBytesPreamble = Preamble->Preamble.getSize();
1344 // Cancel any requests invalidated by this request.
1345 if (Update && Update->ContentChanged) {
1349 if (R.Update && R.Update->ContentChanged)
1362 // Trace the time the request spends in the queue, and the requests that
1372 SPAN_ATTACH(Tracer, "CurrentRequest", CurrentRequest->Name);
1425 Wait.time() - steady_clock::now())
1432 // Any request in ReceivedPreambles is at least as old as the
1444 CurrentRequest->QueueCtx.reset();
1453 Status.ASTActivity.Name = CurrentRequest->Name;
1457 WithContext Guard(std::move(CurrentRequest->Ctx));
1460 Status.ASTActivity.Name = CurrentRequest->Name;
1462 runTask(CurrentRequest->Name, CurrentRequest->Action);
1489 if (!isCancelled(I->Ctx)) {
1491 if (I->Update == std::nullopt)
1496 if (I->Update == std::nullopt) {
1502 // Cancelled updates are downgraded to auto-diagnostics, and may be elided.
1503 if (I->Update->Diagnostics == WantDiagnostics::Yes)
1504 I->Update->Diagnostics = WantDiagnostics::Auto;
1514 // We debounce "maybe-unused" writes, sleeping in case they become dead.
1518 R.Update->Diagnostics == WantDiagnostics::Yes)
1529 auto Update = Next->Update;
1535 if (Next == Requests.end() || !Next->Update)
1538 switch (Update->Diagnostics) {
1546 if (Next->Update && Next->Update->Diagnostics != WantDiagnostics::No)
1576 // Render a TUAction to a user-facing string representation.
1577 // TUAction represents clangd-internal states, we don't intend to expose them
1643 this->Opts.ContextProvider = [](llvm::StringRef) {
1657 // Wait for all in-flight tasks to finish.
1659 PreambleTasks->wait();
1661 WorkerThreads->wait();
1666 if (!File.getValue()->Worker->blockUntilIdle(D))
1669 if (!PreambleTasks->wait(D))
1680 // Create a new worker to process the AST-related tasks.
1687 } else if (FD->Contents != Inputs.Contents) {
1689 FD->Contents = Inputs.Contents;
1691 FD->Worker->update(std::move(Inputs), WantDiags, ContentChanged);
1693 // in such cases.
1733 PreambleTasks->runAsync(Name, [this, &Sem, Ctx = Context::current().clone(),
1750 "trying to get AST for non-added document", ErrorCode::InvalidParams));
1755 It->second->Worker->runWithAST(Name, std::move(Action), Invalidation);
1764 "trying to get preamble for non-added document",
1775 It->second->Worker->getPossiblyStalePreamble(&Signals);
1777 Action(InputsAndPreamble{It->second->Contents,
1778 It->second->Worker->getCurrentCompileCommand(),
1783 std::shared_ptr<const ASTWorker> Worker = It->second->Worker.lock();
1785 Contents = It->second->Contents,
1786 Command = Worker->getCurrentCompileCommand(),
1800 // headers in parallel multiple times.
1801 Worker->waitForFirstPreamble();
1804 Preamble = Worker->getPossiblyStalePreamble(&Signals);
1814 PreambleTasks->runAsync("task:" + llvm::sys::path::filename(File),
1822 PathAndFile.second->Worker->stats());
1829 if (!PathAndFile.second->Worker->isASTCached())
1871 MT.child("header_includer_cache").addUsage(HeaderIncluders->getUsedBytes());