Skip to content

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

paldepind
Copy link
Contributor

@paldepind paldepind commented Jul 31, 2025

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 🙏

@github-actions github-actions bot added the Rust Pull requests that update Rust code label Jul 31, 2025
@paldepind paldepind marked this pull request as ready for review July 31, 2025 12:10
@paldepind paldepind requested a review from a team as a code owner July 31, 2025 12:10
@Copilot Copilot AI review requested due to automatic review settings July 31, 2025 12:10
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

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

@paldepind paldepind added the no-change-note-required This PR does not need a change note label Jul 31, 2025
@paldepind paldepind force-pushed the rust/type-limit-metric branch from a19ce02 to abc58ac Compare July 31, 2025 12:20
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.

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
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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()
Copy link
Contributor

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.

Copy link
Contributor Author

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?

Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no-change-note-required This PR does not need a change note Rust Pull requests that update Rust code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy