<html>
<head>
<base href="https://bugs.webkit.org/" />
</head>
<body>
<p>
<div>
<b><a class="bz_bug_link
bz_status_NEW "
title="NEW - RangeError with deep self recursion (Proper tail call)"
href="https://bugs.webkit.org/show_bug.cgi?id=163663#c2">Comment # 2</a>
on <a class="bz_bug_link
bz_status_NEW "
title="NEW - RangeError with deep self recursion (Proper tail call)"
href="https://bugs.webkit.org/show_bug.cgi?id=163663">bug 163663</a>
from <span class="vcard"><a class="email" href="mailto:fpizlo@apple.com" title="Filip Pizlo <fpizlo@apple.com>"> <span class="fn">Filip Pizlo</span></a>
</span></b>
<pre>(In reply to <a href="show_bug.cgi?id=163663#c0">comment #0</a>)
<span class="quote">> A RangeError is thrown during a deep self recursion. As stack frames are
> supposed to be reused if a function is called in tail position, this is
> unexpected.
>
> ```
> function decToZero(n) {
> return n>0 ? decToZero(n-1) : n;
> }
>
> decToZero(42280) // yields "RangeError: Maximum call stack size exceeded."
> ```
>
> The depth of recursion necessary to blow the stack is not consistent but
> I've always observed it when n >= 100000.
>
> Hardware:
> MacBook Pro (Retina, 15-inch, Mid 2015)
> 2.5 GHz Intel Core i7
> 16 GB 1600 MHz DDR3
>
> Webkit: Version 10.0 (11602.1.50.0.10, r207529)</span >
Does it work if you write your code this way:
function decToZero(n) {
if (n>0)
return decToZero(n-1);
return n;
}
The bug appears to be that we don't handle ternaries correctly for our evaluation of whether a call is in tail position. It took me a while, but by my reading of <a href="http://www.ecma-international.org/ecma-262/6.0/ECMA-262.pdf">http://www.ecma-international.org/ecma-262/6.0/ECMA-262.pdf</a>, on page 265 it appears to say that if the cases of the ternary are tail candidates.</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are the assignee for the bug.</li>
</ul>
</body>
</html>