Index: clang-tools-extra/clangd/CMakeLists.txt =================================================================== --- clang-tools-extra/clangd/CMakeLists.txt +++ clang-tools-extra/clangd/CMakeLists.txt @@ -46,7 +46,7 @@ index/SymbolCollector.cpp index/SymbolYAML.cpp - index/dex/DexIndex.cpp + index/dex/Dex.cpp index/dex/Iterator.cpp index/dex/Trigram.cpp Index: clang-tools-extra/clangd/index/SymbolYAML.cpp =================================================================== --- clang-tools-extra/clangd/index/SymbolYAML.cpp +++ clang-tools-extra/clangd/index/SymbolYAML.cpp @@ -11,7 +11,7 @@ #include "../Trace.h" #include "Index.h" #include "Serialization.h" -#include "dex/DexIndex.h" +#include "dex/Dex.h" #include "llvm/ADT/Optional.h" #include "llvm/ADT/SmallVector.h" #include "llvm/Support/Errc.h" @@ -225,7 +225,7 @@ if (!Slab) return nullptr; trace::Span Tracer("BuildIndex"); - return UseDex ? dex::DexIndex::build(std::move(*Slab), URISchemes) + return UseDex ? dex::Dex::build(std::move(*Slab), URISchemes) : MemIndex::build(std::move(*Slab), RefSlab()); } Index: clang-tools-extra/clangd/index/dex/Dex.h =================================================================== --- clang-tools-extra/clangd/index/dex/Dex.h +++ clang-tools-extra/clangd/index/dex/Dex.h @@ -1,4 +1,4 @@ -//===--- DexIndex.h - Dex Symbol Index Implementation -----------*- C++ -*-===// +//===--- Dex.h - Dex Symbol Index Implementation -----------*- C++ -*-===// // // The LLVM Compiler Infrastructure // @@ -37,11 +37,11 @@ // changed frequently, it's safe to assume that it has to be built only once // (when the clangd process starts). Therefore, it can be easier to store built // index on disk and then load it if available. -class DexIndex : public SymbolIndex { +class Dex : public SymbolIndex { public: // All symbols must outlive this index. template - DexIndex(Range &&Symbols, llvm::ArrayRef Schemes) + Dex(Range &&Symbols, llvm::ArrayRef Schemes) : URISchemes(Schemes) { // If Schemes don't contain any items, fall back to SymbolCollector's // default URI schemes. @@ -55,9 +55,9 @@ } // Symbols are owned by BackingData, Index takes ownership. template - DexIndex(Range &&Symbols, Payload &&BackingData, - llvm::ArrayRef URISchemes) - : DexIndex(std::forward(Symbols), URISchemes) { + Dex(Range &&Symbols, Payload &&BackingData, + llvm::ArrayRef URISchemes) + : Dex(std::forward(Symbols), URISchemes) { KeepAlive = std::shared_ptr( std::make_shared(std::move(BackingData)), nullptr); } @@ -65,7 +65,7 @@ /// Builds an index from a slab. The index takes ownership of the slab. static std::unique_ptr build(SymbolSlab Slab, llvm::ArrayRef URISchemes) { - return llvm::make_unique(Slab, std::move(Slab), URISchemes); + return llvm::make_unique(Slab, std::move(Slab), URISchemes); } bool Index: clang-tools-extra/clangd/index/dex/Dex.cpp =================================================================== --- clang-tools-extra/clangd/index/dex/Dex.cpp +++ clang-tools-extra/clangd/index/dex/Dex.cpp @@ -1,4 +1,4 @@ -//===--- DexIndex.cpp - Dex Symbol Index Implementation ---------*- C++ -*-===// +//===--- Dex.cpp - Dex Symbol Index Implementation ---------*- C++ -*-===// // // The LLVM Compiler Infrastructure // @@ -7,7 +7,7 @@ // //===----------------------------------------------------------------------===// -#include "DexIndex.h" +#include "Dex.h" #include "../../FileDistance.h" #include "../../FuzzyMatch.h" #include "../../Logger.h" @@ -90,7 +90,7 @@ } // namespace -void DexIndex::buildIndex() { +void Dex::buildIndex() { std::vector> ScoredSymbols(Symbols.size()); for (size_t I = 0; I < Symbols.size(); ++I) { @@ -119,16 +119,15 @@ InvertedIndex[Token].push_back(SymbolRank); } - vlog("Built DexIndex with estimated memory usage {0} bytes.", + vlog("Built Dex with estimated memory usage {0} bytes.", estimateMemoryUsage()); } /// Constructs iterators over tokens extracted from the query and exhausts it /// while applying Callback to each symbol in the order of decreasing quality /// of the matched symbols. -bool DexIndex::fuzzyFind( - const FuzzyFindRequest &Req, - llvm::function_ref Callback) const { +bool Dex::fuzzyFind(const FuzzyFindRequest &Req, + llvm::function_ref Callback) const { assert(!StringRef(Req.Query).contains("::") && "There must be no :: in query."); FuzzyMatcher Filter(Req.Query); @@ -213,8 +212,8 @@ return More; } -void DexIndex::lookup(const LookupRequest &Req, - llvm::function_ref Callback) const { +void Dex::lookup(const LookupRequest &Req, + llvm::function_ref Callback) const { for (const auto &ID : Req.IDs) { auto I = LookupTable.find(ID); if (I != LookupTable.end()) @@ -222,12 +221,12 @@ } } -void DexIndex::refs(const RefsRequest &Req, - llvm::function_ref Callback) const { +void Dex::refs(const RefsRequest &Req, + llvm::function_ref Callback) const { log("refs is not implemented."); } -size_t DexIndex::estimateMemoryUsage() const { +size_t Dex::estimateMemoryUsage() const { size_t Bytes = LookupTable.size() * sizeof(std::pair); Bytes += SymbolQuality.size() * sizeof(std::pair); Index: clang-tools-extra/clangd/tool/ClangdMain.cpp =================================================================== --- clang-tools-extra/clangd/tool/ClangdMain.cpp +++ clang-tools-extra/clangd/tool/ClangdMain.cpp @@ -13,7 +13,6 @@ #include "RIFF.h" #include "Trace.h" #include "index/SymbolYAML.h" -#include "index/dex/DexIndex.h" #include "clang/Basic/Version.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/FileSystem.h" Index: clang-tools-extra/unittests/clangd/DexIndexTests.cpp =================================================================== --- clang-tools-extra/unittests/clangd/DexIndexTests.cpp +++ clang-tools-extra/unittests/clangd/DexIndexTests.cpp @@ -1,4 +1,4 @@ -//===-- DexIndexTests.cpp ----------------------------*- C++ -*-----------===// +//===-- DexTests.cpp ----------------------------------*- C++ -*-----------===// // // The LLVM Compiler Infrastructure // @@ -12,7 +12,7 @@ #include "TestIndex.h" #include "index/Index.h" #include "index/Merge.h" -#include "index/dex/DexIndex.h" +#include "index/dex/Dex.h" #include "index/dex/Iterator.h" #include "index/dex/Token.h" #include "index/dex/Trigram.h" @@ -46,7 +46,7 @@ return IDs; } -TEST(DexIndexIterators, DocumentIterator) { +TEST(DexIterators, DocumentIterator) { const PostingList L = {4, 7, 8, 20, 42, 100}; auto DocIterator = create(L); @@ -69,7 +69,7 @@ EXPECT_TRUE(DocIterator->reachedEnd()); } -TEST(DexIndexIterators, AndWithEmpty) { +TEST(DexIterators, AndWithEmpty) { const PostingList L0; const PostingList L1 = {0, 5, 7, 10, 42, 320, 9000}; @@ -82,7 +82,7 @@ EXPECT_THAT(consumeIDs(*AndWithEmpty), ElementsAre()); } -TEST(DexIndexIterators, AndTwoLists) { +TEST(DexIterators, AndTwoLists) { const PostingList L0 = {0, 5, 7, 10, 42, 320, 9000}; const PostingList L1 = {0, 4, 7, 10, 30, 60, 320, 9000}; @@ -106,7 +106,7 @@ And->advanceTo(9001); } -TEST(DexIndexIterators, AndThreeLists) { +TEST(DexIterators, AndThreeLists) { const PostingList L0 = {0, 5, 7, 10, 42, 320, 9000}; const PostingList L1 = {0, 4, 7, 10, 30, 60, 320, 9000}; const PostingList L2 = {1, 4, 7, 11, 30, 60, 320, 9000}; @@ -120,7 +120,7 @@ EXPECT_TRUE(And->reachedEnd()); } -TEST(DexIndexIterators, OrWithEmpty) { +TEST(DexIterators, OrWithEmpty) { const PostingList L0; const PostingList L1 = {0, 5, 7, 10, 42, 320, 9000}; @@ -134,7 +134,7 @@ ElementsAre(0U, 5U, 7U, 10U, 42U, 320U, 9000U)); } -TEST(DexIndexIterators, OrTwoLists) { +TEST(DexIterators, OrTwoLists) { const PostingList L0 = {0, 5, 7, 10, 42, 320, 9000}; const PostingList L1 = {0, 4, 7, 10, 30, 60, 320, 9000}; @@ -167,7 +167,7 @@ ElementsAre(0U, 4U, 5U, 7U, 10U, 30U, 42U, 60U, 320U, 9000U)); } -TEST(DexIndexIterators, OrThreeLists) { +TEST(DexIterators, OrThreeLists) { const PostingList L0 = {0, 5, 7, 10, 42, 320, 9000}; const PostingList L1 = {0, 4, 7, 10, 30, 60, 320, 9000}; const PostingList L2 = {1, 4, 7, 11, 30, 60, 320, 9000}; @@ -197,7 +197,7 @@ // etc iterators) appear. However, it is not exhaustive and it would be // beneficial to implement automatic generation (e.g. fuzzing) of query trees // for more comprehensive testing. -TEST(DexIndexIterators, QueryTree) { +TEST(DexIterators, QueryTree) { // // +-----------------+ // |And Iterator:1, 5| @@ -254,7 +254,7 @@ EXPECT_TRUE(Root->reachedEnd()); } -TEST(DexIndexIterators, StringRepresentation) { +TEST(DexIterators, StringRepresentation) { const PostingList L0 = {4, 7, 8, 20, 42, 100}; const PostingList L1 = {1, 3, 5, 8, 9}; const PostingList L2 = {1, 5, 7, 9}; @@ -272,7 +272,7 @@ "END] [{1}, 3, 5, 8, 9, END]))"); } -TEST(DexIndexIterators, Limit) { +TEST(DexIterators, Limit) { const PostingList L0 = {3, 6, 7, 20, 42, 100}; const PostingList L1 = {1, 3, 5, 6, 7, 30, 100}; const PostingList L2 = {0, 3, 5, 7, 8, 100}; @@ -292,7 +292,7 @@ EXPECT_THAT(consumeIDs(*AndIterator), ElementsAre(3, 7)); } -TEST(DexIndexIterators, True) { +TEST(DexIterators, True) { auto TrueIterator = createTrue(0U); EXPECT_TRUE(TrueIterator->reachedEnd()); EXPECT_THAT(consumeIDs(*TrueIterator), ElementsAre()); @@ -305,7 +305,7 @@ EXPECT_THAT(consumeIDs(*AndIterator), ElementsAre(1, 2, 5)); } -TEST(DexIndexIterators, Boost) { +TEST(DexIterators, Boost) { auto BoostIterator = createBoost(createTrue(5U), 42U); EXPECT_FALSE(BoostIterator->reachedEnd()); auto ElementBoost = BoostIterator->consume(); @@ -351,7 +351,7 @@ return tokensAre(Trigrams, Token::Kind::Trigram); } -TEST(DexIndexTrigrams, IdentifierTrigrams) { +TEST(DexTrigrams, IdentifierTrigrams) { EXPECT_THAT(generateIdentifierTrigrams("X86"), trigramsAre({"x86", "x$$", "x8$"})); @@ -392,7 +392,7 @@ "hkl", "ijk", "ikl", "jkl", "klm", "ab$", "ad$"})); } -TEST(DexIndexTrigrams, QueryTrigrams) { +TEST(DexTrigrams, QueryTrigrams) { EXPECT_THAT(generateQueryTrigrams("c"), trigramsAre({"c$$"})); EXPECT_THAT(generateQueryTrigrams("cl"), trigramsAre({"cl$"})); EXPECT_THAT(generateQueryTrigrams("cla"), trigramsAre({"cla"})); @@ -442,8 +442,8 @@ // Index tests. //===----------------------------------------------------------------------===// -TEST(DexIndex, Lookup) { - auto I = DexIndex::build(generateSymbols({"ns::abc", "ns::xyz"}), URISchemes); +TEST(Dex, Lookup) { + auto I = Dex::build(generateSymbols({"ns::abc", "ns::xyz"}), URISchemes); EXPECT_THAT(lookup(*I, SymbolID("ns::abc")), UnorderedElementsAre("ns::abc")); EXPECT_THAT(lookup(*I, {SymbolID("ns::abc"), SymbolID("ns::xyz")}), UnorderedElementsAre("ns::abc", "ns::xyz")); @@ -452,11 +452,11 @@ EXPECT_THAT(lookup(*I, SymbolID("ns::nonono")), UnorderedElementsAre()); } -TEST(DexIndex, FuzzyFind) { - auto Index = DexIndex::build( - generateSymbols({"ns::ABC", "ns::BCD", "::ABC", "ns::nested::ABC", - "other::ABC", "other::A"}), - URISchemes); +TEST(Dex, FuzzyFind) { + auto Index = + Dex::build(generateSymbols({"ns::ABC", "ns::BCD", "::ABC", + "ns::nested::ABC", "other::ABC", "other::A"}), + URISchemes); FuzzyFindRequest Req; Req.Query = "ABC"; Req.Scopes = {"ns::"}; @@ -476,8 +476,8 @@ "other::A")); } -TEST(DexIndexTest, FuzzyMatchQ) { - auto I = DexIndex::build( +TEST(DexTest, FuzzyMatchQ) { + auto I = Dex::build( generateSymbols({"LaughingOutLoud", "LionPopulation", "LittleOldLady"}), URISchemes); FuzzyFindRequest Req; @@ -487,22 +487,22 @@ UnorderedElementsAre("LaughingOutLoud", "LittleOldLady")); } -// FIXME(kbobyrev): This test is different for DexIndex and MemIndex: while -// MemIndex manages response deduplication, DexIndex simply returns all matched +// FIXME(kbobyrev): This test is different for Dex and MemIndex: while +// MemIndex manages response deduplication, Dex simply returns all matched // symbols which means there might be equivalent symbols in the response. -// Before drop-in replacement of MemIndex with DexIndex happens, FileIndex +// Before drop-in replacement of MemIndex with Dex happens, FileIndex // should handle deduplication instead. -TEST(DexIndexTest, DexIndexDeduplicate) { +TEST(DexTest, DexDeduplicate) { std::vector Symbols = {symbol("1"), symbol("2"), symbol("3"), symbol("2") /* duplicate */}; FuzzyFindRequest Req; Req.Query = "2"; - DexIndex I(Symbols, URISchemes); + Dex I(Symbols, URISchemes); EXPECT_THAT(match(I, Req), ElementsAre("2", "2")); } -TEST(DexIndexTest, DexIndexLimitedNumMatches) { - auto I = DexIndex::build(generateNumSymbols(0, 100), URISchemes); +TEST(DexTest, DexLimitedNumMatches) { + auto I = Dex::build(generateNumSymbols(0, 100), URISchemes); FuzzyFindRequest Req; Req.Query = "5"; Req.MaxCandidateCount = 3; @@ -512,8 +512,8 @@ EXPECT_TRUE(Incomplete); } -TEST(DexIndexTest, FuzzyMatch) { - auto I = DexIndex::build( +TEST(DexTest, FuzzyMatch) { + auto I = Dex::build( generateSymbols({"LaughingOutLoud", "LionPopulation", "LittleOldLady"}), URISchemes); FuzzyFindRequest Req; @@ -523,25 +523,23 @@ UnorderedElementsAre("LaughingOutLoud", "LittleOldLady")); } -TEST(DexIndexTest, MatchQualifiedNamesWithoutSpecificScope) { - auto I = - DexIndex::build(generateSymbols({"a::y1", "b::y2", "y3"}), URISchemes); +TEST(DexTest, MatchQualifiedNamesWithoutSpecificScope) { + auto I = Dex::build(generateSymbols({"a::y1", "b::y2", "y3"}), URISchemes); FuzzyFindRequest Req; Req.Query = "y"; EXPECT_THAT(match(*I, Req), UnorderedElementsAre("a::y1", "b::y2", "y3")); } -TEST(DexIndexTest, MatchQualifiedNamesWithGlobalScope) { - auto I = - DexIndex::build(generateSymbols({"a::y1", "b::y2", "y3"}), URISchemes); +TEST(DexTest, MatchQualifiedNamesWithGlobalScope) { + auto I = Dex::build(generateSymbols({"a::y1", "b::y2", "y3"}), URISchemes); FuzzyFindRequest Req; Req.Query = "y"; Req.Scopes = {""}; EXPECT_THAT(match(*I, Req), UnorderedElementsAre("y3")); } -TEST(DexIndexTest, MatchQualifiedNamesWithOneScope) { - auto I = DexIndex::build( +TEST(DexTest, MatchQualifiedNamesWithOneScope) { + auto I = Dex::build( generateSymbols({"a::y1", "a::y2", "a::x", "b::y2", "y3"}), URISchemes); FuzzyFindRequest Req; Req.Query = "y"; @@ -549,8 +547,8 @@ EXPECT_THAT(match(*I, Req), UnorderedElementsAre("a::y1", "a::y2")); } -TEST(DexIndexTest, MatchQualifiedNamesWithMultipleScopes) { - auto I = DexIndex::build( +TEST(DexTest, MatchQualifiedNamesWithMultipleScopes) { + auto I = Dex::build( generateSymbols({"a::y1", "a::y2", "a::x", "b::y3", "y3"}), URISchemes); FuzzyFindRequest Req; Req.Query = "y"; @@ -558,24 +556,24 @@ EXPECT_THAT(match(*I, Req), UnorderedElementsAre("a::y1", "a::y2", "b::y3")); } -TEST(DexIndexTest, NoMatchNestedScopes) { - auto I = DexIndex::build(generateSymbols({"a::y1", "a::b::y2"}), URISchemes); +TEST(DexTest, NoMatchNestedScopes) { + auto I = Dex::build(generateSymbols({"a::y1", "a::b::y2"}), URISchemes); FuzzyFindRequest Req; Req.Query = "y"; Req.Scopes = {"a::"}; EXPECT_THAT(match(*I, Req), UnorderedElementsAre("a::y1")); } -TEST(DexIndexTest, IgnoreCases) { - auto I = DexIndex::build(generateSymbols({"ns::ABC", "ns::abc"}), URISchemes); +TEST(DexTest, IgnoreCases) { + auto I = Dex::build(generateSymbols({"ns::ABC", "ns::abc"}), URISchemes); FuzzyFindRequest Req; Req.Query = "AB"; Req.Scopes = {"ns::"}; EXPECT_THAT(match(*I, Req), UnorderedElementsAre("ns::ABC", "ns::abc")); } -TEST(DexIndexTest, Lookup) { - auto I = DexIndex::build(generateSymbols({"ns::abc", "ns::xyz"}), URISchemes); +TEST(DexTest, Lookup) { + auto I = Dex::build(generateSymbols({"ns::abc", "ns::xyz"}), URISchemes); EXPECT_THAT(lookup(*I, SymbolID("ns::abc")), UnorderedElementsAre("ns::abc")); EXPECT_THAT(lookup(*I, {SymbolID("ns::abc"), SymbolID("ns::xyz")}), UnorderedElementsAre("ns::abc", "ns::xyz")); @@ -584,14 +582,14 @@ EXPECT_THAT(lookup(*I, SymbolID("ns::nonono")), UnorderedElementsAre()); } -TEST(DexIndexTest, ProximityPathsBoosting) { +TEST(DexTest, ProximityPathsBoosting) { auto RootSymbol = symbol("root::abc"); RootSymbol.CanonicalDeclaration.FileURI = "unittest:///file.h"; auto CloseSymbol = symbol("close::abc"); CloseSymbol.CanonicalDeclaration.FileURI = "unittest:///a/b/c/d/e/f/file.h"; std::vector Symbols{CloseSymbol, RootSymbol}; - DexIndex I(Symbols, URISchemes); + Dex I(Symbols, URISchemes); FuzzyFindRequest Req; Req.Query = "abc"; Index: clang-tools-extra/unittests/clangd/TestIndex.h =================================================================== --- clang-tools-extra/unittests/clangd/TestIndex.h +++ clang-tools-extra/unittests/clangd/TestIndex.h @@ -12,10 +12,6 @@ #include "index/Index.h" #include "index/Merge.h" -#include "index/dex/DexIndex.h" -#include "index/dex/Iterator.h" -#include "index/dex/Token.h" -#include "index/dex/Trigram.h" namespace clang { namespace clangd {