You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Multiple for loops with the same variable name in one function corrupt register allocation #146
Severity: High Area: Compiler — scope resolver / codegen
Description
When a function contains two or more numeric for loops that use the same loop variable name (e.g., i), the scope resolver's locals map is keyed by name. The second loop's for variable overwrites the first loop's entry, so the first loop's loop_var_reg points to the wrong register at code generation time. This causes incorrect values to be used as the loop counter in earlier loops.
Reproduction
functionrun(n)
localsum=0fori=1, ndosum=sum+i-- 'i' register is misassignedendfori=1, ndosum=sum+iendreturnsumendreturnrun(5)
-- Expected: 30-- Actual: wrong value or crash
This was originally fixed in PR #141 (Phase 17), but the perf rewrites that followed (likely PR #156 — fully tail-recursive CPS executor) reintroduced the bug. Minimal repro:
Single loop works fine; the second loop's i register collides with the first loop's residual state.
Adding to the Direction A queue as a new plan file. Will be picked up via /next-plan after the high-leverage A1 fix lands. Tracking under milestone 0.5.0.
Activity
davydog187 commentedon May 4, 2026
Regression confirmed on
main(835de36).This was originally fixed in PR #141 (Phase 17), but the perf rewrites that followed (likely PR #156 — fully tail-recursive CPS executor) reintroduced the bug. Minimal repro:
Single loop works fine; the second loop's
iregister collides with the first loop's residual state.Adding to the Direction A queue as a new plan file. Will be picked up via
/next-planafter the high-leverage A1 fix lands. Tracking under milestone0.5.0.davydog187 commentedon May 4, 2026
Plan filed:
.agents/plans/A14-for-loop-register-regression.md(will be picked up via/next-plan).