This is an archive of the discontinued LLVM Phabricator instance.

[clangd] SymbolOccurrences -> Refs and cleanup
ClosedPublic

Authored by sammccall on Sep 3 2018, 3:49 PM.

Details

Summary

A few things that I noticed while merging the SwapIndex patch:

  • SymbolOccurrences and particularly SymbolOccurrenceSlab are unwieldy names, and these names appear *a lot*. Ref, RefSlab, etc seem clear enough and read/format much better.
  • The asymmetry between SymbolSlab and RefSlab (build() vs freeze()) is confusing and irritating, and doesn't even save much code. Avoiding RefSlab::Builder was my idea, but it was a bad one; add it.
  • DenseMap<SymbolID, ArrayRef<Ref>> seems like a reasonable compromise for constructing MemIndex - and means many less wasted allocations than the current DenseMap<SymbolID, vector<Ref*>> for FileIndex, and none for slabs.
  • RefSlab::find() is not needed, so we can get rid of the DenseMap after building the slab.
  • A few naming/consistency fixes: e.g. Slabs,Refs -> Symbols,Refs.

Diff Detail

Event Timeline

sammccall created this revision.Sep 3 2018, 3:49 PM
sammccall updated this revision to Diff 163751.Sep 3 2018, 4:15 PM

Remove RefsSlab::find()

sammccall edited the summary of this revision. (Show Details)Sep 3 2018, 4:17 PM
hokein added a subscriber: hokein.Sep 4 2018, 2:30 AM

Thanks for cleaning it up! I admit that SymbolOccurrences is a loong name. A few nits.

clangd/index/FileIndex.cpp
120

So the sort is intended to make returned refs ordered?

clangd/index/Index.h
367

we should be careful if Refs is empty. Calling front() on empty container is undefined behavior.

clangd/index/MemIndex.h
22

This type seems not used in this patch, consider removing it or using it to replace existing llvm::DenseMap<SymbolID, llvm::ArrayRef<Ref>> usage.

unittests/clangd/FileIndexTests.cpp
346

My fault here. This is not safe, we need to store the underlying FileURI data.

unittests/clangd/IndexTests.cpp
273

The same here.

ioeric accepted this revision.Sep 4 2018, 2:33 AM

nice!

clangd/index/Index.cpp
147

maybe also mention that this would make lookup faster?

clangd/index/Merge.cpp
12

nit: shouldn't the main header be sorted higher?

We should also put all #includes in one block so that clang-format can sort them properly.

This revision is now accepted and ready to land.Sep 4 2018, 2:33 AM
sammccall marked 7 inline comments as done.Sep 4 2018, 4:37 AM

Thanks for cleaning it up! I admit that SymbolOccurrences is a loong name. A few nits.

Yeah, I hope you don't mind! The references stuff is awesome, I'm hoping to make it work with static index soon!

clangd/index/FileIndex.cpp
120

Yeah, I'm worried about the fact that we have no ranking at all, so the natural implementation of refs() with limit will return randomly different results after each dynamic index rebuild.
Added a comment here, also happy to remove the sorting if you prefer.

clangd/index/Index.h
367

the arg to sizeof() is an unevaluated context, so it never actually gets called (just the type is evaluated).
Changed to sizeof(value_type) for clarity though.

clangd/index/Merge.cpp
12

Ah, <set> was confusing clang-format's main-header heuristic.

unittests/clangd/FileIndexTests.cpp
346

well, the contract on SymbolIndex doesn't say so, but in this concrete case, we know the implementation so it's not too bad.

In any case, avoided the issue (changed getRefPaths -> getRefs which returns a slab)

sammccall updated this revision to Diff 163784.Sep 4 2018, 4:37 AM
sammccall marked 4 inline comments as done.

Address comments

lebedev.ri added inline comments.
clangd/index/Index.cpp
152

I noticed this by accident, but i'm pretty sure std::sort() should not be used in LLVM sources at all.
llvm::sort() should be used everywhere.

sammccall marked an inline comment as done.Sep 4 2018, 4:51 AM
sammccall added inline comments.
clangd/index/Index.cpp
152

OK, I'll send a cleanup, thanks!

hokein accepted this revision.Sep 4 2018, 4:53 AM

LGTM, thanks!

clangd/index/FileIndex.cpp
120

Sounds good to me.

This revision was automatically updated to reflect the committed changes.
sammccall marked an inline comment as done.