Semantic Diff

#9396 Rename a for loop's start expression once when inlining

2 commits

5fcc46e2f4a7a6fc7f7ff198c842c8e89289dfc6..pr-9396

b8ed82e32 · cknitt + Claude · Nov 22, 2026, 20:52 UTC

Rename a for loop's start expression once when inlining

Lam_bounded_vars renames the variables bound inside a function body before it is inlined. Its for-loop case rewrote the start expression twice (let l1 = aux l1 in ... Lambda.for_ ident (aux l1) ...), a slip that has been there since at least 2019. The second pass only renamed the fresh binders again, consistently, so the result was the same program; JS output and diagnostics are byte-identical on 77 benchmark files, and allocation drops by 56 words in total.

a07c272b6 · cknitt + Claude · Nov 23, 2026, 08:37 UTC

Test the renaming of a for loop's start expression when inlining

The previous commit had no lasting test, as Codex pointed out. A unit test now rewrites a for loop whose start expression binds a variable and checks that the binder, its use and the renaming map agree, with one map entry per binder; with the old double rename the map records a name the result doesn't use. An end-to-end test applies two function literals right away, which inlines them through Lam_bounded_vars, with a let and a callback in the loop's start expression, and checks their results. Functions with loops are otherwise too big to inline, so this is the path that reaches the for-loop case.