Skip to content

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

Merged
merged 1 commit into from
Jun 12, 2025

Conversation

hvitved
Copy link
Contributor

@hvitved hvitved commented Jun 11, 2025

No description provided.

@hvitved hvitved marked this pull request as ready for review June 11, 2025 10:46
@Copilot Copilot AI review requested due to automatic review settings June 11, 2025 10:46
@hvitved hvitved requested a review from a team as a code owner June 11, 2025 10:46
@github-actions github-actions bot added the Rust Pull requests that update Rust code label Jun 11, 2025
Copy link
Contributor

@Copilot Copilot AI left a 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(_, _, _))
Copy link
Preview

Copilot AI Jun 11, 2025

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.

Suggested change
c = max(countTypes(_, _, _))
c = max(countTypes(n0, path0, t0) |
n0 = getRelevantLocatable() and
path0 = path and
t0 = t
)

Copilot uses AI. Check for mistakes.

@hvitved hvitved requested a review from paldepind June 12, 2025 08:48
Copy link
Contributor

@geoffw0 geoffw0 left a 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???

@hvitved
Copy link
Contributor Author

hvitved commented Jun 12, 2025

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.

@hvitved hvitved merged commit 9e6ce98 into github:main Jun 12, 2025
16 checks passed
@hvitved hvitved deleted the rust/type-inference-debug-predicates branch June 12, 2025 10:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Rust Pull requests that update Rust code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants