diff --git a/clang-tools-extra/clangd/CodeComplete.cpp b/clang-tools-extra/clangd/CodeComplete.cpp --- a/clang-tools-extra/clangd/CodeComplete.cpp +++ b/clang-tools-extra/clangd/CodeComplete.cpp @@ -1632,8 +1632,8 @@ CodeCompletion::Scores Scores; switch (Opts.RankingModel) { case RM::Heuristics: - Scores.Quality = Quality.evaluate(); - Scores.Relevance = Relevance.evaluate(); + Scores.Quality = Quality.evaluateHeuristics(); + Scores.Relevance = Relevance.evaluateHeuristics(); Scores.Total = evaluateSymbolAndRelevance(Scores.Quality, Scores.Relevance); // NameMatch is in fact a multiplier on total score, so rescoring is diff --git a/clang-tools-extra/clangd/FindSymbols.cpp b/clang-tools-extra/clangd/FindSymbols.cpp --- a/clang-tools-extra/clangd/FindSymbols.cpp +++ b/clang-tools-extra/clangd/FindSymbols.cpp @@ -116,8 +116,8 @@ return; } Relevance.merge(Sym); - auto Score = - evaluateSymbolAndRelevance(Quality.evaluate(), Relevance.evaluate()); + auto Score = evaluateSymbolAndRelevance(Quality.evaluateHeuristics(), + Relevance.evaluateHeuristics()); dlog("FindSymbols: {0}{1} = {2}\n{3}{4}\n", Sym.Scope, Sym.Name, Score, Quality, Relevance); diff --git a/clang-tools-extra/clangd/Quality.h b/clang-tools-extra/clangd/Quality.h --- a/clang-tools-extra/clangd/Quality.h +++ b/clang-tools-extra/clangd/Quality.h @@ -77,9 +77,8 @@ void merge(const CodeCompletionResult &SemaCCResult); void merge(const Symbol &IndexResult); - // FIXME(usx): Rename to evaluateHeuristics(). // Condense these signals down to a single number, higher is better. - float evaluate() const; + float evaluateHeuristics() const; }; llvm::raw_ostream &operator<<(llvm::raw_ostream &, const SymbolQualitySignals &); @@ -158,7 +157,7 @@ void merge(const Symbol &IndexResult); // Condense these signals down to a single number, higher is better. - float evaluate() const; + float evaluateHeuristics() const; }; llvm::raw_ostream &operator<<(llvm::raw_ostream &, const SymbolRelevanceSignals &); diff --git a/clang-tools-extra/clangd/Quality.cpp b/clang-tools-extra/clangd/Quality.cpp --- a/clang-tools-extra/clangd/Quality.cpp +++ b/clang-tools-extra/clangd/Quality.cpp @@ -201,7 +201,7 @@ ReservedName = ReservedName || isReserved(IndexResult.Name); } -float SymbolQualitySignals::evaluate() const { +float SymbolQualitySignals::evaluateHeuristics() const { float Score = 1; // This avoids a sharp gradient for tail symbols, and also neatly avoids the @@ -253,7 +253,7 @@ llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const SymbolQualitySignals &S) { - OS << llvm::formatv("=== Symbol quality: {0}\n", S.evaluate()); + OS << llvm::formatv("=== Symbol quality: {0}\n", S.evaluateHeuristics()); OS << llvm::formatv("\tReferences: {0}\n", S.References); OS << llvm::formatv("\tDeprecated: {0}\n", S.Deprecated); OS << llvm::formatv("\tReserved name: {0}\n", S.ReservedName); @@ -364,7 +364,7 @@ return Derived; } -float SymbolRelevanceSignals::evaluate() const { +float SymbolRelevanceSignals::evaluateHeuristics() const { DerivedSignals Derived = calculateDerivedSignals(); float Score = 1; @@ -445,7 +445,7 @@ llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const SymbolRelevanceSignals &S) { - OS << llvm::formatv("=== Symbol relevance: {0}\n", S.evaluate()); + OS << llvm::formatv("=== Symbol relevance: {0}\n", S.evaluateHeuristics()); OS << llvm::formatv("\tName: {0}\n", S.Name); OS << llvm::formatv("\tName match: {0}\n", S.NameMatch); if (S.ContextWords) diff --git a/clang-tools-extra/clangd/XRefs.cpp b/clang-tools-extra/clangd/XRefs.cpp --- a/clang-tools-extra/clangd/XRefs.cpp +++ b/clang-tools-extra/clangd/XRefs.cpp @@ -514,8 +514,8 @@ Relevance.Name = Sym.Name; Relevance.Query = SymbolRelevanceSignals::Generic; Relevance.merge(Sym); - auto Score = - evaluateSymbolAndRelevance(Quality.evaluate(), Relevance.evaluate()); + auto Score = evaluateSymbolAndRelevance(Quality.evaluateHeuristics(), + Relevance.evaluateHeuristics()); dlog("locateSymbolNamedTextuallyAt: {0}{1} = {2}\n{3}{4}\n", Sym.Scope, Sym.Name, Score, Quality, Relevance); diff --git a/clang-tools-extra/clangd/index/dex/Dex.cpp b/clang-tools-extra/clangd/index/dex/Dex.cpp --- a/clang-tools-extra/clangd/index/dex/Dex.cpp +++ b/clang-tools-extra/clangd/index/dex/Dex.cpp @@ -160,8 +160,8 @@ auto It = iterator(Token(Token::Kind::ProximityURI, ParentURI)); if (It->kind() != Iterator::Kind::False) { PathProximitySignals.SymbolURI = ParentURI; - BoostingIterators.push_back( - Corpus.boost(std::move(It), PathProximitySignals.evaluate())); + BoostingIterators.push_back(Corpus.boost( + std::move(It), PathProximitySignals.evaluateHeuristics())); } } BoostingIterators.push_back(Corpus.all()); @@ -174,7 +174,7 @@ std::vector> BoostingIterators; SymbolRelevanceSignals PreferredTypeSignals; PreferredTypeSignals.TypeMatchesPreferred = true; - auto Boost = PreferredTypeSignals.evaluate(); + auto Boost = PreferredTypeSignals.evaluateHeuristics(); for (const auto &T : Types) BoostingIterators.push_back( Corpus.boost(iterator(Token(Token::Kind::Type, T)), Boost)); diff --git a/clang-tools-extra/clangd/unittests/QualityTests.cpp b/clang-tools-extra/clangd/unittests/QualityTests.cpp --- a/clang-tools-extra/clangd/unittests/QualityTests.cpp +++ b/clang-tools-extra/clangd/unittests/QualityTests.cpp @@ -196,25 +196,27 @@ // Do the signals move the scores in the direction we expect? TEST(QualityTests, SymbolQualitySignalsSanity) { SymbolQualitySignals Default; - EXPECT_EQ(Default.evaluate(), 1); + EXPECT_EQ(Default.evaluateHeuristics(), 1); SymbolQualitySignals Deprecated; Deprecated.Deprecated = true; - EXPECT_LT(Deprecated.evaluate(), Default.evaluate()); + EXPECT_LT(Deprecated.evaluateHeuristics(), Default.evaluateHeuristics()); SymbolQualitySignals ReservedName; ReservedName.ReservedName = true; - EXPECT_LT(ReservedName.evaluate(), Default.evaluate()); + EXPECT_LT(ReservedName.evaluateHeuristics(), Default.evaluateHeuristics()); SymbolQualitySignals ImplementationDetail; ImplementationDetail.ImplementationDetail = true; - EXPECT_LT(ImplementationDetail.evaluate(), Default.evaluate()); + EXPECT_LT(ImplementationDetail.evaluateHeuristics(), + Default.evaluateHeuristics()); SymbolQualitySignals WithReferences, ManyReferences; WithReferences.References = 20; ManyReferences.References = 1000; - EXPECT_GT(WithReferences.evaluate(), Default.evaluate()); - EXPECT_GT(ManyReferences.evaluate(), WithReferences.evaluate()); + EXPECT_GT(WithReferences.evaluateHeuristics(), Default.evaluateHeuristics()); + EXPECT_GT(ManyReferences.evaluateHeuristics(), + WithReferences.evaluateHeuristics()); SymbolQualitySignals Keyword, Variable, Macro, Constructor, Function, Destructor, Operator; @@ -226,41 +228,44 @@ Destructor.Category = SymbolQualitySignals::Destructor; Operator.Category = SymbolQualitySignals::Operator; Function.Category = SymbolQualitySignals::Function; - EXPECT_GT(Variable.evaluate(), Default.evaluate()); - EXPECT_GT(Keyword.evaluate(), Variable.evaluate()); - EXPECT_LT(Macro.evaluate(), Default.evaluate()); - EXPECT_LT(Operator.evaluate(), Default.evaluate()); - EXPECT_LT(Constructor.evaluate(), Function.evaluate()); - EXPECT_LT(Destructor.evaluate(), Constructor.evaluate()); + EXPECT_GT(Variable.evaluateHeuristics(), Default.evaluateHeuristics()); + EXPECT_GT(Keyword.evaluateHeuristics(), Variable.evaluateHeuristics()); + EXPECT_LT(Macro.evaluateHeuristics(), Default.evaluateHeuristics()); + EXPECT_LT(Operator.evaluateHeuristics(), Default.evaluateHeuristics()); + EXPECT_LT(Constructor.evaluateHeuristics(), Function.evaluateHeuristics()); + EXPECT_LT(Destructor.evaluateHeuristics(), Constructor.evaluateHeuristics()); } TEST(QualityTests, SymbolRelevanceSignalsSanity) { SymbolRelevanceSignals Default; - EXPECT_EQ(Default.evaluate(), 1); + EXPECT_EQ(Default.evaluateHeuristics(), 1); SymbolRelevanceSignals Forbidden; Forbidden.Forbidden = true; - EXPECT_LT(Forbidden.evaluate(), Default.evaluate()); + EXPECT_LT(Forbidden.evaluateHeuristics(), Default.evaluateHeuristics()); SymbolRelevanceSignals PoorNameMatch; PoorNameMatch.NameMatch = 0.2f; - EXPECT_LT(PoorNameMatch.evaluate(), Default.evaluate()); + EXPECT_LT(PoorNameMatch.evaluateHeuristics(), Default.evaluateHeuristics()); SymbolRelevanceSignals WithSemaFileProximity; WithSemaFileProximity.SemaFileProximityScore = 0.2f; - EXPECT_GT(WithSemaFileProximity.evaluate(), Default.evaluate()); + EXPECT_GT(WithSemaFileProximity.evaluateHeuristics(), + Default.evaluateHeuristics()); ScopeDistance ScopeProximity({"x::y::"}); SymbolRelevanceSignals WithSemaScopeProximity; WithSemaScopeProximity.ScopeProximityMatch = &ScopeProximity; WithSemaScopeProximity.SemaSaysInScope = true; - EXPECT_GT(WithSemaScopeProximity.evaluate(), Default.evaluate()); + EXPECT_GT(WithSemaScopeProximity.evaluateHeuristics(), + Default.evaluateHeuristics()); SymbolRelevanceSignals WithIndexScopeProximity; WithIndexScopeProximity.ScopeProximityMatch = &ScopeProximity; WithIndexScopeProximity.SymbolScope = "x::"; - EXPECT_GT(WithSemaScopeProximity.evaluate(), Default.evaluate()); + EXPECT_GT(WithSemaScopeProximity.evaluateHeuristics(), + Default.evaluateHeuristics()); SymbolRelevanceSignals IndexProximate; IndexProximate.SymbolURI = "unittest:/foo/bar.h"; @@ -268,40 +273,43 @@ ProxSources.try_emplace(testPath("foo/baz.h")); URIDistance Distance(ProxSources); IndexProximate.FileProximityMatch = &Distance; - EXPECT_GT(IndexProximate.evaluate(), Default.evaluate()); + EXPECT_GT(IndexProximate.evaluateHeuristics(), Default.evaluateHeuristics()); SymbolRelevanceSignals IndexDistant = IndexProximate; IndexDistant.SymbolURI = "unittest:/elsewhere/path.h"; - EXPECT_GT(IndexProximate.evaluate(), IndexDistant.evaluate()) + EXPECT_GT(IndexProximate.evaluateHeuristics(), + IndexDistant.evaluateHeuristics()) << IndexProximate << IndexDistant; - EXPECT_GT(IndexDistant.evaluate(), Default.evaluate()); + EXPECT_GT(IndexDistant.evaluateHeuristics(), Default.evaluateHeuristics()); SymbolRelevanceSignals Scoped; Scoped.Scope = SymbolRelevanceSignals::FileScope; - EXPECT_LT(Scoped.evaluate(), Default.evaluate()); + EXPECT_LT(Scoped.evaluateHeuristics(), Default.evaluateHeuristics()); Scoped.Query = SymbolRelevanceSignals::CodeComplete; - EXPECT_GT(Scoped.evaluate(), Default.evaluate()); + EXPECT_GT(Scoped.evaluateHeuristics(), Default.evaluateHeuristics()); SymbolRelevanceSignals Instance; Instance.IsInstanceMember = false; - EXPECT_EQ(Instance.evaluate(), Default.evaluate()); + EXPECT_EQ(Instance.evaluateHeuristics(), Default.evaluateHeuristics()); Instance.Context = CodeCompletionContext::CCC_DotMemberAccess; - EXPECT_LT(Instance.evaluate(), Default.evaluate()); + EXPECT_LT(Instance.evaluateHeuristics(), Default.evaluateHeuristics()); Instance.IsInstanceMember = true; - EXPECT_EQ(Instance.evaluate(), Default.evaluate()); + EXPECT_EQ(Instance.evaluateHeuristics(), Default.evaluateHeuristics()); SymbolRelevanceSignals InBaseClass; InBaseClass.InBaseClass = true; - EXPECT_LT(InBaseClass.evaluate(), Default.evaluate()); + EXPECT_LT(InBaseClass.evaluateHeuristics(), Default.evaluateHeuristics()); llvm::StringSet<> Words = {"one", "two", "three"}; SymbolRelevanceSignals WithoutMatchingWord; WithoutMatchingWord.ContextWords = &Words; WithoutMatchingWord.Name = "four"; - EXPECT_EQ(WithoutMatchingWord.evaluate(), Default.evaluate()); + EXPECT_EQ(WithoutMatchingWord.evaluateHeuristics(), + Default.evaluateHeuristics()); SymbolRelevanceSignals WithMatchingWord; WithMatchingWord.ContextWords = &Words; WithMatchingWord.Name = "TheTwoTowers"; - EXPECT_GT(WithMatchingWord.evaluate(), Default.evaluate()); + EXPECT_GT(WithMatchingWord.evaluateHeuristics(), + Default.evaluateHeuristics()); } TEST(QualityTests, ScopeProximity) { @@ -310,26 +318,26 @@ Relevance.ScopeProximityMatch = &ScopeProximity; Relevance.SymbolScope = "other::"; - float NotMatched = Relevance.evaluate(); + float NotMatched = Relevance.evaluateHeuristics(); Relevance.SymbolScope = ""; - float Global = Relevance.evaluate(); + float Global = Relevance.evaluateHeuristics(); EXPECT_GT(Global, NotMatched); Relevance.SymbolScope = "llvm::"; - float NonParent = Relevance.evaluate(); + float NonParent = Relevance.evaluateHeuristics(); EXPECT_GT(NonParent, Global); Relevance.SymbolScope = "x::"; - float GrandParent = Relevance.evaluate(); + float GrandParent = Relevance.evaluateHeuristics(); EXPECT_GT(GrandParent, Global); Relevance.SymbolScope = "x::y::"; - float Parent = Relevance.evaluate(); + float Parent = Relevance.evaluateHeuristics(); EXPECT_GT(Parent, GrandParent); Relevance.SymbolScope = "x::y::z::"; - float Enclosing = Relevance.evaluate(); + float Enclosing = Relevance.evaluateHeuristics(); EXPECT_GT(Enclosing, Parent); } @@ -485,7 +493,8 @@ CodeCompletionResult(&findDecl(AST, "x"), 0, nullptr, false, true, {})); EXPECT_FALSE(RelevanceWithoutFixIt.NeedsFixIts); - EXPECT_LT(RelevanceWithFixIt.evaluate(), RelevanceWithoutFixIt.evaluate()); + EXPECT_LT(RelevanceWithFixIt.evaluateHeuristics(), + RelevanceWithoutFixIt.evaluateHeuristics()); } } // namespace