summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--clang-tools-extra/clangd/ClangdServer.cpp6
-rw-r--r--clang-tools-extra/clangd/TUScheduler.cpp23
-rw-r--r--clang-tools-extra/clangd/TUScheduler.h16
-rw-r--r--clang-tools-extra/unittests/clangd/TUSchedulerTests.cpp3
4 files changed, 27 insertions, 21 deletions
diff --git a/clang-tools-extra/clangd/ClangdServer.cpp b/clang-tools-extra/clangd/ClangdServer.cpp
index 2f7d5a2f351..789382db2b4 100644
--- a/clang-tools-extra/clangd/ClangdServer.cpp
+++ b/clang-tools-extra/clangd/ClangdServer.cpp
@@ -159,12 +159,11 @@ void ClangdServer::codeComplete(PathRef File, Position Pos,
llvm::Expected<InputsAndPreamble> IP) {
assert(IP && "error when trying to read preamble for codeComplete");
auto PreambleData = IP->Preamble;
- auto &Command = IP->Inputs.CompileCommand;
// FIXME(ibiryukov): even if Preamble is non-null, we may want to check
// both the old and the new version in case only one of them matches.
CompletionList Result = clangd::codeComplete(
- File, Command, PreambleData ? &PreambleData->Preamble : nullptr,
+ File, IP->Command, PreambleData ? &PreambleData->Preamble : nullptr,
Contents, Pos, FS, PCHs, CodeCompleteOpts);
CB(std::move(Result));
};
@@ -191,8 +190,7 @@ void ClangdServer::signatureHelp(PathRef File, Position Pos,
return CB(IP.takeError());
auto PreambleData = IP->Preamble;
- auto &Command = IP->Inputs.CompileCommand;
- CB(clangd::signatureHelp(File, Command,
+ CB(clangd::signatureHelp(File, IP->Command,
PreambleData ? &PreambleData->Preamble : nullptr,
Contents, Pos, FS, PCHs));
};
diff --git a/clang-tools-extra/clangd/TUScheduler.cpp b/clang-tools-extra/clangd/TUScheduler.cpp
index 15bb9c13dbe..51b13e2b7ba 100644
--- a/clang-tools-extra/clangd/TUScheduler.cpp
+++ b/clang-tools-extra/clangd/TUScheduler.cpp
@@ -407,7 +407,8 @@ unsigned getDefaultAsyncThreadsCount() {
struct TUScheduler::FileData {
/// Latest inputs, passed to TUScheduler::update().
- ParseInputs Inputs;
+ std::string Contents;
+ tooling::CompileCommand Command;
ASTWorkerHandle Worker;
};
@@ -456,9 +457,11 @@ void TUScheduler::update(PathRef File, ParseInputs Inputs,
File, WorkerThreads ? WorkerThreads.getPointer() : nullptr, Barrier,
CppFile(File, StorePreamblesInMemory, PCHOps, ASTCallback),
UpdateDebounce);
- FD = std::unique_ptr<FileData>(new FileData{Inputs, std::move(Worker)});
+ FD = std::unique_ptr<FileData>(new FileData{
+ Inputs.Contents, Inputs.CompileCommand, std::move(Worker)});
} else {
- FD->Inputs = Inputs;
+ FD->Contents = Inputs.Contents;
+ FD->Command = Inputs.CompileCommand;
}
FD->Worker->update(std::move(Inputs), WantDiags, std::move(OnUpdated));
}
@@ -500,26 +503,28 @@ void TUScheduler::runWithPreamble(
SPAN_ATTACH(Tracer, "file", File);
std::shared_ptr<const PreambleData> Preamble =
It->second->Worker->getPossiblyStalePreamble();
- Action(InputsAndPreamble{It->second->Inputs, Preamble.get()});
+ Action(InputsAndPreamble{It->second->Contents, It->second->Command,
+ Preamble.get()});
return;
}
- ParseInputs InputsCopy = It->second->Inputs;
std::shared_ptr<const ASTWorker> Worker = It->second->Worker.lock();
- auto Task = [InputsCopy, Worker, this](std::string Name, std::string File,
- Context Ctx,
- decltype(Action) Action) mutable {
+ auto Task = [Worker, this](std::string Name, std::string File,
+ std::string Contents,
+ tooling::CompileCommand Command, Context Ctx,
+ decltype(Action) Action) mutable {
std::lock_guard<Semaphore> BarrierLock(Barrier);
WithContext Guard(std::move(Ctx));
trace::Span Tracer(Name);
SPAN_ATTACH(Tracer, "file", File);
std::shared_ptr<const PreambleData> Preamble =
Worker->getPossiblyStalePreamble();
- Action(InputsAndPreamble{InputsCopy, Preamble.get()});
+ Action(InputsAndPreamble{Contents, Command, Preamble.get()});
};
PreambleTasks->runAsync("task:" + llvm::sys::path::filename(File),
Bind(Task, std::string(Name), std::string(File),
+ It->second->Contents, It->second->Command,
Context::current().clone(), std::move(Action)));
}
diff --git a/clang-tools-extra/clangd/TUScheduler.h b/clang-tools-extra/clangd/TUScheduler.h
index a56d251d165..b48d289489a 100644
--- a/clang-tools-extra/clangd/TUScheduler.h
+++ b/clang-tools-extra/clangd/TUScheduler.h
@@ -29,7 +29,8 @@ struct InputsAndAST {
};
struct InputsAndPreamble {
- const ParseInputs &Inputs;
+ llvm::StringRef Contents;
+ const tooling::CompileCommand &Command;
const PreambleData *Preamble;
};
@@ -78,11 +79,14 @@ public:
void runWithAST(llvm::StringRef Name, PathRef File,
Callback<InputsAndAST> Action);
- /// Schedule an async read of the Preamble. Preamble passed to \p Action may
- /// be built for any version of the file, callers must not rely on it being
- /// consistent with the current version of the file.
- /// If an error occurs during processing, it is forwarded to the \p Action
- /// callback.
+ /// Schedule an async read of the Preamble.
+ /// The preamble may be stale, generated from an older version of the file.
+ /// Reading from locations in the preamble may cause the files to be re-read.
+ /// This gives callers two options:
+ /// - validate that the preamble is still valid, and only use it in this case
+ /// - accept that preamble contents may be outdated, and try to avoid reading
+ /// source code from headers. If an error occurs during processing, it is
+ /// forwarded to the \p Action callback.
void runWithPreamble(llvm::StringRef Name, PathRef File,
Callback<InputsAndPreamble> Action);
diff --git a/clang-tools-extra/unittests/clangd/TUSchedulerTests.cpp b/clang-tools-extra/unittests/clangd/TUSchedulerTests.cpp
index 927ab2dc2ca..2235e8722c2 100644
--- a/clang-tools-extra/unittests/clangd/TUSchedulerTests.cpp
+++ b/clang-tools-extra/unittests/clangd/TUSchedulerTests.cpp
@@ -226,8 +226,7 @@ TEST_F(TUSchedulerTests, ManyUpdates) {
EXPECT_THAT(Context::current().get(NonceKey), Pointee(Nonce));
ASSERT_TRUE((bool)Preamble);
- EXPECT_EQ(Preamble->Inputs.FS, Inputs.FS);
- EXPECT_EQ(Preamble->Inputs.Contents, Inputs.Contents);
+ EXPECT_EQ(Preamble->Contents, Inputs.Contents);
std::lock_guard<std::mutex> Lock(Mut);
++TotalPreambleReads;
OpenPOWER on IntegriCloud