This is an archive of the discontinued LLVM Phabricator instance.

[clangd] Make FileIndex aware of the main file
ClosedPublic

Authored by ilya-biryukov on Aug 17 2018, 3:19 AM.

Details

Summary

It was previously only indexing the preamble decls. The new
implementation will index both the preamble and the main AST and
report both sets of symbols, preferring the ones from the main AST
whenever the symbol is present in both.
The symbols in the main AST slab always store all information
available in the preamble symbols, possibly adding more,
e.g. definition locations.

Diff Detail

Event Timeline

ilya-biryukov created this revision.Aug 17 2018, 3:19 AM

This is still WIP, but wanted to share anyway the progress anyway.
Need to fix the FIXMEs currently added to the code and add tests.

clangd/index/FileIndex.cpp
60

We need to be more careful here now that we have to slabs in the list. Should only erase when both are removed.

66

This should definitely be done outside the lock, only the actual swap of the symbol tables should be there.

ilya-biryukov planned changes to this revision.Aug 17 2018, 5:01 AM

As discussed offline, we could instead have a two-layer scheme for dynamic index. A top layer will contain main file symbols, second layer will contain preamble symbols.

  • Reverted changes to FileIndex, use merged index instead

Still missing tests, but otherwise should be good to review.

hokein added inline comments.Aug 20 2018, 2:56 AM
clangd/index/FileIndex.h
70

Any strong reason to unify the interface (and indexAST)?

It seems to me that we do different things on PreambleAST and MainAST:

  • on PreambleAST, we only index Symbols for code completion.
  • on MainAST, we index Symbols (to collect other information missing from PreambleAST, e.g. definition location), and collect symbol references.

Therefore, we'd need to set different options for SymbolCollector accordingly. Having a single interface would make the implementation tricky (checking TopLevelDecls to see whether this is a PreambleASt).

ioeric added inline comments.Aug 20 2018, 3:11 AM
clangd/ClangdServer.cpp
71

Maybe provide noop implementations for ParsingCallbacks::onPreambleAST() and ParsingCallbacks::onMainAST by default?

clangd/ClangdServer.h
215

Can we move this into ClangdServer.cpp as an implementation helper?

226

nit: s/FileIdx/DymIdx? (also need to update the comment above)

clangd/index/FileIndex.cpp
46

nit: I'd try avoiding modify the input argument if possible. Maybe set Storage properly according to TopLevelDecls?

ilya-biryukov marked 3 inline comments as done.
  • Move DynamicIndex into ClangdServer.cpp
  • Rename FileIdx to DynamicIdx
  • Avoid modifying input args
ilya-biryukov added inline comments.Aug 21 2018, 4:36 AM
clangd/ClangdServer.cpp
71

I'll address this in a parent revision.

clangd/ClangdServer.h
226

Went with DynamicIdx.

  • Use noop callbacks from the parent revision
ilya-biryukov marked 2 inline comments as done.Aug 21 2018, 7:39 AM

All the issues should be addressed at this point

clangd/ClangdServer.cpp
71

Done

ilya-biryukov marked an inline comment as done.Aug 21 2018, 7:43 AM
ilya-biryukov added inline comments.
clangd/index/FileIndex.h
70

The only reason is to keep the changes to FileIndex minimal in this change. We'll have to change more code to cover those differences, but I'm not sure I have enough context on what's going to be different for this change, a change that will plug xrefs into clangd is probably a better candidate for those.

ioeric accepted this revision.Aug 22 2018, 2:37 AM

lgtm

This revision is now accepted and ready to land.Aug 22 2018, 2:37 AM
  • Rebase onto head
This revision was automatically updated to reflect the committed changes.