rescript-lang / rescript-compiler

The compiler for ReScript.
https://rescript-lang.org
Other
6.65k stars 442 forks source link

Trampolining of mutually recursive functions #849

Open tanaka-de-silva opened 7 years ago

tanaka-de-silva commented 7 years ago

Introduce an annotation to rewrite mutually recursive functions to use a trampoline. This will enable the user to avoid exceeding the stack size at the expense of more overhead until ES6 proper tail calls are widely implemented (it is only available in Safari 10 & WebKit at the moment).

bobzhang commented 7 years ago

after we upgrade 4.04 we have more fine control over the inlining info and tail call annotation. And in 4.04 we will optimize local exception into a jump. so we will wait until 4.04 upgrade finishes. Note we have baked in conditional compilation in case you need a workaround http://bloomberg.github.io/bucklescript/Manual.html#_conditional_compilation_support_static_if

bwestergard commented 7 years ago

Note that newer versions of node support tail call optimization in accordance with the ES6 spec. Here is a demonstration.

dapetcu21 commented 6 years ago

Hi! Any updates on this? I have a parser generated with Menhir and it gives me a stack overflow whenever I try to run it on a real-world amount of Lua code. Node 8 removed the tail calls flag, so I'm left with no solution.

TheSpyder commented 6 years ago

I see occasional mentions of adding trampolines but I think it's still a long-term plan. My app has a small enough JS surface area that I was able to switch to js_of_ocaml to get trampolining. I kept the Bucklescript compile path for development, though, and I look forward to being able to use it for production eventually 😉

mweichert commented 3 years ago

Watching. I would love to see trampolines added.

stale[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

TheSpyder commented 1 year ago

I’ll give it one more ping. Five years later we are sick of needing native dependencies in an otherwise fully NPM environment, but without trampolines we can’t use ReScript. Our only option is to rewrite the section of code that generates mutually recursive functions, and then switch.