summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIlya Biryukov <ibiryukov@google.com>2018-01-18 15:17:00 +0000
committerIlya Biryukov <ibiryukov@google.com>2018-01-18 15:17:00 +0000
commit295c8e1e2df57c9c85029e256a561b131043b0cd (patch)
tree80340054bbe6b598a408ed3d0f463dca7a6db8e4
parent4a8f7533061bdd575677fc3d7c066a7a3a2b372e (diff)
downloadbcm5719-llvm-295c8e1e2df57c9c85029e256a561b131043b0cd.tar.gz
bcm5719-llvm-295c8e1e2df57c9c85029e256a561b131043b0cd.zip
[clangd] Always use preamble (even stale) for code completion
Summary: This improves performance of code completion, because we avoid stating the files from the preamble and never attempt to parse the files without using the preamble if it's provided. However, the change comes at a cost of sometimes providing incorrect results when doing code completion after making actually considerable changes to the files used in the preamble or the preamble itself. Eventually the preamble will get rebuilt and code completion will be providing the correct results. Reviewers: bkramer, sammccall, jkorous-apple Reviewed By: sammccall Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D41991 llvm-svn: 322854
-rw-r--r--clang-tools-extra/clangd/CodeComplete.cpp12
-rw-r--r--clang-tools-extra/clangd/Compiler.cpp9
-rw-r--r--clang-tools-extra/clangd/Compiler.h17
3 files changed, 19 insertions, 19 deletions
diff --git a/clang-tools-extra/clangd/CodeComplete.cpp b/clang-tools-extra/clangd/CodeComplete.cpp
index 73acc0c6c37..fe74dbd9863 100644
--- a/clang-tools-extra/clangd/CodeComplete.cpp
+++ b/clang-tools-extra/clangd/CodeComplete.cpp
@@ -517,14 +517,18 @@ bool invokeCodeComplete(const Context &Ctx,
std::unique_ptr<llvm::MemoryBuffer> ContentsBuffer =
llvm::MemoryBuffer::getMemBufferCopy(Contents, FileName);
- // Attempt to reuse the PCH from precompiled preamble, if it was built.
+ // We reuse the preamble whether it's valid or not. This is a
+ // correctness/performance tradeoff: building without a preamble is slow, and
+ // completion is latency-sensitive.
if (Preamble) {
auto Bounds =
ComputePreambleBounds(*CI->getLangOpts(), ContentsBuffer.get(), 0);
- if (!Preamble->CanReuse(*CI, ContentsBuffer.get(), Bounds, VFS.get()))
- Preamble = nullptr;
+ // FIXME(ibiryukov): Remove this call to CanReuse() after we'll fix
+ // clients relying on getting stats for preamble files during code
+ // completion.
+ // Note that results of CanReuse() are ignored, see the comment above.
+ Preamble->CanReuse(*CI, ContentsBuffer.get(), Bounds, VFS.get());
}
-
auto Clang = prepareCompilerInstance(
std::move(CI), Preamble, std::move(ContentsBuffer), std::move(PCHs),
std::move(VFS), DummyDiagsConsumer);
diff --git a/clang-tools-extra/clangd/Compiler.cpp b/clang-tools-extra/clangd/Compiler.cpp
index b45fbb57fc7..f85ed6cd039 100644
--- a/clang-tools-extra/clangd/Compiler.cpp
+++ b/clang-tools-extra/clangd/Compiler.cpp
@@ -14,13 +14,6 @@
namespace clang {
namespace clangd {
-/// Creates a CompilerInstance from \p CI, with main buffer overriden to \p
-/// Buffer and arguments to read the PCH from \p Preamble, if \p Preamble is not
-/// null. Note that vfs::FileSystem inside returned instance may differ from \p
-/// VFS if additional file remapping were set in command-line arguments.
-/// On some errors, returns null. When non-null value is returned, it's expected
-/// to be consumed by the FrontendAction as it will have a pointer to the \p
-/// Buffer that will only be deleted if BeginSourceFile is called.
std::unique_ptr<CompilerInstance>
prepareCompilerInstance(std::unique_ptr<clang::CompilerInvocation> CI,
const PrecompiledPreamble *Preamble,
@@ -36,7 +29,7 @@ prepareCompilerInstance(std::unique_ptr<clang::CompilerInvocation> CI,
// NOTE: we use Buffer.get() when adding remapped files, so we have to make
// sure it will be released if no error is emitted.
if (Preamble) {
- Preamble->AddImplicitPreamble(*CI, VFS, Buffer.get());
+ Preamble->OverridePreamble(*CI, VFS, Buffer.get());
} else {
CI->getPreprocessorOpts().addRemappedFile(
CI->getFrontendOpts().Inputs[0].getFile(), Buffer.get());
diff --git a/clang-tools-extra/clangd/Compiler.h b/clang-tools-extra/clangd/Compiler.h
index 97b683c9aaa..8b5e2e813f4 100644
--- a/clang-tools-extra/clangd/Compiler.h
+++ b/clang-tools-extra/clangd/Compiler.h
@@ -28,13 +28,16 @@ public:
const clang::Diagnostic &Info) override {}
};
-/// Creates a CompilerInstance with the main file contens overridden.
-/// The preamble will be reused unless it is null.
-/// Note that the vfs::FileSystem inside returned instance may differ if
-/// additional file remappings occur in command-line arguments.
-/// On some errors, returns null. When non-null value is returned, it's expected
-/// to be consumed by the FrontendAction as it will have a pointer to the
-/// MainFile buffer that will only be deleted if BeginSourceFile is called.
+/// Creates a compiler instance, configured so that:
+/// - Contents of the parsed file are remapped to \p MainFile.
+/// - Preamble is overriden to use PCH passed to this function. It means the
+/// changes to the preamble headers or files included in the preamble are
+/// not visible to this compiler instance.
+/// - vfs::FileSystem is used for all underlying file accesses. The actual
+/// vfs used by the compiler may be an overlay over the passed vfs.
+/// Returns null on errors. When non-null value is returned, it is expected to
+/// be consumed by FrontendAction::BeginSourceFile to properly destroy \p
+/// MainFile.
std::unique_ptr<CompilerInstance> prepareCompilerInstance(
std::unique_ptr<clang::CompilerInvocation>, const PrecompiledPreamble *,
std::unique_ptr<llvm::MemoryBuffer> MainFile,
OpenPOWER on IntegriCloud