Skip to content

Commit d8fff44

Browse files
authored
Merge pull request #20712 from geoffw0/macrometric2
Rust: Exclude skipped files in rust/diagnostic/database-quality
2 parents f672f6b + 0e7d410 commit d8fff44

File tree

2 files changed

+41
-6
lines changed

2 files changed

+41
-6
lines changed

rust/ql/lib/codeql/files/FileSystem.qll

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ module Folder = Impl::Folder;
3838

3939
/** A file. */
4040
class File extends Container, Impl::File {
41-
/** Holds if this file was extracted from ordinary source code. */
41+
/**
42+
* Holds if this file was extracted from the source code of the target project
43+
* (rather than another location such as inside a dependency).
44+
*/
4245
predicate fromSource() {
4346
exists(ExtractorStep s | s.getAction() = "Extract" and s.getFile() = this)
4447
}

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

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,21 @@ import rust
88
import codeql.util.ReportStats
99
import codeql.rust.internal.TypeInference as TypeInference
1010

11+
/**
12+
* A file that is included in the quality statistics.
13+
*/
14+
private class RelevantFile extends File {
15+
RelevantFile() {
16+
// files that are not skipped by the compilation
17+
not this.(ExtractedFile).isSkippedByCompilation()
18+
}
19+
}
20+
1121
module CallTargetStats implements StatsSig {
12-
int getNumberOfOk() { result = count(CallExprBase c | exists(c.getStaticTarget())) }
22+
int getNumberOfOk() {
23+
result =
24+
count(CallExprBase c | c.getFile() instanceof RelevantFile and exists(c.getStaticTarget()))
25+
}
1326

1427
private predicate isLambdaCall(CallExpr call) {
1528
exists(Expr receiver | receiver = call.getFunction() |
@@ -19,6 +32,7 @@ module CallTargetStats implements StatsSig {
1932
}
2033

2134
additional predicate isNotOkCall(CallExprBase c) {
35+
c.getFile() instanceof RelevantFile and
2236
not exists(c.getStaticTarget()) and
2337
not isLambdaCall(c)
2438
}
@@ -31,9 +45,13 @@ module CallTargetStats implements StatsSig {
3145
}
3246

3347
module MacroCallTargetStats implements StatsSig {
34-
int getNumberOfOk() { result = count(MacroCall c | c.hasMacroCallExpansion()) }
48+
int getNumberOfOk() {
49+
result = count(MacroCall c | c.getFile() instanceof RelevantFile and c.hasMacroCallExpansion())
50+
}
3551

36-
additional predicate isNotOkCall(MacroCall c) { not c.hasMacroCallExpansion() }
52+
additional predicate isNotOkCall(MacroCall c) {
53+
c.getFile() instanceof RelevantFile and not c.hasMacroCallExpansion()
54+
}
3755

3856
int getNumberOfNotOk() { result = count(MacroCall c | isNotOkCall(c)) }
3957

@@ -45,9 +63,23 @@ module MacroCallTargetStats implements StatsSig {
4563
private predicate hasGoodType(Expr e) { exists(TypeInference::inferType(e, _)) }
4664

4765
module ExprTypeStats implements StatsSig {
48-
int getNumberOfOk() { result = count(Expr e | e.fromSource() and hasGoodType(e)) }
66+
int getNumberOfOk() {
67+
result =
68+
count(Expr e |
69+
e.getFile() instanceof RelevantFile and
70+
e.fromSource() and
71+
hasGoodType(e)
72+
)
73+
}
4974

50-
int getNumberOfNotOk() { result = count(Expr e | e.fromSource() and not hasGoodType(e)) }
75+
int getNumberOfNotOk() {
76+
result =
77+
count(Expr e |
78+
e.getFile() instanceof RelevantFile and
79+
e.fromSource() and
80+
not hasGoodType(e)
81+
)
82+
}
5183

5284
string getOkText() { result = "expressions with known type" }
5385

0 commit comments

Comments
 (0)