WASM's lack of Goto makes compilers more complicated

Created on 2023-07-27T17:43:00-05:00

Return to the Index

This card can also be read via Gemini.

WASM intentionally reduces control flow to a specific, structure format. This format does not include support for labels and gotos. Thus it becomes easier to write a translator and interrogation software for--but makes encoding logic to WASM more difficult.

Arbitrary control flow requires using a counter and a switch block, surrounded in a loop, so the destination label can be assigned and break to the next iteration where a switch dispatches it.

Some [potentially complex] algorithms are then needed to get away from this trope. The trope works but has poor performance as it involved making constant dispatches. So algorithms like Relooper and Stackifier make a compiler more complex with heuristics to try and avoid the dispatch loop mantra.