-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Rust: Add another type inference debug predicate #19728
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rust: Add another type inference debug predicate #19728
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Adds new debug predicates to count and identify the maximum number of type inferences for AST nodes in Rust CodeQL.
- Introduces
countTypes
to tally how many times a type is inferred for a node and path. - Introduces
maxTypes
to 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 | |
) |
Copilot uses AI. Check for mistakes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.