[clang-tools-extra] r338378 - [clangd] Do not build AST if no diagnostics were requested

Ilya Biryukov via cfe-commits cfe-commits at lists.llvm.org
Tue Jul 31 06:45:38 PDT 2018


Author: ibiryukov
Date: Tue Jul 31 06:45:37 2018
New Revision: 338378

URL: http://llvm.org/viewvc/llvm-project?rev=338378&view=rev
Log:
[clangd] Do not build AST if no diagnostics were requested

Summary:
It can be removed from the cache before the first access anyway, so
building it can be a waste of time.

Reviewers: ioeric

Reviewed By: ioeric

Subscribers: javed.absar, MaskRay, jkorous, arphaman, cfe-commits

Differential Revision: https://reviews.llvm.org/D49991

Modified:
    clang-tools-extra/trunk/clangd/TUScheduler.cpp

Modified: clang-tools-extra/trunk/clangd/TUScheduler.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/TUScheduler.cpp?rev=338378&r1=338377&r2=338378&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/TUScheduler.cpp (original)
+++ clang-tools-extra/trunk/clangd/TUScheduler.cpp Tue Jul 31 06:45:37 2018
@@ -391,6 +391,10 @@ void ASTWorker::update(
       }
     }
 
+    // We only need to build the AST if diagnostics were requested.
+    if (WantDiags == WantDiagnostics::No)
+      return;
+
     // Get the AST for diagnostics.
     llvm::Optional<std::unique_ptr<ParsedAST>> AST = IdleASTs.take(this);
     if (!AST) {
@@ -398,12 +402,11 @@ void ASTWorker::update(
           buildAST(FileName, std::move(Invocation), Inputs, NewPreamble, PCHs);
       AST = NewAST ? llvm::make_unique<ParsedAST>(std::move(*NewAST)) : nullptr;
     }
-
     // We want to report the diagnostics even if this update was cancelled.
     // It seems more useful than making the clients wait indefinitely if they
     // spam us with updates.
     // Note *AST can be still be null if buildAST fails.
-    if (WantDiags != WantDiagnostics::No && *AST) {
+    if (*AST) {
       OnUpdated((*AST)->getDiagnostics());
       DiagsWereReported = true;
     }




More information about the cfe-commits mailing list