-
Notifications
You must be signed in to change notification settings - Fork 583
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Proper Tail Optimization doesn't work #2140
Comments
The option for tail calls is not enabled by default. How did you coming your ES6 code? |
I enabled it with
I don't understand the question. |
Oops. Typo, should have been "how did you compile your code" If I remember correctly the tall call implementation in traceur did not cover all cases. I have to look closer at your code. Note, no one is really maintaining this project at the moment. If you have some time your contribution would be appreciated. |
Actually the compilation is ok, it's just that I don't have a correct Yes hopefully I can help. I just successfully ran the following program: "use strict";
function foo(n) {
if (n===0) {
return "done"
} else {
return foo(n-1)
}
}
console.log(foo(100000)); I guess I need to find out what is not optmised in the other case. |
By the way the code is written using CPS. Someone told me cheney on the MTA should be the way to go. But I don't understand how in the context of JavaScript it makes sens. |
Hopefully, it will be helpful to someone on the same quest. For what it's worth, I managed to translate a subset of Scheme (!) to JavaScript using Continuation-Passing-Style and a trampoline. Here is the Scheme description of the transformation in nanopass framework syntax: It works. The thing is that as-is it is very slow, proof: https://www.measurethat.net/Benchmarks/Show/5674/0/ruse-compiler-factorial The rest of the compiler can be found at https://github.com/scheme-live/ruse-scheme/blob/master/rusec.scm edit: change link to code to updated version and replace benchmark link with something that is not buggy |
Ideas on how to optimize the code is 💯 welcome. Here is another jsperf link because the other is broken: https://jsperf.com/ruse-scheme-factorial-v0 |
GNU Guile has now a working prototype of a compiler backend that generates JavaScript.
It use lots of tail calls. I compiled it with traceur using the following command:
I run it in chrome using the following html file:
It fails with a
Uncaught RangeError: Maximum call stack size exceeded
.The original scheme program is:
The input JavaScript file can be found here. That input file is correctly intrepreted by nodejs v8.4.0 using the
--harmony_tailcalls
flag.The text was updated successfully, but these errors were encountered: