← board

wasm32 and the shared scope-exit sweep

Why this is a ticket rather than a seventh commit

The other six targets all had the same shape of answer: place the sweep once after the body, jump over it, CALL it from every return past the first, and spell three per-target things (a stack adjust, a call, a return). Every one of them writes into a flat Code[] and can name an address inside the body being emitted.

wasm32 cannot do any of that.

So the equivalent change is: emit a real wasm function that performs the sweep, and call it. That function needs the frame — and there is no frame. The locals are wasm locals, not slots at an offset from a base pointer, so the argument the shared sweep would need does not exist in a form that can be passed.

What is already established

Before doing any of it, measure the value

The payoff on the flat-code targets is code size: compiler.pas for riscv32 went 23,179,116 -> 16,133,996 bytes (30.4%), and for xtensa Call0 under --xtensa-long-calls 26,308,460 -> 14,163,820 (46.2%, inflated by that flag making every call site large). Neither number transfers. A wasm module's size is dominated by different things, and a function call in wasm is not the same trade as a call rel32. Measure the duplicated-sweep bytes in a real module first; if the answer is small, the right resolution of this ticket is rejected/ with the measurement attached.