-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Rust: Add metric for DCA and debug predicates for type that reach the length limit #20147
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
base: main
Are you sure you want to change the base?
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
This PR adds a new DCA metric to track AST nodes with types that reach the type path length limit, which helps identify potential infinite cycles in type inference that could lead to performance issues.
- Adds a new query
NodesWithTypeAtLengthLimit.ql
that counts nodes with types at the 10-level type path limit - Exposes the type path limit constant and adds debug predicates for investigating type limit issues
- Updates query suite expectations to include the new metric query
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
File | Description |
---|---|
NodesWithTypeAtLenghtLimit.ql |
New metric query that counts AST nodes with types at the length limit |
TypeInference.qll |
Exposes type path limit constant and adds debug predicates for type limit analysis |
*.qls.expected |
Updates query suite expectations to include the new metric query |
a19ce02
to
abc58ac
Compare
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.
the type is 10 levels deep (not likely)
How confident are you of this claim, and what would we lose if we change the number to, say, 100?
* @name Nodes With Type At Length Limit | ||
* @description Counts the number of AST nodes with a type at the type path length limit. | ||
* @kind metric | ||
* @id rust/summary/nodes-at-type-path-length-limit |
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.
Do you want me to talk you through adding this metric to the DCA reports (and our metrics issue) - or would you prefer I do it for you? I'm happy either way assuming this is the only metric you have plans to add right now.
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.
I think I can add the metric to DCA but it would be great to have your eyes on the PR!
Regarding the metrics issue it's up to you if we add it there or not. It obviously be nice to have, but may not be important enough to include.
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.
@mention
me in the metrics PR then.
I'm happy to track it in metrics, it won't be among the fiddlier bits to track.
where | ||
atLimit = | ||
count(AstNode n, TypePath path | | ||
exists(inferType(n, path)) and path.length() = getTypePathLimit() |
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.
How come this is =
, whereas debugInferTypeForNodeAtLimit
uses >=
?
I'm a bit suspicious because in at least one case I get more results when I increase the threshold.
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.
The length can never be greater than getTypePathLimit()
so I =
and >=
should be the same?
In the debug predicate changing getTypePathLimit()
to getTypePathLimit() - 2
was useful for me, and that is easier with >=
, though we can also change it to =
if the other is a bit confusing?
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.
I see, and when the path limit is increased we potentially get more results because of more (longer) spurious / multiple paths being permitted and counted.
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.
Yes :)
A node can have a type at a type path that reaches the length limit of 10 if: 1/ the type is 10 levels deep (not likely) or 2/ type inference got in some infinite cycle and reached the type path length limit.
We'v previously had a performance issue due to the latter and now it seems that something similar is happening in #20140: We have some existing types that reach the limit and something in #20140 causes that latent issue to explode even further.
This PR adds a metric for DCA that tracks how many nodes have a type that reach the type path length limit. These infinite cycles may not show up as performance issues initially, but they could later, so having DCA report them will let us catch things earlier and will help us work towards getting the metric to zero which should be possible in most/all projects.
NOTE: I don't know much about DCA things, so please double check that the metric query is usable for DCA 🙏