Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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.
15 changes: 15 additions & 0 deletions rust/ql/src/queries/telemetry/DatabaseQuality.qll
Original file line number Diff line number Diff line change
Expand Up @@ -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())) }
Expand Down Expand Up @@ -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>;
2 changes: 2 additions & 0 deletions rust/ql/src/queries/telemetry/DatabaseQualityDiagnostics.ql
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
5 changes: 4 additions & 1 deletion rust/ql/src/queries/telemetry/ExtractorInformation.ql
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down