rescript-compiler icon indicating copy to clipboard operation
rescript-compiler copied to clipboard

Trampolining of mutually recursive functions

Open tanaka-de-silva opened this issue 9 years ago • 8 comments

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).

tanaka-de-silva avatar Oct 11 '16 03:10 tanaka-de-silva

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

bobzhang avatar Oct 11 '16 13:10 bobzhang

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

bwestergard avatar Dec 04 '16 21:12 bwestergard

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.

dapetcu21 avatar Sep 26 '17 17:09 dapetcu21

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 😉

TheSpyder avatar Nov 06 '17 01:11 TheSpyder

Watching. I would love to see trampolines added.

mweichert avatar Jan 01 '21 03:01 mweichert

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.

stale[bot] avatar May 03 '23 19:05 stale[bot]

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.

TheSpyder avatar May 03 '23 21:05 TheSpyder

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.

github-actions[bot] avatar Apr 06 '25 02:04 github-actions[bot]