Skip to content

[ty] Propagate deletions through nested loop headers - #28044

Open
carljm wants to merge 1 commit into
mainfrom
cjm/fix-nested-loop-assignment-narrowing
Open

[ty] Propagate deletions through nested loop headers#28044
carljm wants to merge 1 commit into
mainfrom
cjm/fix-nested-loop-assignment-narrowing

Conversation

@carljm

@carljm carljm commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

An inner loop can delete a variable on one iteration and then exit through break on a later iteration. The variable can remain unbound after the inner loop and on subsequent outer iterations, but ty did not propagate deletions carried by nested loop headers into the enclosing loop's boundness analysis.

Include nested headers' deletion reachability when computing an enclosing header's reachability. Keep the loop-back bindings intact for type inference, and memoize the structural traversal used during Salsa cycle initialization so shared descendant headers are only visited once.

Related to #28009.

Ecosystem

The ecosystem run reports no stable diagnostic changes. Typing conformance and memory usage are unchanged.

Test plan

  • Add while and for mdtests for deletions that survive an inner-loop iteration and a later break, including an explicit continue and a for-else that returns.
  • Verify that reassignment after the inner loop restores boundness on subsequent outer iterations.
  • Verify that statically unreachable deletions preserve boundness and literal types through several nested loops.

@carljm carljm added the ty Multi-file analysis & type inference label Aug 25, 2026
@astral-sh-bot

astral-sh-bot Bot commented Aug 25, 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 97.69%. The percentage of expected errors that received a diagnostic held steady at 93.71%. The number of fully passing files held steady at 110/136.

@astral-sh-bot

astral-sh-bot Bot commented Aug 25, 2026

Copy link
Copy Markdown

Memory usage report

Memory usage unchanged ✅

@astral-sh-bot

astral-sh-bot Bot commented Aug 25, 2026

Copy link
Copy Markdown

ecosystem-analyzer results

No diagnostic changes detected ✅

Large timing changes:

Project Old Time New Time Change
dd-trace-py 3.08s 0.92s -70%

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

Full report with detailed diff (timing results)

@carljm
carljm marked this pull request as ready for review August 25, 2026 19:04
@carljm
carljm requested a review from a team as a code owner August 25, 2026 19:04
@astral-sh-bot
astral-sh-bot Bot requested a review from ibraheemdev August 25, 2026 19:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ty Multi-file analysis & type inference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant