How can we improve the Microsoft Edge developer experience?

ES6 Tail Call Optimization

Besides providing better tools for JS devs, this will greatly enhance JavaScript's support for functional languages compiled to JS, like ClojureScript.

452 votes
Vote
Sign in
Check!
(thinking…)
Reset
or sign in with
  • facebook
  • google
    Password icon
    Signed in as (Sign out)
    You have left! (?) (thinking…)
    Roy TinkerRoy Tinker shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →

    6 comments

    Sign in
    Check!
    (thinking…)
    Reset
    or sign in with
    • facebook
    • google
      Password icon
      Signed in as (Sign out)
      Submitting...
      • Marc Nieper-WißkirchenMarc Nieper-Wißkirchen commented  ·   ·  Flag as inappropriate

        Could you elucidate this quote: "We are still evaluating this technology. There may be significant spec stabilization, foundational work, or additional community input required before we can begin development."?

        Regarding proper tail call elimination, the spec is stabilized, and foundational work is at least as old as the first Scheme compiler.

      • Marc Nieper-WißkirchenMarc Nieper-Wißkirchen commented  ·   ·  Flag as inappropriate

        In order to be able to effectively compile languages with proper tail calls (e.g. Scheme) to Ecmascript, this is a must-have-feature. Furthermore, for an Ecmascript programmer, this allows for a continuation-passing program style without having to worry about stack overflows.

        I've implemented proper tail calls in the Traceur transpiler. It is working but with a heavy loss of performance due to missing language support by the current Ecmascript engines.

      • JohnJohn commented  ·   ·  Flag as inappropriate

        I'd love TCO and have voted for it - it would be wise to see why others have not included it in their languages. There are threads out there about this for Python and Ruby and reasons why it was not included in the end.

      • Brian MitchellBrian Mitchell commented  ·   ·  Flag as inappropriate

        There are many parts of ES-harmony which can be trivially polyfilled but tail call elimination is not one of them. Some compilers such as babel attempt to emulate some optimizations for trivial cases but it turns into a guessing game of when something may or may not be effectively eliminated making the feature hard to leverage at any significant scale. This would not only be an advantage for functional languages compiled to ES6+ but for functional languages that want rich interoperation with JavaScript. The potential for influencing the way future JS code is written is huge if this is considered.

        While it will likely be some time before widespread support can be counted upon, it's very important for some things that may wish to target JS. It would also be advantageous to find a clean way to detect proper call elimination compliance w/o trying to run the stack out as we see in this test: https://kangax.github.io/compat-table/es6/#proper_tail_calls_(tail_call_optimisation)_mutual_recursion.

      Feedback and Knowledge Base