diff --git a/clang-tools-extra/clangd/Preamble.h b/clang-tools-extra/clangd/Preamble.h --- a/clang-tools-extra/clangd/Preamble.h +++ b/clang-tools-extra/clangd/Preamble.h @@ -43,7 +43,7 @@ /// 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 Diags, IncludeStructure Includes, MainFileMacros Macros, std::unique_ptr StatCache, @@ -80,7 +80,6 @@ std::shared_ptr buildPreamble(PathRef FileName, CompilerInvocation &CI, std::shared_ptr OldPreamble, - const tooling::CompileCommand &OldCompileCommand, const ParseInputs &Inputs, bool StoreInMemory, PreambleParsedCallback PreambleCallback); diff --git a/clang-tools-extra/clangd/Preamble.cpp b/clang-tools-extra/clangd/Preamble.cpp --- 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 @@ } // namespace -PreambleData::PreambleData(llvm::StringRef Version, +PreambleData::PreambleData(const ParseInputs &Inputs, PrecompiledPreamble Preamble, std::vector Diags, IncludeStructure Includes, MainFileMacros Macros, std::unique_ptr 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 @@ std::shared_ptr buildPreamble(PathRef FileName, CompilerInvocation &CI, std::shared_ptr 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 @@ 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 @@ BuiltPreamble->getSize(), FileName, Inputs.Version); std::vector Diags = PreambleDiagnostics.take(); return std::make_shared( - 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/TUScheduler.cpp b/clang-tools-extra/clangd/TUScheduler.cpp --- a/clang-tools-extra/clangd/TUScheduler.cpp +++ b/clang-tools-extra/clangd/TUScheduler.cpp @@ -403,7 +403,6 @@ std::tie(PrevInputs->CompileCommand, PrevInputs->Contents) == std::tie(Inputs.CompileCommand, Inputs.Contents); - tooling::CompileCommand OldCommand = PrevInputs->CompileCommand; bool RanCallbackForPrevInputs = RanASTCallback; { std::lock_guard Lock(Mutex); @@ -445,8 +444,7 @@ Inputs.ForceRebuild ? std::shared_ptr() : getPossiblyStalePreamble(); std::shared_ptr NewPreamble = buildPreamble( - FileName, *Invocation, OldPreamble, OldCommand, Inputs, - StorePreambleInMemory, + FileName, *Invocation, OldPreamble, Inputs, StorePreambleInMemory, [this, Version(Inputs.Version)]( ASTContext &Ctx, std::shared_ptr PP, const CanonicalIncludes &CanonIncludes) { diff --git a/clang-tools-extra/clangd/unittests/FileIndexTests.cpp b/clang-tools-extra/clangd/unittests/FileIndexTests.cpp --- a/clang-tools-extra/clangd/unittests/FileIndexTests.cpp +++ b/clang-tools-extra/clangd/unittests/FileIndexTests.cpp @@ -286,16 +286,16 @@ FileIndex Index; bool IndexUpdated = false; - buildPreamble( - FooCpp, *CI, /*OldPreamble=*/nullptr, tooling::CompileCommand(), PI, - /*StoreInMemory=*/true, - [&](ASTContext &Ctx, std::shared_ptr 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 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 --- a/clang-tools-extra/clangd/unittests/TestTU.cpp +++ b/clang-tools-extra/clangd/unittests/TestTU.cpp @@ -67,8 +67,7 @@ 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);