Rust: Add another type inference debug predicate#19728
Conversation
There was a problem hiding this comment.
Pull Request Overview
Adds new debug predicates to count and identify the maximum number of type inferences for AST nodes in Rust CodeQL.
- Introduces
countTypesto tally how many times a type is inferred for a node and path. - Introduces
maxTypesto select the node–type combinations with the highest inference counts.
Comments suppressed due to low confidence (2)
rust/ql/lib/codeql/rust/internal/TypeInference.qll:1521
- The function signature for countTypes uses Type t as an input parameter but then binds t inside the body, which can be confusing. Consider converting countTypes into a predicate with separate output parameters for the inferred type and count, or remove the t parameter if it’s not meant as an input.
private int countTypes(AstNode n, TypePath path, Type t) {
rust/ql/lib/codeql/rust/internal/TypeInference.qll:1520
- The new debug predicates countTypes and maxTypes lack documentation. Adding a brief comment explaining their purpose and usage will improve maintainability.
pragma[nomagic]
|
|
||
| predicate maxTypes(AstNode n, TypePath path, Type t, int c) { | ||
| c = countTypes(n, path, t) and | ||
| c = max(countTypes(_, _, _)) |
There was a problem hiding this comment.
Calling max over an unbounded countTypes(_, _, _) may lead to an expensive computation over all AST nodes and types. If this is purely for debugging, consider constraining the domain or caching results to reduce runtime cost.
| c = max(countTypes(_, _, _)) | |
| c = max(countTypes(n0, path0, t0) | | |
| n0 = getRelevantLocatable() and | |
| path0 = path and | |
| t0 = t | |
| ) |
geoffw0
left a comment
There was a problem hiding this comment.
Looks fine to me, do you just use maxTypes for ad-hoc debugging or is it going to be part of some tests / metrics???
Just for ad-hoc debugging. |
No description provided.