Semantic Diff

#9258 Replace local mutable blocks in one pass over the function

2 commits

bf35764db1628906bf68c424735c68da4d1711fb..pr-9258

52c1aa6bc · cknitt + Claude · Nov 07, 2026, 10:04 UTC

Replace local mutable blocks in one pass over the function

Why

The pass analyzed and rewrote a block's whole scope once per block, so n refs used in one function cost O(n²): 1,000 refs updated in one loop allocated 151M words. One traversal now decides every block and one rewrite replaces them, so the same input allocates 17M.

A value written to, or initializing, a never-read field is held back until its block is decided, as the old innermost-first order dropped such values before analyzing the blocks around them. The generated JavaScript is the same for the test suites and 1,600 generated functions.

ba4c395e8 · cknitt + Claude · Nov 07, 2026, 19:02 UTC

Analyze blocks without allocating a closure per node

The benchmarks showed the single pass allocating up to 0.9% more for functions without local blocks: each node passed a new closure to the traversal. The innermost slot is now a reference, so the traversal reuses one closure, and other inputs allocate as much as before.