Skip to content

Commit a627277

Browse files
committed
Rust: Add type inference inconsistency counts to the stats summary
1 parent 64c2876 commit a627277

File tree

5 files changed

+33
-4
lines changed

5 files changed

+33
-4
lines changed

rust/ql/integration-tests/hello-project/summary.expected

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66
| Files extracted - without errors % | 80 |
77
| Inconsistencies - AST | 0 |
88
| Inconsistencies - CFG | 0 |
9+
| Inconsistencies - Data flow | 0 |
910
| Inconsistencies - Path resolution | 0 |
1011
| Inconsistencies - SSA | 0 |
11-
| Inconsistencies - data flow | 0 |
12+
| Inconsistencies - Type inference | 1967 |
1213
| Lines of code extracted | 6 |
1314
| Lines of user code extracted | 6 |
1415
| Macro calls - resolved | 2 |

rust/ql/integration-tests/hello-workspace/summary.cargo.expected

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66
| Files extracted - without errors % | 100 |
77
| Inconsistencies - AST | 0 |
88
| Inconsistencies - CFG | 0 |
9+
| Inconsistencies - Data flow | 0 |
910
| Inconsistencies - Path resolution | 0 |
1011
| Inconsistencies - SSA | 0 |
11-
| Inconsistencies - data flow | 0 |
12+
| Inconsistencies - Type inference | 1967 |
1213
| Lines of code extracted | 9 |
1314
| Lines of user code extracted | 9 |
1415
| Macro calls - resolved | 2 |

rust/ql/integration-tests/hello-workspace/summary.rust-project.expected

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66
| Files extracted - without errors % | 100 |
77
| Inconsistencies - AST | 0 |
88
| Inconsistencies - CFG | 0 |
9+
| Inconsistencies - Data flow | 0 |
910
| Inconsistencies - Path resolution | 0 |
1011
| Inconsistencies - SSA | 0 |
11-
| Inconsistencies - data flow | 0 |
12+
| Inconsistencies - Type inference | 1967 |
1213
| Lines of code extracted | 9 |
1314
| Lines of user code extracted | 9 |
1415
| Macro calls - resolved | 2 |

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

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

5+
private import Type
6+
private import TypeMention
57
import TypeInference::Consistency
8+
9+
int getTypeInferenceInconsistencyCounts(string type) {
10+
type = "Missing type parameter ID" and
11+
result = count(TypeParameter tp | missingTypeParameterId(tp) | tp)
12+
or
13+
type = "Non-functional type parameter ID" and
14+
result = count(TypeParameter tp | nonFunctionalTypeParameterId(tp) | tp)
15+
or
16+
type = "Non-injective type parameter ID" and
17+
result = count(TypeParameter tp | nonInjectiveTypeParameterId(tp, _) | tp)
18+
or
19+
type = "Ill-formed type mention" and
20+
result = count(TypeMention tm | illFormedTypeMention(tm) | tm)
21+
}

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

Lines changed: 11 additions & 1 deletion
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
*/
@@ -156,7 +164,9 @@ predicate inconsistencyStats(string key, int value) {
156164
or
157165
key = "Inconsistencies - SSA" and value = getTotalSsaInconsistencies()
158166
or
159-
key = "Inconsistencies - data flow" and value = getTotalDataFlowInconsistencies()
167+
key = "Inconsistencies - Data flow" and value = getTotalDataFlowInconsistencies()
168+
or
169+
key = "Inconsistencies - Type inference" and value = getTotalTypeInferenceInconsistencies()
160170
}
161171

162172
/**

0 commit comments

Comments
 (0)