This is an archive of the discontinued LLVM Phabricator instance.

[clangd] Fix some references missing in dynamic index.
ClosedPublic

Authored by hokein on Oct 15 2018, 2:03 AM.

Details

Summary

Previously, SymbolCollector postfilters all references at the end to
find all references of interesting symbols.
It was incorrect when indxing main AST where we don't see locations
of symbol declarations and definitions in the main AST (as those are in
preamble AST).

The fix is to do earily check during collecting references.

Diff Detail

Repository
rL LLVM

Event Timeline

hokein created this revision.Oct 15 2018, 2:03 AM

Nice fix, just performance concerns.

(I do think this might be significant, but measuring dynamic index time before/after for a big TU might show this to be unimportant)

clangd/index/SymbolCollector.cpp
348 ↗(On Diff #169660)

This seems better for the main-AST case, but substantially more expensive for indexing preambles: we may not want references at all, so paying for shouldCollectSymbol for every reference seems wasteful.

what about

bool RefMayBeInteresting = RefFilter & Roles;
bool IsOnlyRef = !(Roles & (Declaration | Definition));
if (IsOnlyRef && !RefMayBeInteresting)
  return;
if (!shouldCollectSymbol())
  return;
if (RefMayBeInteresting && File == getMainFileID())
  // add ref
if (IsOnlyRef) // don't continue if mere reference
  return;
hokein updated this revision to Diff 169671.Oct 15 2018, 3:19 AM
hokein marked an inline comment as done.

avoid calling shouldCollectSymbol every time during indexing.

clangd/index/SymbolCollector.cpp
348 ↗(On Diff #169660)

I thought shouldCollectSymbol is not as expensive as before (since we have removed AST matchers stuff there), but I'm definitely +1 on the idea of avoid calling it for every reference.

sammccall accepted this revision.Oct 15 2018, 3:33 AM
This revision is now accepted and ready to land.Oct 15 2018, 3:33 AM
This revision was automatically updated to reflect the committed changes.