ocaml-wasm / wasm_of_ocaml

Other
238 stars 8 forks source link

Separate compilation: generate and use cross module information regarding function arity #92

Open vouillon opened 2 days ago

vouillon commented 2 days ago

We could improve the code generated when compiling cmo files if we knew the arity of the functions exported by each module. This would allow to call functions directly rather than going through an helper function which manages currying. When the function is known, one could also export the corresponding Wasm function so that it can be directly accessed without going through the toplevel module and the closure.

In order for this to work with submodules and functors, we need to know which blocks are immutable (see #91). Alternatively, in the case of functors, it might be possible to refine the escape analysis to recognize that a fresh block returned by a function cannot be mutated by other callers.

This is wasm_of_ocaml counterpart to ocsigen/js_of_ocaml/issues/550. @hhugo has written a draft implementation for js_of_ocaml in ocsigen/js_of_ocaml#1594.