Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions rust/ql/lib/codeql/rust/internal/TypeInference.qll
Original file line number Diff line number Diff line change
Expand Up @@ -1516,4 +1516,15 @@ private module Debug {
mce = getRelevantLocatable() and
result = resolveMethodCallTarget(mce)
}

pragma[nomagic]
private int countTypes(AstNode n, TypePath path, Type t) {
t = inferType(n, path) and
result = strictcount(Type t0 | t0 = inferType(n, path))
}

predicate maxTypes(AstNode n, TypePath path, Type t, int c) {
c = countTypes(n, path, t) and
c = max(countTypes(_, _, _))
Copy link

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.
}
}