Skip to content

Commit 5d2ddbf

Browse files
authored
Merge pull request #20670 from geoffw0/missingmetric
Rust: Add expressions with known type metric
2 parents 7d0509b + 7da00b3 commit 5d2ddbf

File tree

4 files changed

+25
-1
lines changed

4 files changed

+25
-1
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* 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.

rust/ql/src/queries/telemetry/DatabaseQuality.qll

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import rust
88
import codeql.util.ReportStats
9+
import codeql.rust.internal.TypeInference as TypeInference
910

1011
module CallTargetStats implements StatsSig {
1112
int getNumberOfOk() { result = count(CallExprBase c | exists(c.getStaticTarget())) }
@@ -41,6 +42,20 @@ module MacroCallTargetStats implements StatsSig {
4142
string getNotOkText() { result = "macro calls with missing call target" }
4243
}
4344

45+
private predicate hasGoodType(Expr e) { exists(TypeInference::inferType(e, _)) }
46+
47+
module ExprTypeStats implements StatsSig {
48+
int getNumberOfOk() { result = count(Expr e | e.fromSource() and hasGoodType(e)) }
49+
50+
int getNumberOfNotOk() { result = count(Expr e | e.fromSource() and not hasGoodType(e)) }
51+
52+
string getOkText() { result = "expressions with known type" }
53+
54+
string getNotOkText() { result = "expressions with unknown type" }
55+
}
56+
4457
module CallTargetStatsReport = ReportStats<CallTargetStats>;
4558

4659
module MacroCallTargetStatsReport = ReportStats<MacroCallTargetStats>;
60+
61+
module ExprTypeStatsReport = ReportStats<ExprTypeStats>;

rust/ql/src/queries/telemetry/DatabaseQualityDiagnostics.ql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ private predicate diagnostic(string msg, float value, float threshold) {
1313
CallTargetStatsReport::percentageOfOk(msg, value) and threshold = 50
1414
or
1515
MacroCallTargetStatsReport::percentageOfOk(msg, value) and threshold = 50
16+
or
17+
ExprTypeStatsReport::percentageOfOk(msg, value) and threshold = 20
1618
}
1719

1820
private string getDbHealth() {

rust/ql/src/queries/telemetry/ExtractorInformation.ql

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,10 @@ where
5454
CallTargetStatsReport::percentageOfOk(key, value) or
5555
MacroCallTargetStatsReport::numberOfOk(key, value) or
5656
MacroCallTargetStatsReport::numberOfNotOk(key, value) or
57-
MacroCallTargetStatsReport::percentageOfOk(key, value)
57+
MacroCallTargetStatsReport::percentageOfOk(key, value) or
58+
ExprTypeStatsReport::numberOfOk(key, value) or
59+
ExprTypeStatsReport::numberOfNotOk(key, value) or
60+
ExprTypeStatsReport::percentageOfOk(key, value)
5861
) and
5962
/* Infinity */
6063
value != 1.0 / 0.0 and

0 commit comments

Comments
 (0)