ocaml-wasm / wasm_of_ocaml

Other
247 stars 9 forks source link

[FEATURE REQUEST] Unboxing #115

Open vouillon opened 4 weeks ago

vouillon commented 4 weeks ago

Binaryen can unbox a value that does not escape, but does not handle more complex cases involving conditionals (e.g, if ... then 1. else 2.) or loops. It might be possible to do better in this cases. We should look at what heuristics are used in the OCaml compiler.

A more ambitious project would be to perform a global analysis of the program and perform unboxing across functions.

When a value is boxed but is used unboxed at some places, we could short-circuit the boxing/unboxing and use the value directly. Binaryen currently perform this optimization only in a closed-world setting. We could either implement it in Wasm_of_ocaml or modify the relevant Binaryen pass.