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
5 changes: 4 additions & 1 deletion rust/ql/lib/codeql/files/FileSystem.qll
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
42 changes: 37 additions & 5 deletions rust/ql/src/queries/telemetry/DatabaseQuality.qll
Original file line number Diff line number Diff line change
Expand Up @@ -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() |
Expand All @@ -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)
}
Expand All @@ -31,9 +45,13 @@ module CallTargetStats implements StatsSig {
}

module MacroCallTargetStats implements StatsSig {
int getNumberOfOk() { result = count(MacroCall c | c.hasMacroCallExpansion()) }
int getNumberOfOk() {
result = count(MacroCall c | c.getFile() instanceof RelevantFile and c.hasMacroCallExpansion())
}

additional predicate isNotOkCall(MacroCall c) { not c.hasMacroCallExpansion() }
additional predicate isNotOkCall(MacroCall c) {
c.getFile() instanceof RelevantFile and not c.hasMacroCallExpansion()
}

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

Expand All @@ -45,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" }

Expand Down