This is an archive of the discontinued LLVM Phabricator instance.

[clangd] Always use preamble (even stale) for code completion
ClosedPublic

Authored by ilya-biryukov on Jan 12 2018, 6:19 AM.

Details

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.

Event Timeline

ilya-biryukov created this revision.Jan 12 2018, 6:19 AM
bkramer added inline comments.Jan 16 2018, 6:38 AM
clangd/Compiler.h
38

This comment is somewhat messy now. Can you rephrase it a bit?

sammccall accepted this revision.Jan 17 2018, 8:13 AM

Big +1 to the change here.
Just suggestions for the comments.

clangd/CodeComplete.cpp
533–534

delibirately -> deliberately

Thanks for adding the motivation here! I think this can be a bit terser, but up to you.
e.g.

// 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.
clangd/Compiler.h
38

+1, this has grown a bit unwieldy. Maybe:

/// Creates a compiler which will build the provided file.
/// The preamble will not be checked for validity - caller should do that if needed.
/// The returned compiler's VFS may differ due to command-line flags.
/// The returned value must be consumed by a FrontendAction to avoid leaking MainFile.
/// May return null in error cases.
This revision is now accepted and ready to land.Jan 17 2018, 8:13 AM
  • Rewrote the comment for prepareCompilerInstance
  • Call CanReuse() and discard its results. We have clients that rely on having the stat() calls for files from preamble
ilya-biryukov marked an inline comment as done.
  • Use a better comment suggest by Sam
ilya-biryukov added inline comments.Jan 17 2018, 8:44 AM
clangd/CodeComplete.cpp
533–534

Looks much better, thanks.

clangd/Compiler.h
38

I rewrote the comment before reading your suggestion, it should be better now.
If it's still unclear, let me know.

  • Fixed a typo
sammccall accepted this revision.Jan 17 2018, 8:50 AM

Thanks, LG!

clangd/Compiler.h
39

nit: "buffer for MainFile" -> "MainFile"
(since MainFile is already a buffer. also: less wrapping!)

ilya-biryukov marked an inline comment as done.
  • s/buffer for MainFile/MainFile/
This revision was automatically updated to reflect the committed changes.