From 6f1eca8be1851dc9fd11d6560994d87cfa3785d8 Mon Sep 17 00:00:00 2001 From: Geoffrey White <40627776+geoffw0@users.noreply.github.com> Date: Fri, 24 Oct 2025 15:18:11 +0100 Subject: [PATCH 1/4] Rust: Make the QLDoc for fromSource a bit more precise. --- rust/ql/lib/codeql/files/FileSystem.qll | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/rust/ql/lib/codeql/files/FileSystem.qll b/rust/ql/lib/codeql/files/FileSystem.qll index 854de53652f4..ebc4085fbbb5 100644 --- a/rust/ql/lib/codeql/files/FileSystem.qll +++ b/rust/ql/lib/codeql/files/FileSystem.qll @@ -38,7 +38,10 @@ module Folder = Impl::Folder; /** A file. */ class File extends Container, Impl::File { - /** Holds if this file was extracted from ordinary source code. */ + /** + * Holds if this file was extracted from the source code of the target project + * (rather than another location such as inside a dependency). + */ predicate fromSource() { exists(ExtractorStep s | s.getAction() = "Extract" and s.getFile() = this) } From 25e4b790a3634e3e1fc8ee1024def4ff12458085 Mon Sep 17 00:00:00 2001 From: Geoffrey White <40627776+geoffw0@users.noreply.github.com> Date: Tue, 28 Oct 2025 11:46:54 +0000 Subject: [PATCH 2/4] Rust: Exclude skipped files from MacroCallTargetStats. --- rust/ql/src/queries/telemetry/DatabaseQuality.qll | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/rust/ql/src/queries/telemetry/DatabaseQuality.qll b/rust/ql/src/queries/telemetry/DatabaseQuality.qll index 0b874a9b9cef..cdac11b94e7e 100644 --- a/rust/ql/src/queries/telemetry/DatabaseQuality.qll +++ b/rust/ql/src/queries/telemetry/DatabaseQuality.qll @@ -31,11 +31,21 @@ module CallTargetStats implements StatsSig { } module MacroCallTargetStats implements StatsSig { - int getNumberOfOk() { result = count(MacroCall c | c.hasMacroCallExpansion()) } + int getNumberOfOk() { + result = + count(MacroCall c | + not c.getFile().(ExtractedFile).isSkippedByCompilation() and c.hasMacroCallExpansion() + ) + } additional predicate isNotOkCall(MacroCall c) { not c.hasMacroCallExpansion() } - int getNumberOfNotOk() { result = count(MacroCall c | isNotOkCall(c)) } + int getNumberOfNotOk() { + result = + count(MacroCall c | + not c.getFile().(ExtractedFile).isSkippedByCompilation() and isNotOkCall(c) + ) + } string getOkText() { result = "macro calls with call target" } From 5ca0bd071decbb78fa60c07969e9b1c7b399357f Mon Sep 17 00:00:00 2001 From: Geoffrey White <40627776+geoffw0@users.noreply.github.com> Date: Tue, 28 Oct 2025 16:07:59 +0000 Subject: [PATCH 3/4] Rust: Exclude skipped files from CallTargetStats and ExprTypeStats as well. --- .../src/queries/telemetry/DatabaseQuality.qll | 44 ++++++++++++++----- 1 file changed, 33 insertions(+), 11 deletions(-) diff --git a/rust/ql/src/queries/telemetry/DatabaseQuality.qll b/rust/ql/src/queries/telemetry/DatabaseQuality.qll index cdac11b94e7e..0c3e4dcd448a 100644 --- a/rust/ql/src/queries/telemetry/DatabaseQuality.qll +++ b/rust/ql/src/queries/telemetry/DatabaseQuality.qll @@ -8,8 +8,21 @@ import rust import codeql.util.ReportStats import codeql.rust.internal.TypeInference as TypeInference +/** + * A file that is included in the quality statistics. + */ +private class RelevantFile extends File { + RelevantFile() { + // files that are not skipped by the compilation + not this.(ExtractedFile).isSkippedByCompilation() + } +} + module CallTargetStats implements StatsSig { - int getNumberOfOk() { result = count(CallExprBase c | exists(c.getStaticTarget())) } + int getNumberOfOk() { + result = + count(CallExprBase c | c.getFile() instanceof RelevantFile and exists(c.getStaticTarget())) + } private predicate isLambdaCall(CallExpr call) { exists(Expr receiver | receiver = call.getFunction() | @@ -19,6 +32,7 @@ module CallTargetStats implements StatsSig { } additional predicate isNotOkCall(CallExprBase c) { + c.getFile() instanceof RelevantFile and not exists(c.getStaticTarget()) and not isLambdaCall(c) } @@ -32,19 +46,13 @@ module CallTargetStats implements StatsSig { module MacroCallTargetStats implements StatsSig { int getNumberOfOk() { - result = - count(MacroCall c | - not c.getFile().(ExtractedFile).isSkippedByCompilation() and c.hasMacroCallExpansion() - ) + result = count(MacroCall c | c.getFile() instanceof RelevantFile and c.hasMacroCallExpansion()) } additional predicate isNotOkCall(MacroCall c) { not c.hasMacroCallExpansion() } int getNumberOfNotOk() { - result = - count(MacroCall c | - not c.getFile().(ExtractedFile).isSkippedByCompilation() and isNotOkCall(c) - ) + result = count(MacroCall c | c.getFile() instanceof RelevantFile and isNotOkCall(c)) } string getOkText() { result = "macro calls with call target" } @@ -55,9 +63,23 @@ module MacroCallTargetStats implements StatsSig { 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 getNumberOfOk() { + result = + count(Expr e | + e.getFile() instanceof RelevantFile and + e.fromSource() and + hasGoodType(e) + ) + } - int getNumberOfNotOk() { result = count(Expr e | e.fromSource() and not hasGoodType(e)) } + int getNumberOfNotOk() { + result = + count(Expr e | + e.getFile() instanceof RelevantFile and + e.fromSource() and + not hasGoodType(e) + ) + } string getOkText() { result = "expressions with known type" } From 7a864c5244365843fde5fa5ad2d119244b1b5abc Mon Sep 17 00:00:00 2001 From: Geoffrey White <40627776+geoffw0@users.noreply.github.com> Date: Wed, 29 Oct 2025 12:13:12 +0000 Subject: [PATCH 4/4] Rust: Implement suggestion from review. --- rust/ql/src/queries/telemetry/DatabaseQuality.qll | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/rust/ql/src/queries/telemetry/DatabaseQuality.qll b/rust/ql/src/queries/telemetry/DatabaseQuality.qll index 0c3e4dcd448a..64adf9826dc1 100644 --- a/rust/ql/src/queries/telemetry/DatabaseQuality.qll +++ b/rust/ql/src/queries/telemetry/DatabaseQuality.qll @@ -49,12 +49,12 @@ module MacroCallTargetStats implements StatsSig { result = count(MacroCall c | c.getFile() instanceof RelevantFile and c.hasMacroCallExpansion()) } - additional predicate isNotOkCall(MacroCall c) { not c.hasMacroCallExpansion() } - - int getNumberOfNotOk() { - result = count(MacroCall c | c.getFile() instanceof RelevantFile and isNotOkCall(c)) + additional predicate isNotOkCall(MacroCall c) { + c.getFile() instanceof RelevantFile and not c.hasMacroCallExpansion() } + int getNumberOfNotOk() { result = count(MacroCall c | isNotOkCall(c)) } + string getOkText() { result = "macro calls with call target" } string getNotOkText() { result = "macro calls with missing call target" }