Skip to content

fix(codegen): keep captured loop counters on shared storage - #11060

Closed
proggeramlug wants to merge 2 commits into
PerryTS:mainfrom
proggeramlug:fix/11052-captured-var-loop
Closed

proggeramlug wants to merge 2 commits into
PerryTS:mainfrom
proggeramlug:fix/11052-captured-var-loop

Conversation

@proggeramlug

Copy link
Copy Markdown
Contributor

Summary

  • keep captured or otherwise non-local loop counters out of the static i32 local-bound specialization
  • make loop conditions and updates continue sharing the counter's heap box
  • add an end-to-end regression with a timeout for both unused and retained closure captures

Root cause

The static counter < localBound optimizer created a fresh stack i32 shadow even when the counter was a captured mutable var. The loop update correctly wrote the shared heap box and returned before synchronizing that shadow, while the optimized condition kept reading the shadow's initial value. The condition therefore stayed true forever.

Tests

  • cargo test -p perry --test local_bound_loop_semantics -- --nocapture
  • cargo test -p perry-codegen --lib
  • cargo fmt --all -- --check
  • scripts/check_file_size.sh
  • git diff --check

Closes #11052

@coderabbitai

coderabbitai Bot commented Sep 22, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

Note

Currently processing new changes in this PR. This may take a few minutes, please wait...

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: 5a0c279d-9674-474d-8a99-956a6956ffb4

📥 Commits

Reviewing files that changed from the base of the PR and between f5cfbff and 23c4dd2.

📒 Files selected for processing (2)
  • crates/perry-codegen/src/stmt/loops.rs
  • crates/perry/tests/local_bound_loop_semantics.rs
 ___________________________________________________________________
< Your commit message says 'quick fix'. That's how folklore starts. >
 -------------------------------------------------------------------
  \
   \   \
        \ /\
        ( )
      .( o ).
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@proggeramlug
proggeramlug marked this pull request as ready for review September 22, 2026 22:38
@proggeramlug

Copy link
Copy Markdown
Contributor Author

Landed on main in merge train 259 (#11079), released as v0.5.1642 at 7f4417b5a1.

Your commits are on main — cherry-picked from this PR's head a7c8de9fce and validated as one tree, CI 22/22 green including all 6 gap-suite shards. GitHub cannot auto-close a PR whose commits land under new SHAs via a train rebase, which is why I'm closing this by hand rather than it happening on merge.

Nothing is lost and nothing is needed from you. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

for (var k …) inside a function hangs forever when a closure in the body captures k

1 participant