[clang-tools-extra] 9b1666f - [clangd] Rename evaluate() to evaluateHeuristics()
Utkarsh Saxena via cfe-commits
cfe-commits at lists.llvm.org
Mon Sep 28 11:05:11 PDT 2020
Author: Utkarsh Saxena
Date: 2020-09-28T20:05:01+02:00
New Revision: 9b1666f3ce2b02be70f8e7f82c3ec5c81262010b
URL: https://github.com/llvm/llvm-project/commit/9b1666f3ce2b02be70f8e7f82c3ec5c81262010b
DIFF: https://github.com/llvm/llvm-project/commit/9b1666f3ce2b02be70f8e7f82c3ec5c81262010b.diff
LOG: [clangd] Rename evaluate() to evaluateHeuristics()
Since we have 2 scoring functions (heuristics and decision forest),
renaming the existing evaluate() function to be more descriptive of the
Heuristics being evaluated in it.
Differential Revision: https://reviews.llvm.org/D88431
Added:
Modified:
clang-tools-extra/clangd/CodeComplete.cpp
clang-tools-extra/clangd/FindSymbols.cpp
clang-tools-extra/clangd/Quality.cpp
clang-tools-extra/clangd/Quality.h
clang-tools-extra/clangd/XRefs.cpp
clang-tools-extra/clangd/index/dex/Dex.cpp
clang-tools-extra/clangd/unittests/QualityTests.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/clangd/CodeComplete.cpp b/clang-tools-extra/clangd/CodeComplete.cpp
index 90e793f11564..1d2770823190 100644
--- a/clang-tools-extra/clangd/CodeComplete.cpp
+++ b/clang-tools-extra/clangd/CodeComplete.cpp
@@ -1632,8 +1632,8 @@ class CodeCompleteFlow {
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
index e37d73103e36..e86c01d4076e 100644
--- a/clang-tools-extra/clangd/FindSymbols.cpp
+++ b/clang-tools-extra/clangd/FindSymbols.cpp
@@ -116,8 +116,8 @@ getWorkspaceSymbols(llvm::StringRef Query, int Limit,
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.cpp b/clang-tools-extra/clangd/Quality.cpp
index 37f1cf62821a..55b97eef123f 100644
--- a/clang-tools-extra/clangd/Quality.cpp
+++ b/clang-tools-extra/clangd/Quality.cpp
@@ -201,7 +201,7 @@ void SymbolQualitySignals::merge(const Symbol &IndexResult) {
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 @@ float SymbolQualitySignals::evaluate() const {
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 @@ SymbolRelevanceSignals::calculateDerivedSignals() const {
return Derived;
}
-float SymbolRelevanceSignals::evaluate() const {
+float SymbolRelevanceSignals::evaluateHeuristics() const {
DerivedSignals Derived = calculateDerivedSignals();
float Score = 1;
@@ -445,7 +445,7 @@ float SymbolRelevanceSignals::evaluate() const {
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/Quality.h b/clang-tools-extra/clangd/Quality.h
index 694653e1a714..afbc0f10208f 100644
--- a/clang-tools-extra/clangd/Quality.h
+++ b/clang-tools-extra/clangd/Quality.h
@@ -77,9 +77,8 @@ struct SymbolQualitySignals {
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 @@ struct SymbolRelevanceSignals {
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/XRefs.cpp b/clang-tools-extra/clangd/XRefs.cpp
index 973816253f42..b4487453847c 100644
--- a/clang-tools-extra/clangd/XRefs.cpp
+++ b/clang-tools-extra/clangd/XRefs.cpp
@@ -514,8 +514,8 @@ locateSymbolTextually(const SpelledWord &Word, ParsedAST &AST,
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
index 8082ffd75ad9..29aea353e07c 100644
--- a/clang-tools-extra/clangd/index/dex/Dex.cpp
+++ b/clang-tools-extra/clangd/index/dex/Dex.cpp
@@ -160,8 +160,8 @@ std::unique_ptr<Iterator> Dex::createFileProximityIterator(
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 @@ Dex::createTypeBoostingIterator(llvm::ArrayRef<std::string> Types) const {
std::vector<std::unique_ptr<Iterator>> 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
index d2d02618313c..f5fcb0e8d04e 100644
--- a/clang-tools-extra/clangd/unittests/QualityTests.cpp
+++ b/clang-tools-extra/clangd/unittests/QualityTests.cpp
@@ -196,25 +196,27 @@ TEST(QualityTests, SymbolRelevanceSignalExtraction) {
// 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 @@ TEST(QualityTests, SymbolQualitySignalsSanity) {
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 @@ TEST(QualityTests, SymbolRelevanceSignalsSanity) {
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 @@ TEST(QualityTests, ScopeProximity) {
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 @@ TEST(QualityTests, ItemWithFixItsRankedDown) {
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
More information about the cfe-commits
mailing list