mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-11-06 08:23:19 +08:00
A loop that counts with number locals (`lines++`, `run = 0`, `longest = run`) kept each counter a double, so every increment was a dependent floating-point add, and conditional increments compiled to branches. The speculative integer copy only covered loops with products or variable steps. The range analysis now bounds for-loop cursors that are reset to an integer literal or set to another bounded binding, besides those it already bounded by their increments. A cursor's writes take its loop range, which holds every value it takes in the loop, so `changes + 1` stays proven at the limit of a typed array's length. The analysis reports these loop ranges per for loop. Where an exception leaves the function (no enclosing try or finally, no coroutine), the emitter keeps such cursors in i64 shadows for the loop: one copy of the loop, no checks, and each double is written back when the loop exits. A loop with a labeled break or continue keeps its doubles.