[clang-tools-extra] ecd3e67 - [clangd] Populate PreambleData::CompileCommand and make use of it inside buildPreamble
Kadir Cetinkaya via cfe-commits
cfe-commits at lists.llvm.org
Fri Mar 13 01:44:49 PDT 2020
Author: Kadir Cetinkaya
Date: 2020-03-13T09:40:47+01:00
New Revision: ecd3e678bbb11cf899603037ec2c5949b8d7fa6c
URL: https://github.com/llvm/llvm-project/commit/ecd3e678bbb11cf899603037ec2c5949b8d7fa6c
DIFF: https://github.com/llvm/llvm-project/commit/ecd3e678bbb11cf899603037ec2c5949b8d7fa6c.diff
LOG: [clangd] Populate PreambleData::CompileCommand and make use of it inside buildPreamble
Reviewers: sammccall
Subscribers: ilya-biryukov, javed.absar, MaskRay, jkorous, arphaman, usaxena95, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D75996
Added:
Modified:
clang-tools-extra/clangd/Preamble.cpp
clang-tools-extra/clangd/Preamble.h
clang-tools-extra/clangd/TUScheduler.cpp
clang-tools-extra/clangd/unittests/FileIndexTests.cpp
clang-tools-extra/clangd/unittests/TestTU.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/clangd/Preamble.cpp b/clang-tools-extra/clangd/Preamble.cpp
index 86fa7905a61e..bd92b8c1bdb4 100644
--- a/clang-tools-extra/clangd/Preamble.cpp
+++ b/clang-tools-extra/clangd/Preamble.cpp
@@ -7,6 +7,7 @@
//===----------------------------------------------------------------------===//
#include "Preamble.h"
+#include "Compiler.h"
#include "Logger.h"
#include "Trace.h"
#include "clang/Basic/SourceLocation.h"
@@ -75,13 +76,14 @@ class CppFilePreambleCallbacks : public PreambleCallbacks {
} // namespace
-PreambleData::PreambleData(llvm::StringRef Version,
+PreambleData::PreambleData(const ParseInputs &Inputs,
PrecompiledPreamble Preamble,
std::vector<Diag> Diags, IncludeStructure Includes,
MainFileMacros Macros,
std::unique_ptr<PreambleFileStatusCache> StatCache,
CanonicalIncludes CanonIncludes)
- : Version(Version), Preamble(std::move(Preamble)), Diags(std::move(Diags)),
+ : Version(Inputs.Version), CompileCommand(Inputs.CompileCommand),
+ Preamble(std::move(Preamble)), Diags(std::move(Diags)),
Includes(std::move(Includes)), Macros(std::move(Macros)),
StatCache(std::move(StatCache)), CanonIncludes(std::move(CanonIncludes)) {
}
@@ -89,7 +91,6 @@ PreambleData::PreambleData(llvm::StringRef Version,
std::shared_ptr<const PreambleData>
buildPreamble(PathRef FileName, CompilerInvocation &CI,
std::shared_ptr<const PreambleData> OldPreamble,
- const tooling::CompileCommand &OldCompileCommand,
const ParseInputs &Inputs, bool StoreInMemory,
PreambleParsedCallback PreambleCallback) {
// Note that we don't need to copy the input contents, preamble can live
@@ -100,7 +101,8 @@ buildPreamble(PathRef FileName, CompilerInvocation &CI,
ComputePreambleBounds(*CI.getLangOpts(), ContentsBuffer.get(), 0);
if (OldPreamble &&
- compileCommandsAreEqual(Inputs.CompileCommand, OldCompileCommand) &&
+ compileCommandsAreEqual(Inputs.CompileCommand,
+ OldPreamble->CompileCommand) &&
OldPreamble->Preamble.CanReuse(CI, ContentsBuffer.get(), Bounds,
Inputs.FS.get())) {
vlog("Reusing preamble version {0} for version {1} of {2}",
@@ -155,7 +157,7 @@ buildPreamble(PathRef FileName, CompilerInvocation &CI,
BuiltPreamble->getSize(), FileName, Inputs.Version);
std::vector<Diag> Diags = PreambleDiagnostics.take();
return std::make_shared<PreambleData>(
- Inputs.Version, std::move(*BuiltPreamble), std::move(Diags),
+ Inputs, std::move(*BuiltPreamble), std::move(Diags),
SerializedDeclsCollector.takeIncludes(),
SerializedDeclsCollector.takeMacros(), std::move(StatCache),
SerializedDeclsCollector.takeCanonicalIncludes());
diff --git a/clang-tools-extra/clangd/Preamble.h b/clang-tools-extra/clangd/Preamble.h
index 1517daaf05a9..c2049cde78a9 100644
--- a/clang-tools-extra/clangd/Preamble.h
+++ b/clang-tools-extra/clangd/Preamble.h
@@ -43,7 +43,7 @@ namespace clangd {
/// As we must avoid re-parsing the preamble, any information that can only
/// be obtained during parsing must be eagerly captured and stored here.
struct PreambleData {
- PreambleData(llvm::StringRef Version, PrecompiledPreamble Preamble,
+ PreambleData(const ParseInputs &Inputs, PrecompiledPreamble Preamble,
std::vector<Diag> Diags, IncludeStructure Includes,
MainFileMacros Macros,
std::unique_ptr<PreambleFileStatusCache> StatCache,
@@ -80,7 +80,6 @@ using PreambleParsedCallback =
std::shared_ptr<const PreambleData>
buildPreamble(PathRef FileName, CompilerInvocation &CI,
std::shared_ptr<const PreambleData> OldPreamble,
- const tooling::CompileCommand &OldCompileCommand,
const ParseInputs &Inputs, bool StoreInMemory,
PreambleParsedCallback PreambleCallback);
diff --git a/clang-tools-extra/clangd/TUScheduler.cpp b/clang-tools-extra/clangd/TUScheduler.cpp
index 7188d0be69ff..e5a001997ecc 100644
--- a/clang-tools-extra/clangd/TUScheduler.cpp
+++ b/clang-tools-extra/clangd/TUScheduler.cpp
@@ -403,7 +403,6 @@ void ASTWorker::update(ParseInputs Inputs, WantDiagnostics WantDiags) {
std::tie(PrevInputs->CompileCommand, PrevInputs->Contents) ==
std::tie(Inputs.CompileCommand, Inputs.Contents);
- tooling::CompileCommand OldCommand = PrevInputs->CompileCommand;
bool RanCallbackForPrevInputs = RanASTCallback;
{
std::lock_guard<std::mutex> Lock(Mutex);
@@ -445,8 +444,7 @@ void ASTWorker::update(ParseInputs Inputs, WantDiagnostics WantDiags) {
Inputs.ForceRebuild ? std::shared_ptr<const PreambleData>()
: getPossiblyStalePreamble();
std::shared_ptr<const PreambleData> NewPreamble = buildPreamble(
- FileName, *Invocation, OldPreamble, OldCommand, Inputs,
- StorePreambleInMemory,
+ FileName, *Invocation, OldPreamble, Inputs, StorePreambleInMemory,
[this, Version(Inputs.Version)](
ASTContext &Ctx, std::shared_ptr<clang::Preprocessor> PP,
const CanonicalIncludes &CanonIncludes) {
diff --git a/clang-tools-extra/clangd/unittests/FileIndexTests.cpp b/clang-tools-extra/clangd/unittests/FileIndexTests.cpp
index 7c9aa3842531..b020c2f72105 100644
--- a/clang-tools-extra/clangd/unittests/FileIndexTests.cpp
+++ b/clang-tools-extra/clangd/unittests/FileIndexTests.cpp
@@ -286,16 +286,16 @@ TEST(FileIndexTest, RebuildWithPreamble) {
FileIndex Index;
bool IndexUpdated = false;
- buildPreamble(
- FooCpp, *CI, /*OldPreamble=*/nullptr, tooling::CompileCommand(), PI,
- /*StoreInMemory=*/true,
- [&](ASTContext &Ctx, std::shared_ptr<Preprocessor> PP,
- const CanonicalIncludes &CanonIncludes) {
- EXPECT_FALSE(IndexUpdated) << "Expected only a single index update";
- IndexUpdated = true;
- Index.updatePreamble(FooCpp, /*Version=*/"null", Ctx, std::move(PP),
- CanonIncludes);
- });
+ buildPreamble(FooCpp, *CI, /*OldPreamble=*/nullptr, PI,
+ /*StoreInMemory=*/true,
+ [&](ASTContext &Ctx, std::shared_ptr<Preprocessor> PP,
+ const CanonicalIncludes &CanonIncludes) {
+ EXPECT_FALSE(IndexUpdated)
+ << "Expected only a single index update";
+ IndexUpdated = true;
+ Index.updatePreamble(FooCpp, /*Version=*/"null", Ctx,
+ std::move(PP), CanonIncludes);
+ });
ASSERT_TRUE(IndexUpdated);
// Check the index contains symbols from the preamble, but not from the main
diff --git a/clang-tools-extra/clangd/unittests/TestTU.cpp b/clang-tools-extra/clangd/unittests/TestTU.cpp
index 18f0589f5d17..909c125aed2e 100644
--- a/clang-tools-extra/clangd/unittests/TestTU.cpp
+++ b/clang-tools-extra/clangd/unittests/TestTU.cpp
@@ -67,8 +67,7 @@ ParsedAST TestTU::build() const {
assert(CI && "Failed to build compilation invocation.");
auto Preamble =
buildPreamble(FullFilename, *CI,
- /*OldPreamble=*/nullptr,
- /*OldCompileCommand=*/Inputs.CompileCommand, Inputs,
+ /*OldPreamble=*/nullptr, Inputs,
/*StoreInMemory=*/true, /*PreambleCallback=*/nullptr);
auto AST =
buildAST(FullFilename, std::move(CI), Diags.take(), Inputs, Preamble);
More information about the cfe-commits
mailing list