Skip to content

Commit 5228062

Browse files
committed
Rust: Add type inference inconsistency counts to the stats summary
1 parent ba4950f commit 5228062

File tree

4 files changed

+44
-0
lines changed

4 files changed

+44
-0
lines changed

rust/ql/lib/codeql/rust/internal/TypeInferenceConsistency.qll

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,28 @@
22
* Provides classes for recognizing type inference inconsistencies.
33
*/
44

5+
private import Type
6+
private import TypeMention
7+
private import TypeInference::Consistency as Consistency
58
import TypeInference::Consistency
9+
10+
query predicate illFormedTypeMention(TypeMention tm) {
11+
Consistency::illFormedTypeMention(tm) and
12+
// Only include inconsistencies in the source, as we otherwise get
13+
// inconsistencies from library code in every project.
14+
tm.fromSource()
15+
}
16+
17+
int getTypeInferenceInconsistencyCounts(string type) {
18+
type = "Missing type parameter ID" and
19+
result = count(TypeParameter tp | missingTypeParameterId(tp) | tp)
20+
or
21+
type = "Non-functional type parameter ID" and
22+
result = count(TypeParameter tp | nonFunctionalTypeParameterId(tp) | tp)
23+
or
24+
type = "Non-injective type parameter ID" and
25+
result = count(TypeParameter tp | nonInjectiveTypeParameterId(tp, _) | tp)
26+
or
27+
type = "Ill-formed type mention" and
28+
result = count(TypeMention tm | illFormedTypeMention(tm) | tm)
29+
}

rust/ql/src/queries/summary/Stats.qll

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ private import codeql.rust.dataflow.internal.DataFlowImpl
88
private import codeql.rust.dataflow.internal.TaintTrackingImpl
99
private import codeql.rust.internal.AstConsistency as AstConsistency
1010
private import codeql.rust.internal.PathResolutionConsistency as PathResolutionConsistency
11+
private import codeql.rust.internal.TypeInferenceConsistency as TypeInferenceConsistency
1112
private import codeql.rust.controlflow.internal.CfgConsistency as CfgConsistency
1213
private import codeql.rust.dataflow.internal.DataFlowConsistency as DataFlowConsistency
1314
private import codeql.rust.dataflow.internal.SsaImpl::Consistency as SsaConsistency
@@ -52,6 +53,13 @@ int getTotalPathResolutionInconsistencies() {
5253
sum(string type | | PathResolutionConsistency::getPathResolutionInconsistencyCounts(type))
5354
}
5455

56+
/**
57+
* Gets a count of the total number of type inference inconsistencies in the database.
58+
*/
59+
int getTotalTypeInferenceInconsistencies() {
60+
result = sum(string type | | TypeInferenceConsistency::getTypeInferenceInconsistencyCounts(type))
61+
}
62+
5563
/**
5664
* Gets a count of the total number of control flow graph inconsistencies in the database.
5765
*/
@@ -159,6 +167,13 @@ predicate inconsistencyStats(string key, int value) {
159167
key = "Inconsistencies - data flow" and value = getTotalDataFlowInconsistencies()
160168
}
161169

170+
/**
171+
* Gets summary statistics about inconsistencies related to type inference.
172+
*/
173+
predicate typeInferenceInconsistencyStats(string key, int value) {
174+
key = "Inconsistencies - Type inference" and value = getTotalTypeInferenceInconsistencies()
175+
}
176+
162177
/**
163178
* Gets summary statistics about taint.
164179
*/

rust/ql/src/queries/summary/SummaryStats.ql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,7 @@ where
1717
or
1818
inconsistencyStats(key, value)
1919
or
20+
typeInferenceInconsistencyStats(key, value)
21+
or
2022
taintStats(key, value)
2123
select key, value order by key
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
illFormedTypeMention
2+
| sqlx.rs:158:13:158:81 | ...::BoxDynError |
3+
| sqlx.rs:160:17:160:86 | ...::BoxDynError |

0 commit comments

Comments
 (0)