Rust: Add type inference inconsistency counts to the stats summary

This commit is contained in:
Simon Friis Vindum
2025-05-23 14:20:44 +02:00
parent ba4950fb89
commit 52280625ee
4 changed files with 44 additions and 0 deletions

View File

@@ -2,4 +2,28 @@
* Provides classes for recognizing type inference inconsistencies.
*/
private import Type
private import TypeMention
private import TypeInference::Consistency as Consistency
import TypeInference::Consistency
query predicate illFormedTypeMention(TypeMention tm) {
Consistency::illFormedTypeMention(tm) and
// Only include inconsistencies in the source, as we otherwise get
// inconsistencies from library code in every project.
tm.fromSource()
}
int getTypeInferenceInconsistencyCounts(string type) {
type = "Missing type parameter ID" and
result = count(TypeParameter tp | missingTypeParameterId(tp) | tp)
or
type = "Non-functional type parameter ID" and
result = count(TypeParameter tp | nonFunctionalTypeParameterId(tp) | tp)
or
type = "Non-injective type parameter ID" and
result = count(TypeParameter tp | nonInjectiveTypeParameterId(tp, _) | tp)
or
type = "Ill-formed type mention" and
result = count(TypeMention tm | illFormedTypeMention(tm) | tm)
}

View File

@@ -8,6 +8,7 @@ private import codeql.rust.dataflow.internal.DataFlowImpl
private import codeql.rust.dataflow.internal.TaintTrackingImpl
private import codeql.rust.internal.AstConsistency as AstConsistency
private import codeql.rust.internal.PathResolutionConsistency as PathResolutionConsistency
private import codeql.rust.internal.TypeInferenceConsistency as TypeInferenceConsistency
private import codeql.rust.controlflow.internal.CfgConsistency as CfgConsistency
private import codeql.rust.dataflow.internal.DataFlowConsistency as DataFlowConsistency
private import codeql.rust.dataflow.internal.SsaImpl::Consistency as SsaConsistency
@@ -52,6 +53,13 @@ int getTotalPathResolutionInconsistencies() {
sum(string type | | PathResolutionConsistency::getPathResolutionInconsistencyCounts(type))
}
/**
* Gets a count of the total number of type inference inconsistencies in the database.
*/
int getTotalTypeInferenceInconsistencies() {
result = sum(string type | | TypeInferenceConsistency::getTypeInferenceInconsistencyCounts(type))
}
/**
* Gets a count of the total number of control flow graph inconsistencies in the database.
*/
@@ -159,6 +167,13 @@ predicate inconsistencyStats(string key, int value) {
key = "Inconsistencies - data flow" and value = getTotalDataFlowInconsistencies()
}
/**
* Gets summary statistics about inconsistencies related to type inference.
*/
predicate typeInferenceInconsistencyStats(string key, int value) {
key = "Inconsistencies - Type inference" and value = getTotalTypeInferenceInconsistencies()
}
/**
* Gets summary statistics about taint.
*/

View File

@@ -17,5 +17,7 @@ where
or
inconsistencyStats(key, value)
or
typeInferenceInconsistencyStats(key, value)
or
taintStats(key, value)
select key, value order by key

View File

@@ -0,0 +1,3 @@
illFormedTypeMention
| sqlx.rs:158:13:158:81 | ...::BoxDynError |
| sqlx.rs:160:17:160:86 | ...::BoxDynError |