This is an archive of the discontinued LLVM Phabricator instance.

[clangd] Cache include fixes for diagnostics caused by the same unresolved name or incomplete type.
ClosedPublic

Authored by ioeric on Feb 14 2019, 8:00 AM.

Details

Summary

Multiple diagnostics can be caused by the same unresolved name or incomplete type,
especially if the code is copy-pasted without #includes. The cache can avoid making
repetitive index requests, and thus reduce latency and allow more diagnostics to be
fixed (we limit the number of index requests for each parse).

Event Timeline

ioeric created this revision.Feb 14 2019, 8:00 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 14 2019, 8:00 AM
sammccall added inline comments.Feb 15 2019, 9:01 AM
clangd/IncludeFixer.cpp
130

oops - this seems broken (in both the old and new form). Symbol is a shallow reference, and it's not valid after lookup() returns.

We can fix here or separately... one option to fix is the ResolvedSymbol struct suggested above.

(The fuzzyFind case looks ok)

clangd/IncludeFixer.h
85

This seems pretty messy (the assumption that Fix depends only on the index lookup).
It saves some code now at the expense of being magic. If we want to e.g. insert qualifiers too, I worry it's going to (stop us || return incorrect cached results || lead to unneccesary cache misses) depending on what we do.

What would we need to store to calculate Fix?
Maybe a struct ResolvedSymbol with {scope, name, inserted header}? (or even the edit to insert the header)
If it's not hugely complicated, that seems both cleaner and more extensible - wdyt?

90

DenseMap<SymbolID, ...>?

(big thumbs up to the caching overall of course!)

ioeric updated this revision to Diff 187205.Feb 18 2019, 2:40 AM
ioeric marked 4 inline comments as done.
  • address review comments
ioeric added inline comments.Feb 18 2019, 2:40 AM
clangd/IncludeFixer.h
85

Yeah, surely this was too hacky ;)

Instead of a new struct, how about simply storing SymbolSlabs? We are already building symbol slabs for fuzzy find results. And there are some helpers that take only Symbol. WDYT?

sammccall accepted this revision.Feb 18 2019, 4:17 AM

SymbolSlab is much cleaner, nice!

clangd/IncludeFixer.cpp
136–137

extract a function that maps SymbolID -> const SymbolSlab& and takes care of the caching?
(likewise for fuzzyfind)

clangd/IncludeFixer.h
86

nit: maybe drop the parenthetical here? I think it's more confusing than enlightening.

("assuming" can mean either "and we assume" or "if" in this context. Also it's not clear there's a better behavior even if results did change and queries are free.)

This revision is now accepted and ready to land.Feb 18 2019, 4:17 AM
ioeric updated this revision to Diff 187226.Feb 18 2019, 5:03 AM
ioeric marked 2 inline comments as done.
  • pulled cached index queries into functions
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptFeb 18 2019, 5:11 AM