Merge pull request #20670 from geoffw0/missingmetric

Rust: Add expressions with known type metric
This commit is contained in:
Geoffrey White
2025-10-22 15:42:48 +01:00
committed by GitHub
4 changed files with 25 additions and 1 deletions

View File

@@ -0,0 +1,4 @@
---
category: minorAnalysis
---
* The "Low Rust analysis quality" query (`rust/diagnostic/database-quality`), used by the tool status page, has been extended with a measure of successful type inference.

View File

@@ -6,6 +6,7 @@
import rust
import codeql.util.ReportStats
import codeql.rust.internal.TypeInference as TypeInference
module CallTargetStats implements StatsSig {
int getNumberOfOk() { result = count(CallExprBase c | exists(c.getStaticTarget())) }
@@ -41,6 +42,20 @@ module MacroCallTargetStats implements StatsSig {
string getNotOkText() { result = "macro calls with missing call target" }
}
private predicate hasGoodType(Expr e) { exists(TypeInference::inferType(e, _)) }
module ExprTypeStats implements StatsSig {
int getNumberOfOk() { result = count(Expr e | e.fromSource() and hasGoodType(e)) }
int getNumberOfNotOk() { result = count(Expr e | e.fromSource() and not hasGoodType(e)) }
string getOkText() { result = "expressions with known type" }
string getNotOkText() { result = "expressions with unknown type" }
}
module CallTargetStatsReport = ReportStats<CallTargetStats>;
module MacroCallTargetStatsReport = ReportStats<MacroCallTargetStats>;
module ExprTypeStatsReport = ReportStats<ExprTypeStats>;

View File

@@ -13,6 +13,8 @@ private predicate diagnostic(string msg, float value, float threshold) {
CallTargetStatsReport::percentageOfOk(msg, value) and threshold = 50
or
MacroCallTargetStatsReport::percentageOfOk(msg, value) and threshold = 50
or
ExprTypeStatsReport::percentageOfOk(msg, value) and threshold = 20
}
private string getDbHealth() {

View File

@@ -54,7 +54,10 @@ where
CallTargetStatsReport::percentageOfOk(key, value) or
MacroCallTargetStatsReport::numberOfOk(key, value) or
MacroCallTargetStatsReport::numberOfNotOk(key, value) or
MacroCallTargetStatsReport::percentageOfOk(key, value)
MacroCallTargetStatsReport::percentageOfOk(key, value) or
ExprTypeStatsReport::numberOfOk(key, value) or
ExprTypeStatsReport::numberOfNotOk(key, value) or
ExprTypeStatsReport::percentageOfOk(key, value)
) and
/* Infinity */
value != 1.0 / 0.0 and