Skip to content

Commit d691c32

Browse files
committed
Rust: Add expressions with unknown type metric (expected by DCA).
1 parent 1047c3e commit d691c32

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

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/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)