OSDN Git Service

[clangd] Use ASTSignals in Heuristics CC Ranking.
authorUtkarsh Saxena <usx@google.com>
Mon, 18 Jan 2021 20:01:46 +0000 (21:01 +0100)
committerUtkarsh Saxena <usx@google.com>
Tue, 19 Jan 2021 18:48:42 +0000 (19:48 +0100)
Differential Revision: https://reviews.llvm.org/D94927

clang-tools-extra/clangd/Quality.cpp

index 1c41b7c..b49392b 100644 (file)
@@ -474,6 +474,21 @@ float SymbolRelevanceSignals::evaluateHeuristics() const {
   if (NeedsFixIts)
     Score *= 0.5f;
 
+  // Use a sigmoid style boosting function similar to `References`, which flats
+  // out nicely for large values. This avoids a sharp gradient for heavily
+  // referenced symbols. Use smaller gradient for ScopeRefsInFile since ideally
+  // MainFileRefs <= ScopeRefsInFile.
+  if (MainFileRefs >= 2) {
+    // E.g.: (2, 1.12), (9, 2.0), (48, 3.0).
+    float S = std::pow(MainFileRefs, -0.11);
+    Score *= 11.0 * (1 - S) / (1 + S) + 0.7;
+  }
+  if (ScopeRefsInFile >= 2) {
+    // E.g.: (2, 1.04), (14, 2.0), (109, 3.0), (400, 3.6).
+    float S = std::pow(ScopeRefsInFile, -0.10);
+    Score *= 10.0 * (1 - S) / (1 + S) + 0.7;
+  }
+
   return Score;
 }