markup.ml icon indicating copy to clipboard operation
markup.ml copied to clipboard

Stack overflow in js_of_ocaml

Open aantron opened this issue 8 years ago • 9 comments

Reported by @Armael in https://github.com/aantron/markup.ml/issues/22#issuecomment-313258936:

Hi. I'm not sure what the state of this discussion is, but I can report on my recent experience of using markup with js_of_ocaml (wrt bucklescript, I would very much like to use jsoo and not BS, and do not really care for the size of the produced js file).

Essentially it is very easy to run into a stack overflow, when using markup compiled to js. I suspect this is due to the CPS used in the implementation, which I assume is hard for jsoo to optimize into tail-recursion.

One solution I see would be to manually trampoline in markup, which is a somewhat invasive > change...

Repro case: https://paste.isomorphis.me/O8j

and confirmed in a subsequent comment.

aantron avatar Jul 06 '17 01:07 aantron

See http://ocsigen.org/js_of_ocaml/2.8/manual/tailcall .

Armael avatar Jul 06 '17 01:07 Armael

As far as I know, CPS is not optimized into tailcalls by js_of_ocaml.

Armael avatar Jul 06 '17 01:07 Armael

@hhugo Is there something that could be done on jsoo's side? Or is the only solution to implement trampolining in markup itself?

Armael avatar Jul 06 '17 02:07 Armael