Module Wax_conversion.Sink_letSource

Sourceval occurs_list : string -> Wax_lang.Ast.location Wax_lang.Ast.instr list -> bool

occurs_list x l is whether any instruction in l (at any depth) reads or writes the local x. Binders (let, match patterns) are not treated as shadowing, so a rebound x still counts.

module_ m rewrites the local declarations of every function body to be more idiomatic. Each let x : t; declaration is pushed inward as far as possible: down to the first instruction that uses x, and into the innermost block / branch that contains every use of x. A declaration whose first use is an initial assignment (let x : t; ... x = e;, with e not mentioning x) is fused into let x : t = e;.

This is meant as a cleanup of From_wasm.module_ output, which emits all locals as bare declarations at the top of the function body. The rewrite preserves runtime semantics: a bare declaration generates no code, so moving it never reorders any computation, and fusion only relabels an assignment that already sat at the chosen position.