[clang-tools-extra] 890190a - Revert "Revert "[clangd] Use ML Code completion ranking as default.""
Utkarsh Saxena via cfe-commits
cfe-commits at lists.llvm.org
Tue Mar 2 09:04:03 PST 2021
Author: Utkarsh Saxena
Date: 2021-03-02T18:03:52+01:00
New Revision: 890190a61d648755c9213d4a38af294f7dad3de2
URL: https://github.com/llvm/llvm-project/commit/890190a61d648755c9213d4a38af294f7dad3de2
DIFF: https://github.com/llvm/llvm-project/commit/890190a61d648755c9213d4a38af294f7dad3de2.diff
LOG: Revert "Revert "[clangd] Use ML Code completion ranking as default.""
The ASAN failure was fixed by
https://github.com/llvm/llvm-project/commit/bf935a034b345e905907c80030c67ef8f737d56a.
This reverts commit 7f086d74c347750c1da619058eb5b3e79c2fae14.
Added:
Modified:
clang-tools-extra/clangd/CodeComplete.h
clang-tools-extra/clangd/Quality.cpp
clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/clangd/CodeComplete.h b/clang-tools-extra/clangd/CodeComplete.h
index debf71d4117c..40a528caa939 100644
--- a/clang-tools-extra/clangd/CodeComplete.h
+++ b/clang-tools-extra/clangd/CodeComplete.h
@@ -133,7 +133,7 @@ struct CodeCompleteOptions {
enum CodeCompletionRankingModel {
Heuristics,
DecisionForest,
- } RankingModel = Heuristics;
+ } RankingModel = DecisionForest;
/// Callback used to score a CompletionCandidate if DecisionForest ranking
/// model is enabled.
diff --git a/clang-tools-extra/clangd/Quality.cpp b/clang-tools-extra/clangd/Quality.cpp
index b49392bc7d04..99421009c71c 100644
--- a/clang-tools-extra/clangd/Quality.cpp
+++ b/clang-tools-extra/clangd/Quality.cpp
@@ -580,12 +580,16 @@ evaluateDecisionForest(const SymbolQualitySignals &Quality,
// multiplciative boost (like NameMatch). This allows us to weigh the
// prediciton score and NameMatch appropriately.
Scores.ExcludingName = pow(Base, Evaluate(E));
- // NeedsFixIts is not part of the DecisionForest as generating training
- // data that needs fixits is not-feasible.
+ // Following cases are not part of the generated training dataset:
+ // - Symbols with `NeedsFixIts`.
+ // - Forbidden symbols.
+ // - Keywords: Dataset contains only macros and decls.
if (Relevance.NeedsFixIts)
Scores.ExcludingName *= 0.5;
if (Relevance.Forbidden)
Scores.ExcludingName *= 0;
+ if (Quality.Category == SymbolQualitySignals::Keyword)
+ Scores.ExcludingName *= 4;
// NameMatch should be a multiplier on total score to support rescoring.
Scores.Total = Relevance.NameMatch * Scores.ExcludingName;
diff --git a/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp b/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
index b7a40179aa98..0ff1e83b7613 100644
--- a/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
+++ b/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
@@ -647,13 +647,13 @@ TEST(CompletionTest, ScopedWithFilter) {
}
TEST(CompletionTest, ReferencesAffectRanking) {
- auto Results = completions("int main() { abs^ }", {ns("absl"), func("absb")});
- EXPECT_THAT(Results.Completions,
- HasSubsequence(Named("absb"), Named("absl")));
- Results = completions("int main() { abs^ }",
- {withReferences(10000, ns("absl")), func("absb")});
- EXPECT_THAT(Results.Completions,
- HasSubsequence(Named("absl"), Named("absb")));
+ EXPECT_THAT(completions("int main() { abs^ }", {func("absA"), func("absB")})
+ .Completions,
+ HasSubsequence(Named("absA"), Named("absB")));
+ EXPECT_THAT(completions("int main() { abs^ }",
+ {func("absA"), withReferences(1000, func("absB"))})
+ .Completions,
+ HasSubsequence(Named("absB"), Named("absA")));
}
TEST(CompletionTest, ContextWords) {
More information about the cfe-commits
mailing list