Skip to content

[ty] Avoid recursion when projecting narrowing constraints - #26276

Merged
charliermarsh merged 3 commits into
mainfrom
charlie/unroll-narrowing-projection
Jun 23, 2026
Merged

charliermarsh merged 3 commits into
mainfrom
charlie/unroll-narrowing-projection

Conversation

@charliermarsh

@charliermarsh charliermarsh commented Jun 23, 2026 •

Copy link
Copy Markdown
Member

Summary

NarrowingProjector::project recursively walks the input narrowing decision diagram before producing the projected graph for one place. Deep constraint chains can therefore exhaust the native stack even when the projected graph is shallow.

This replaces the recursive traversal with an explicit post-order worklist. A small inline action buffer avoids a heap allocation for common shallow projections. The actions preserve the existing visitation order and semantics: uncertain branches are projected before resolving non-terminal calls, ordinary predicates project all three branches before computing their narrowing constraints, and completed nodes continue to use the same cache.

The full ty semantic suite and workspace Clippy pass.

@astral-sh-bot astral-sh-bot Bot added the ty The ty type checker label Jun 23, 2026
@charliermarsh charliermarsh added the bug An issue describing something that isn't working, or a PR that fixes a bug label Jun 23, 2026
@astral-sh-bot

astral-sh-bot Bot commented Jun 23, 2026

Copy link
Copy Markdown

Typing conformance results

No changes detected ✅

Current numbers
The percentage of diagnostics emitted that were expected errors held steady at 94.37%. The percentage of expected errors that received a diagnostic held steady at 89.00%. The number of fully passing files held steady at 94/134.

@astral-sh-bot

astral-sh-bot Bot commented Jun 23, 2026 •

Copy link
Copy Markdown

Memory usage report

Summary

Project Old New Diff Outcome
prefect 516.30MB 516.31MB +0.00% (16.01kB) ⏫
trio 77.51MB 77.51MB +0.01% (5.91kB) ⏫
sphinx 193.38MB 193.38MB +0.00% (5.13kB) ⏫
flake8 30.75MB 30.74MB -0.02% (5.23kB) ⬇️

Significant changes

Click to expand detailed breakdown

prefect

Name Old New Diff Outcome
parsed_module 19.35MB 19.37MB +0.08% (16.01kB) ⏫

trio

Name Old New Diff Outcome
parsed_module 15.04MB 15.05MB +0.04% (5.91kB) ⏫

sphinx

Name Old New Diff Outcome
parsed_module 18.36MB 18.36MB +0.03% (5.13kB) ⏫

flake8

Name Old New Diff Outcome
parsed_module 9.77MB 9.77MB -0.05% (5.23kB) ⬇️

@astral-sh-bot

astral-sh-bot Bot commented Jun 23, 2026 •

Copy link
Copy Markdown

ecosystem-analyzer results

No diagnostic changes detected ✅

Flaky changes detected. This PR summary excludes flaky changes; see the HTML report for details.

Full report with detailed diff (timing results)

@charliermarsh
charliermarsh marked this pull request as ready for review June 23, 2026 17:47
@charliermarsh
charliermarsh requested a review from a team as a code owner June 23, 2026 17:47
@charliermarsh
charliermarsh force-pushed the charlie/unroll-narrowing-projection branch 2 times, most recently from ca37784 to 21446d8 Compare June 23, 2026 19:27
@MichaReiser

Copy link
Copy Markdown
Member

Same here. I don’t think I’m the right reviewer for this

@charliermarsh

Copy link
Copy Markdown
Member Author

Why? This is mechanically unrolling the recursive loop. There isn’t really any specific logic here?

@charliermarsh
charliermarsh removed the request for review from MichaReiser June 23, 2026 21:44

@carljm carljm left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This looks good. Thank you! A regression test that would actually stack overflow on main would be a nice addition.

@charliermarsh
charliermarsh requested a review from a team as a code owner June 23, 2026 22:26
@charliermarsh
charliermarsh force-pushed the charlie/unroll-narrowing-projection branch from 76c8a95 to 0f94c6a Compare June 23, 2026 23:19
@charliermarsh
charliermarsh enabled auto-merge (squash) June 23, 2026 23:23
@charliermarsh
charliermarsh merged commit bcd2028 into main Jun 23, 2026
62 checks passed
@charliermarsh
charliermarsh deleted the charlie/unroll-narrowing-projection branch June 23, 2026 23:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug An issue describing something that isn't working, or a PR that fixes a bug ty The ty type checker

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants