{"action":"created","issue":{"url":"https://api.github.com/repos/tc39/ecma262/issues/535","repository_url":"https://api.github.com/repos/tc39/ecma262","labels_url":"https://api.github.com/repos/tc39/ecma262/issues/535/labels{/name}","comments_url":"https://api.github.com/repos/tc39/ecma262/issues/535/comments","events_url":"https://api.github.com/repos/tc39/ecma262/issues/535/events","html_url":"https://github.com/tc39/ecma262/issues/535","id":147599667,"number":535,"title":"Response to the proposal to add explicit tail call syntax to ECMAScript","user":{"login":"msaboff","id":16887220,"avatar_url":"https://avatars.githubusercontent.com/u/16887220?v=3","gravatar_id":"","url":"https://api.github.com/users/msaboff","html_url":"https://github.com/msaboff","followers_url":"https://api.github.com/users/msaboff/followers","following_url":"https://api.github.com/users/msaboff/following{/other_user}","gists_url":"https://api.github.com/users/msaboff/gists{/gist_id}","starred_url":"https://api.github.com/users/msaboff/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/msaboff/subscriptions","organizations_url":"https://api.github.com/users/msaboff/orgs","repos_url":"https://api.github.com/users/msaboff/repos","events_url":"https://api.github.com/users/msaboff/events{/privacy}","received_events_url":"https://api.github.com/users/msaboff/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":8,"created_at":"2016-04-12T00:48:44Z","updated_at":"2016-04-12T21:38:31Z","closed_at":null,"body":"After some discussion with other JavaScriptCore team members, we at Apple cannot support the suggested change to make tail calls explicit via syntax due to the expected web incompatibilities those changes will create.\r\n\r\nGiven that tail calls are currently part of the ES6 and draft ES7 specification, a compliant implementation should implement tail calls as described in those specifications.  Compliance with any proposed changes would not occur for almost two years since the earliest that any proposed tail call changes could be adopted would be for the ES2017 (ES8?) specification.  In the mean time web pages and Javascript applications will be created that are susceptible to future breakage.  \r\n\r\nIn addition to the current JavaScriptCore implementation, it is likely that other browser venders will implement Tail Calls compliant with the current standard.  Let’s consider the changes to tail calls as suggested at the March 2016 TC-39 meeting and the impact it would have on Safari and any other compliant implementations that will be shipped this year.  I’d like to cover what I understood was being presented at the March meeting, but I will also cover two other reasonable variants of that proposal and my assessment of their suitability.\r\n\r\n1. **Tail calls based on tail position are optional. Tail calls based on opt-in syntax are required.**\r\nThere will be web pages and web applications developed starting this year that take advantage of tail calls as currently specified.  Those web pages would become susceptible to breakage should we change the specification.  Consider web pages that take advantage of tail calls as intended in the current specification.  The Javascript written for such a web page assumes unlimited tail calls.  Obviously, those pages won't work on an implementation that doesn’t support tail calls.  If one browser decides to stop supporting implicit tail call behavior, they break that class of web pages.  Therefore early adopters like us need to continue to support the currently specified behavior.  The implication of this is that ES6 tail call behavior cannot be made optional without compatibility issues for Safari.  Other early adopting browsers have the same issue.\r\n\r\n    If another browser decided to not support implicit tail calls, but waits for the proposed change and only implements explicit tail calls, they introduce cross browser incompatibilities.  Certainly such a browser is not compatible when running a web page that depends on implicit tail calls and likely never will be.  In addition, there would be at least another class of incompatibilities.  Consider a web page that inadvertently makes infinite recursive calls.  For browsers that waited for explicit tail calls, that web page could throw an out of memory exception that might be silently caught, after which the web page proceeds as expected.  For Safari and other browsers that support implicit tail calls, that web page is stuck in an infinite loop.  The error is in the web page, but the handling of the error by each browsers is vastly different depending on their support of implicit tail calls.  We have seen this type of issue in the past and reduced our stack size to maintain cross browser compatibility.\r\n\r\n    Approval of this proposal also encourages browser vendors to wait to implement the current ES6 specified tail call behavior.  This selective delay by some implementations diminishes the purpose of the ECMAScript standard and the features contained therein.  Selective support by various implementations will cause developers to delay their adoption of the programming patterns tail calls was designed to address.  Again this only impacts early adopting browsers like Safari.\r\n\r\n    The main problem with this proposal is that it relaxes normative behavior and makes it optional, effectively eliminating that behavior from the standard.  After we work through the early adopter problems described above, we’d introduce a new problem: Developers don’t know if they can use tail calls based on tail position or not, since implementations vary.  Feature testing for the optional tail call behavior would be difficult and cumbersome, given the current specification.  Optional behavior without a feature test has little place in the standard and cannot be relied upon by implementors and developers alike.\r\n\r\n    Given these web compatibility issues and related developer concerns, we reject this type of proposal.\r\n\r\n2. **Tail calls based on tail position are forbidden. Tail calls based on opt-in syntax are required.**\r\nA proposal based on this option requires that early adopting implementations, like Safari, need to change and stop supporting implicit tail calls.  Those changes break web pages designed for the current spec as described above.  It not only breaks those web pages, it would require that they be rewritten.  The web breakage and subsequent rework by web developers caused by this option is much worse than with the first option.\r\n\r\n    There will also be web pages that accidentally took advantage of and benefited from implicit tail calls.  With this proposal, those web pages could break due to running out of stack space.  These breakages would be confusing at best to the web page implementers and likely damage the perceived quality of Safari.\r\n\r\n    Due to the breakage this imposes on Safari and web pages developed to use implicit tail calls, we also reject this type of proposal.\r\n\r\n3. **Tail calls based on tail position are required. New syntax for verifying tail position is required.**\r\nThis is the only proposal that wouldn’t cause breakage.  This proposal would be to add syntax to signify a tail call is intended, but wouldn’t change the normative nature of tail calls as currently specified.  If the call is not in tail position, a syntax error is issued.  Implicit tail calls as currently defined would still be normative and must be implemented by conforming implementations.  This change is backward compatible.  Pages developed to take advantage of proper tail calls without the new syntax would continue to work.  Javascript code developed with the new syntax get additional checking and the added benefit that tail calls appear different in the source code.  The usefulness of this change is minimal though as it adds optional syntax with little corresponding semantic changes.\r\n\r\n    We recommend against this proposal, but our objection is not as strong as our objections to (1) and (2), since this proposal would not harm web compatibility.  Our main concern is that this proposal could add confusion with very little benefit."},"comment":{"url":"https://api.github.com/repos/tc39/ecma262/issues/comments/209113820","html_url":"https://github.com/tc39/ecma262/issues/535#issuecomment-209113820","issue_url":"https://api.github.com/repos/tc39/ecma262/issues/535","id":209113820,"user":{"login":"msaboff","id":16887220,"avatar_url":"https://avatars.githubusercontent.com/u/16887220?v=3","gravatar_id":"","url":"https://api.github.com/users/msaboff","html_url":"https://github.com/msaboff","followers_url":"https://api.github.com/users/msaboff/followers","following_url":"https://api.github.com/users/msaboff/following{/other_user}","gists_url":"https://api.github.com/users/msaboff/gists{/gist_id}","starred_url":"https://api.github.com/users/msaboff/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/msaboff/subscriptions","organizations_url":"https://api.github.com/users/msaboff/orgs","repos_url":"https://api.github.com/users/msaboff/repos","events_url":"https://api.github.com/users/msaboff/events{/privacy}","received_events_url":"https://api.github.com/users/msaboff/received_events","type":"User","site_admin":false},"created_at":"2016-04-12T21:38:30Z","updated_at":"2016-04-12T21:38:30Z","body":"> Interop is about how actual implementations match and how well they run code that exists.\r\n\r\nThis is the crux of our argument.\r\n\r\n> As far as I am aware there is no actual interop concern with regard to tail calls as tail calls are not implemented interoperably in browsers and will not be for some time. It is possible (and has occurred before) that a change to a ratified specification results in more interoperability rather than less. See for example myriad changes to functions in sloppy mode or removal of Proxy's enumerate trap (something Edge had already shipped).\r\n\r\nOur point is that the proposed change would decrease interoperability.  Some implementations will do implicit PTC and eventually all will do Syntactic Tail Calls (STC).  But as @getify points out, feature testing for either difficult and kludgy at best.  Adding STC complicates matters as both PTC and STC would need to be tested.\r\n\r\n> Can you clarify what websites that exist today or in the near future would break as a result of adopting a proposal like (1)?\r\n\r\nThere are no known websites that would break with proposal (1), optional PTC + future STC.  There are also no known current websites that will break with ES6 PTC alone.  My point is that one can easily envision a website written to take advantage of PTC that would break without them.  Remember that the PTC feature was added to enable a pattern that doesn't work today.  Part of the objection to (1) is that future cross browser compatibility could force WebKit/JavaScriptCore to eliminate PTC and only support STC.  In the process we break websites written assuming PTC.  \r\n\r\n> An implementation can do implicit tail calls without violating the spec, though I agree developers would not choose to rely on the implicit tail calls as there is no guarantee they will work. That's exactly the case they're in today and will be until they can support only browsers that support tail calls.\r\n\r\nA spec compliant implementation would need to support PTC.  Without broad support across major browsers, we introduce confusion that @getify points out.\r\n"}}