<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[189336] trunk/Source/JavaScriptCore</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/189336">189336</a></dd>
<dt>Author</dt> <dd>basile_clement@apple.com</dd>
<dt>Date</dt> <dd>2015-09-03 20:05:46 -0700 (Thu, 03 Sep 2015)</dd>
</dl>

<h3>Log Message</h3>
<pre>[ES6] Recognize calls in tail position
https://bugs.webkit.org/show_bug.cgi?id=148665

Reviewed by Saam Barati.

This patch adds the capability for the bytecode generator to recognize
and dispatch tail calls, as per ES6 spec:
http://www.ecma-international.org/ecma-262/6.0/#sec-isintailposition

This does not change the generated bytecode, but merely provides the
hook for generating tail calls in subsequent patches toward
https://bugs.webkit.org/show_bug.cgi?id=146477

* bytecompiler/BytecodeGenerator.cpp:
(JSC::BytecodeGenerator::BytecodeGenerator):
(JSC::BytecodeGenerator::emitCallInTailPosition):
(JSC::BytecodeGenerator::emitCallVarargsInTailPosition):
* bytecompiler/BytecodeGenerator.h:
(JSC::BytecodeGenerator::emitNode):
(JSC::BytecodeGenerator::emitNodeInTailPosition):
* bytecompiler/NodesCodegen.cpp:
(JSC::FunctionCallValueNode::emitBytecode):
(JSC::FunctionCallResolveNode::emitBytecode):
(JSC::FunctionCallBracketNode::emitBytecode):
(JSC::FunctionCallDotNode::emitBytecode):
(JSC::CallFunctionCallDotNode::emitBytecode):
(JSC::ApplyFunctionCallDotNode::emitBytecode):
(JSC::LogicalOpNode::emitBytecode):
(JSC::ConditionalNode::emitBytecode):
(JSC::CommaNode::emitBytecode):
(JSC::SourceElements::emitBytecode):
(JSC::IfElseNode::emitBytecode):
(JSC::DoWhileNode::emitBytecode):
(JSC::WhileNode::emitBytecode):
(JSC::ForNode::emitBytecode):
(JSC::ReturnNode::emitBytecode):
(JSC::WithNode::emitBytecode):
(JSC::TryNode::emitBytecode):
* bytecompiler/SetForScope.h: Added.
(JSC::SetForScope::SetForScope):
(JSC::SetForScope::~SetForScope):
* runtime/Options.h:</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceJavaScriptCoreChangeLog">trunk/Source/JavaScriptCore/ChangeLog</a></li>
<li><a href="#trunkSourceJavaScriptCorebytecompilerBytecodeGeneratorcpp">trunk/Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCorebytecompilerBytecodeGeneratorh">trunk/Source/JavaScriptCore/bytecompiler/BytecodeGenerator.h</a></li>
<li><a href="#trunkSourceJavaScriptCorebytecompilerNodesCodegencpp">trunk/Source/JavaScriptCore/bytecompiler/NodesCodegen.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoreruntimeOptionsh">trunk/Source/JavaScriptCore/runtime/Options.h</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkSourceJavaScriptCorebytecompilerSetForScopeh">trunk/Source/JavaScriptCore/bytecompiler/SetForScope.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceJavaScriptCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/ChangeLog (189335 => 189336)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/ChangeLog        2015-09-04 02:43:41 UTC (rev 189335)
+++ trunk/Source/JavaScriptCore/ChangeLog        2015-09-04 03:05:46 UTC (rev 189336)
</span><span class="lines">@@ -1,3 +1,48 @@
</span><ins>+2015-09-03  Basile Clement  &lt;basile_clement@apple.com&gt;
+
+        [ES6] Recognize calls in tail position
+        https://bugs.webkit.org/show_bug.cgi?id=148665
+
+        Reviewed by Saam Barati.
+
+        This patch adds the capability for the bytecode generator to recognize
+        and dispatch tail calls, as per ES6 spec:
+        http://www.ecma-international.org/ecma-262/6.0/#sec-isintailposition
+
+        This does not change the generated bytecode, but merely provides the
+        hook for generating tail calls in subsequent patches toward
+        https://bugs.webkit.org/show_bug.cgi?id=146477
+
+        * bytecompiler/BytecodeGenerator.cpp:
+        (JSC::BytecodeGenerator::BytecodeGenerator):
+        (JSC::BytecodeGenerator::emitCallInTailPosition):
+        (JSC::BytecodeGenerator::emitCallVarargsInTailPosition):
+        * bytecompiler/BytecodeGenerator.h:
+        (JSC::BytecodeGenerator::emitNode):
+        (JSC::BytecodeGenerator::emitNodeInTailPosition):
+        * bytecompiler/NodesCodegen.cpp:
+        (JSC::FunctionCallValueNode::emitBytecode):
+        (JSC::FunctionCallResolveNode::emitBytecode):
+        (JSC::FunctionCallBracketNode::emitBytecode):
+        (JSC::FunctionCallDotNode::emitBytecode):
+        (JSC::CallFunctionCallDotNode::emitBytecode):
+        (JSC::ApplyFunctionCallDotNode::emitBytecode):
+        (JSC::LogicalOpNode::emitBytecode):
+        (JSC::ConditionalNode::emitBytecode):
+        (JSC::CommaNode::emitBytecode):
+        (JSC::SourceElements::emitBytecode):
+        (JSC::IfElseNode::emitBytecode):
+        (JSC::DoWhileNode::emitBytecode):
+        (JSC::WhileNode::emitBytecode):
+        (JSC::ForNode::emitBytecode):
+        (JSC::ReturnNode::emitBytecode):
+        (JSC::WithNode::emitBytecode):
+        (JSC::TryNode::emitBytecode):
+        * bytecompiler/SetForScope.h: Added.
+        (JSC::SetForScope::SetForScope):
+        (JSC::SetForScope::~SetForScope):
+        * runtime/Options.h:
+
</ins><span class="cx"> 2015-08-11  Basile Clement  &lt;basile_clement@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Add more strict mode tests
</span></span></pre></div>
<a id="trunkSourceJavaScriptCorebytecompilerBytecodeGeneratorcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp (189335 => 189336)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp        2015-09-04 02:43:41 UTC (rev 189335)
+++ trunk/Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp        2015-09-04 03:05:46 UTC (rev 189336)
</span><span class="lines">@@ -191,6 +191,7 @@
</span><span class="cx">     , m_vm(&amp;vm)
</span><span class="cx">     , m_isBuiltinFunction(codeBlock-&gt;isBuiltinFunction())
</span><span class="cx">     , m_usesNonStrictEval(codeBlock-&gt;usesEval() &amp;&amp; !codeBlock-&gt;isStrictMode())
</span><ins>+    , m_inTailPosition(Options::enableTailCalls() &amp;&amp; constructorKind() == ConstructorKind::None &amp;&amp; isStrictMode())
</ins><span class="cx"> {
</span><span class="cx">     for (auto&amp; constantRegister : m_linkTimeConstantRegisters)
</span><span class="cx">         constantRegister = nullptr;
</span><span class="lines">@@ -2480,6 +2481,14 @@
</span><span class="cx">     return emitCall(op_call, dst, func, expectedFunction, callArguments, divot, divotStart, divotEnd);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+RegisterID* BytecodeGenerator::emitCallInTailPosition(RegisterID* dst, RegisterID* func, ExpectedFunction expectedFunction, CallArguments&amp; callArguments, const JSTextPosition&amp; divot, const JSTextPosition&amp; divotStart, const JSTextPosition&amp; divotEnd)
+{
+    // FIXME: We should be emitting a new op_tail_call here when
+    // m_inTailPosition is false
+    // https://bugs.webkit.org/show_bug.cgi?id=148661
+    return emitCall(op_call, dst, func, expectedFunction, callArguments, divot, divotStart, divotEnd);
+}
+
</ins><span class="cx"> RegisterID* BytecodeGenerator::emitCallEval(RegisterID* dst, RegisterID* func, CallArguments&amp; callArguments, const JSTextPosition&amp; divot, const JSTextPosition&amp; divotStart, const JSTextPosition&amp; divotEnd)
</span><span class="cx"> {
</span><span class="cx">     return emitCall(op_call_eval, dst, func, NoExpectedFunction, callArguments, divot, divotStart, divotEnd);
</span><span class="lines">@@ -2629,6 +2638,14 @@
</span><span class="cx">     return emitCallVarargs(op_call_varargs, dst, func, thisRegister, arguments, firstFreeRegister, firstVarArgOffset, profileHookRegister, divot, divotStart, divotEnd);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+RegisterID* BytecodeGenerator::emitCallVarargsInTailPosition(RegisterID* dst, RegisterID* func, RegisterID* thisRegister, RegisterID* arguments, RegisterID* firstFreeRegister, int32_t firstVarArgOffset, RegisterID* profileHookRegister, const JSTextPosition&amp; divot, const JSTextPosition&amp; divotStart, const JSTextPosition&amp; divotEnd)
+{
+    // FIXME: We should be emitting a new op_tail_call here when
+    // m_inTailPosition is false
+    // https://bugs.webkit.org/show_bug.cgi?id=148661
+    return emitCallVarargs(op_call_varargs, dst, func, thisRegister, arguments, firstFreeRegister, firstVarArgOffset, profileHookRegister, divot, divotStart, divotEnd);
+}
+
</ins><span class="cx"> RegisterID* BytecodeGenerator::emitConstructVarargs(RegisterID* dst, RegisterID* func, RegisterID* thisRegister, RegisterID* arguments, RegisterID* firstFreeRegister, int32_t firstVarArgOffset, RegisterID* profileHookRegister, const JSTextPosition&amp; divot, const JSTextPosition&amp; divotStart, const JSTextPosition&amp; divotEnd)
</span><span class="cx"> {
</span><span class="cx">     return emitCallVarargs(op_construct_varargs, dst, func, thisRegister, arguments, firstFreeRegister, firstVarArgOffset, profileHookRegister, divot, divotStart, divotEnd);
</span></span></pre></div>
<a id="trunkSourceJavaScriptCorebytecompilerBytecodeGeneratorh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/bytecompiler/BytecodeGenerator.h (189335 => 189336)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/bytecompiler/BytecodeGenerator.h        2015-09-04 02:43:41 UTC (rev 189335)
+++ trunk/Source/JavaScriptCore/bytecompiler/BytecodeGenerator.h        2015-09-04 03:05:46 UTC (rev 189336)
</span><span class="lines">@@ -39,6 +39,7 @@
</span><span class="cx"> #include &quot;Interpreter.h&quot;
</span><span class="cx"> #include &quot;ParserError.h&quot;
</span><span class="cx"> #include &quot;RegisterID.h&quot;
</span><ins>+#include &quot;SetForScope.h&quot;
</ins><span class="cx"> #include &quot;SymbolTable.h&quot;
</span><span class="cx"> #include &quot;Debugger.h&quot;
</span><span class="cx"> #include &quot;Nodes.h&quot;
</span><span class="lines">@@ -359,6 +360,12 @@
</span><span class="cx"> 
</span><span class="cx">         void emitNode(RegisterID* dst, StatementNode* n)
</span><span class="cx">         {
</span><ins>+            SetForScope&lt;bool&gt; tailPositionPoisoner(m_inTailPosition, false);
+            return emitNodeInTailPosition(dst, n);
+        }
+
+        void emitNodeInTailPosition(RegisterID* dst, StatementNode* n)
+        {
</ins><span class="cx">             // Node::emitCode assumes that dst, if provided, is either a local or a referenced temporary.
</span><span class="cx">             ASSERT(!dst || dst == ignoredResult() || !dst-&gt;isTemporary() || dst-&gt;refCount());
</span><span class="cx">             if (!m_vm-&gt;isSafeToRecurse()) {
</span><span class="lines">@@ -370,11 +377,22 @@
</span><span class="cx"> 
</span><span class="cx">         void emitNode(StatementNode* n)
</span><span class="cx">         {
</span><del>-            emitNode(0, n);
</del><ins>+            emitNode(nullptr, n);
</ins><span class="cx">         }
</span><span class="cx"> 
</span><ins>+        void emitNodeInTailPosition(StatementNode* n)
+        {
+            emitNodeInTailPosition(nullptr, n);
+        }
+
</ins><span class="cx">         RegisterID* emitNode(RegisterID* dst, ExpressionNode* n)
</span><span class="cx">         {
</span><ins>+            SetForScope&lt;bool&gt; tailPositionPoisoner(m_inTailPosition, false);
+            return emitNodeInTailPosition(dst, n);
+        }
+
+        RegisterID* emitNodeInTailPosition(RegisterID* dst, ExpressionNode* n)
+        {
</ins><span class="cx">             // Node::emitCode assumes that dst, if provided, is either a local or a referenced temporary.
</span><span class="cx">             ASSERT(!dst || dst == ignoredResult() || !dst-&gt;isTemporary() || dst-&gt;refCount());
</span><span class="cx">             if (!m_vm-&gt;isSafeToRecurse())
</span><span class="lines">@@ -384,9 +402,14 @@
</span><span class="cx"> 
</span><span class="cx">         RegisterID* emitNode(ExpressionNode* n)
</span><span class="cx">         {
</span><del>-            return emitNode(0, n);
</del><ins>+            return emitNode(nullptr, n);
</ins><span class="cx">         }
</span><span class="cx"> 
</span><ins>+        RegisterID* emitNodeInTailPosition(ExpressionNode* n)
+        {
+            return emitNodeInTailPosition(nullptr, n);
+        }
+
</ins><span class="cx">         void emitNodeInConditionContext(ExpressionNode* n, Label* trueTarget, Label* falseTarget, FallThroughMode fallThroughMode)
</span><span class="cx">         {
</span><span class="cx">             if (!m_vm-&gt;isSafeToRecurse()) {
</span><span class="lines">@@ -518,8 +541,10 @@
</span><span class="cx">         
</span><span class="cx">         ExpectedFunction expectedFunctionForIdentifier(const Identifier&amp;);
</span><span class="cx">         RegisterID* emitCall(RegisterID* dst, RegisterID* func, ExpectedFunction, CallArguments&amp;, const JSTextPosition&amp; divot, const JSTextPosition&amp; divotStart, const JSTextPosition&amp; divotEnd);
</span><ins>+        RegisterID* emitCallInTailPosition(RegisterID* dst, RegisterID* func, ExpectedFunction, CallArguments&amp;, const JSTextPosition&amp; divot, const JSTextPosition&amp; divotStart, const JSTextPosition&amp; divotEnd);
</ins><span class="cx">         RegisterID* emitCallEval(RegisterID* dst, RegisterID* func, CallArguments&amp;, const JSTextPosition&amp; divot, const JSTextPosition&amp; divotStart, const JSTextPosition&amp; divotEnd);
</span><span class="cx">         RegisterID* emitCallVarargs(RegisterID* dst, RegisterID* func, RegisterID* thisRegister, RegisterID* arguments, RegisterID* firstFreeRegister, int32_t firstVarArgOffset, RegisterID* profileHookRegister, const JSTextPosition&amp; divot, const JSTextPosition&amp; divotStart, const JSTextPosition&amp; divotEnd);
</span><ins>+        RegisterID* emitCallVarargsInTailPosition(RegisterID* dst, RegisterID* func, RegisterID* thisRegister, RegisterID* arguments, RegisterID* firstFreeRegister, int32_t firstVarArgOffset, RegisterID* profileHookRegister, const JSTextPosition&amp; divot, const JSTextPosition&amp; divotStart, const JSTextPosition&amp; divotEnd);
</ins><span class="cx"> 
</span><span class="cx">         enum PropertyDescriptorOption {
</span><span class="cx">             PropertyConfigurable = 1,
</span><span class="lines">@@ -833,6 +858,7 @@
</span><span class="cx">         bool m_expressionTooDeep { false };
</span><span class="cx">         bool m_isBuiltinFunction { false };
</span><span class="cx">         bool m_usesNonStrictEval { false };
</span><ins>+        bool m_inTailPosition { false };
</ins><span class="cx">     };
</span><span class="cx"> 
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceJavaScriptCorebytecompilerNodesCodegencpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/bytecompiler/NodesCodegen.cpp (189335 => 189336)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/bytecompiler/NodesCodegen.cpp        2015-09-04 02:43:41 UTC (rev 189335)
+++ trunk/Source/JavaScriptCore/bytecompiler/NodesCodegen.cpp        2015-09-04 03:05:46 UTC (rev 189336)
</span><span class="lines">@@ -713,7 +713,7 @@
</span><span class="cx">         return ret;
</span><span class="cx">     }
</span><span class="cx">     generator.emitLoad(callArguments.thisRegister(), jsUndefined());
</span><del>-    RegisterID* ret = generator.emitCall(returnValue.get(), func.get(), NoExpectedFunction, callArguments, divot(), divotStart(), divotEnd());
</del><ins>+    RegisterID* ret = generator.emitCallInTailPosition(returnValue.get(), func.get(), NoExpectedFunction, callArguments, divot(), divotStart(), divotEnd());
</ins><span class="cx">     generator.emitProfileType(returnValue.get(), divotStart(), divotEnd());
</span><span class="cx">     return ret;
</span><span class="cx"> }
</span><span class="lines">@@ -733,7 +733,7 @@
</span><span class="cx">         generator.emitLoad(callArguments.thisRegister(), jsUndefined());
</span><span class="cx">         // This passes NoExpectedFunction because we expect that if the function is in a
</span><span class="cx">         // local variable, then it's not one of our built-in constructors.
</span><del>-        RegisterID* ret = generator.emitCall(returnValue.get(), func.get(), NoExpectedFunction, callArguments, divot(), divotStart(), divotEnd());
</del><ins>+        RegisterID* ret = generator.emitCallInTailPosition(returnValue.get(), func.get(), NoExpectedFunction, callArguments, divot(), divotStart(), divotEnd());
</ins><span class="cx">         generator.emitProfileType(returnValue.get(), divotStart(), divotEnd());
</span><span class="cx">         return ret;
</span><span class="cx">     }
</span><span class="lines">@@ -749,7 +749,7 @@
</span><span class="cx">         generator.emitResolveScope(callArguments.thisRegister(), var));
</span><span class="cx">     generator.emitGetFromScope(func.get(), callArguments.thisRegister(), var, ThrowIfNotFound);
</span><span class="cx">     generator.emitTDZCheckIfNecessary(var, func.get(), nullptr);
</span><del>-    RegisterID* ret = generator.emitCall(returnValue.get(), func.get(), expectedFunction, callArguments, divot(), divotStart(), divotEnd());
</del><ins>+    RegisterID* ret = generator.emitCallInTailPosition(returnValue.get(), func.get(), expectedFunction, callArguments, divot(), divotStart(), divotEnd());
</ins><span class="cx">     generator.emitProfileType(returnValue.get(), divotStart(), divotEnd());
</span><span class="cx">     return ret;
</span><span class="cx"> }
</span><span class="lines">@@ -817,7 +817,7 @@
</span><span class="cx">         generator.emitMove(callArguments.thisRegister(), generator.thisRegister());
</span><span class="cx">     else
</span><span class="cx">         generator.emitMove(callArguments.thisRegister(), base.get());
</span><del>-    RegisterID* ret = generator.emitCall(returnValue.get(), function.get(), NoExpectedFunction, callArguments, divot(), divotStart(), divotEnd());
</del><ins>+    RegisterID* ret = generator.emitCallInTailPosition(returnValue.get(), function.get(), NoExpectedFunction, callArguments, divot(), divotStart(), divotEnd());
</ins><span class="cx">     generator.emitProfileType(returnValue.get(), divotStart(), divotEnd());
</span><span class="cx">     return ret;
</span><span class="cx"> }
</span><span class="lines">@@ -836,7 +836,7 @@
</span><span class="cx">         generator.emitNode(callArguments.thisRegister(), m_base);
</span><span class="cx">     generator.emitExpressionInfo(subexpressionDivot(), subexpressionStart(), subexpressionEnd());
</span><span class="cx">     generator.emitGetById(function.get(), baseIsSuper ? emitSuperBaseForCallee(generator) : callArguments.thisRegister(), m_ident);
</span><del>-    RegisterID* ret = generator.emitCall(returnValue.get(), function.get(), NoExpectedFunction, callArguments, divot(), divotStart(), divotEnd());
</del><ins>+    RegisterID* ret = generator.emitCallInTailPosition(returnValue.get(), function.get(), NoExpectedFunction, callArguments, divot(), divotStart(), divotEnd());
</ins><span class="cx">     generator.emitProfileType(returnValue.get(), divotStart(), divotEnd());
</span><span class="cx">     return ret;
</span><span class="cx"> }
</span><span class="lines">@@ -865,7 +865,7 @@
</span><span class="cx">             argumentsRegister = generator.emitNode(subject);
</span><span class="cx">             generator.emitExpressionInfo(spread-&gt;divot(), spread-&gt;divotStart(), spread-&gt;divotEnd());
</span><span class="cx">             RefPtr&lt;RegisterID&gt; thisRegister = generator.emitGetByVal(generator.newTemporary(), argumentsRegister.get(), generator.emitLoad(0, jsNumber(0)));
</span><del>-            generator.emitCallVarargs(returnValue.get(), base.get(), thisRegister.get(), argumentsRegister.get(), generator.newTemporary(), 1, profileHookRegister.get(), divot(), divotStart(), divotEnd());
</del><ins>+            generator.emitCallVarargsInTailPosition(returnValue.get(), base.get(), thisRegister.get(), argumentsRegister.get(), generator.newTemporary(), 1, profileHookRegister.get(), divot(), divotStart(), divotEnd());
</ins><span class="cx">         } else if (m_args-&gt;m_listNode &amp;&amp; m_args-&gt;m_listNode-&gt;m_expr) {
</span><span class="cx">             ArgumentListNode* oldList = m_args-&gt;m_listNode;
</span><span class="cx">             m_args-&gt;m_listNode = m_args-&gt;m_listNode-&gt;m_next;
</span><span class="lines">@@ -873,13 +873,13 @@
</span><span class="cx">             RefPtr&lt;RegisterID&gt; realFunction = generator.emitMove(generator.tempDestination(dst), base.get());
</span><span class="cx">             CallArguments callArguments(generator, m_args);
</span><span class="cx">             generator.emitNode(callArguments.thisRegister(), oldList-&gt;m_expr);
</span><del>-            generator.emitCall(returnValue.get(), realFunction.get(), NoExpectedFunction, callArguments, divot(), divotStart(), divotEnd());
</del><ins>+            generator.emitCallInTailPosition(returnValue.get(), realFunction.get(), NoExpectedFunction, callArguments, divot(), divotStart(), divotEnd());
</ins><span class="cx">             m_args-&gt;m_listNode = oldList;
</span><span class="cx">         } else {
</span><span class="cx">             RefPtr&lt;RegisterID&gt; realFunction = generator.emitMove(generator.tempDestination(dst), base.get());
</span><span class="cx">             CallArguments callArguments(generator, m_args);
</span><span class="cx">             generator.emitLoad(callArguments.thisRegister(), jsUndefined());
</span><del>-            generator.emitCall(returnValue.get(), realFunction.get(), NoExpectedFunction, callArguments, divot(), divotStart(), divotEnd());
</del><ins>+            generator.emitCallInTailPosition(returnValue.get(), realFunction.get(), NoExpectedFunction, callArguments, divot(), divotStart(), divotEnd());
</ins><span class="cx">         }
</span><span class="cx">     }
</span><span class="cx">     if (emitCallCheck) {
</span><span class="lines">@@ -888,7 +888,7 @@
</span><span class="cx">         {
</span><span class="cx">             CallArguments callArguments(generator, m_args);
</span><span class="cx">             generator.emitMove(callArguments.thisRegister(), base.get());
</span><del>-            generator.emitCall(returnValue.get(), function.get(), NoExpectedFunction, callArguments, divot(), divotStart(), divotEnd());
</del><ins>+            generator.emitCallInTailPosition(returnValue.get(), function.get(), NoExpectedFunction, callArguments, divot(), divotStart(), divotEnd());
</ins><span class="cx">         }
</span><span class="cx">         generator.emitLabel(end.get());
</span><span class="cx">     }
</span><span class="lines">@@ -951,7 +951,7 @@
</span><span class="cx">                     generator.emitLabel(end.get());
</span><span class="cx">                 };
</span><span class="cx">                 generator.emitEnumeration(this, spread-&gt;expression(), extractor);
</span><del>-                generator.emitCallVarargs(returnValue.get(), realFunction.get(), thisRegister.get(), argumentsRegister.get(), generator.newTemporary(), 0, profileHookRegister.get(), divot(), divotStart(), divotEnd());
</del><ins>+                generator.emitCallVarargsInTailPosition(returnValue.get(), realFunction.get(), thisRegister.get(), argumentsRegister.get(), generator.newTemporary(), 0, profileHookRegister.get(), divot(), divotStart(), divotEnd());
</ins><span class="cx">             } else if (m_args-&gt;m_listNode-&gt;m_next) {
</span><span class="cx">                 ASSERT(m_args-&gt;m_listNode-&gt;m_next-&gt;m_expr-&gt;isSimpleArray());
</span><span class="cx">                 ASSERT(!m_args-&gt;m_listNode-&gt;m_next-&gt;m_next);
</span><span class="lines">@@ -959,20 +959,20 @@
</span><span class="cx">                 RefPtr&lt;RegisterID&gt; realFunction = generator.emitMove(generator.tempDestination(dst), base.get());
</span><span class="cx">                 CallArguments callArguments(generator, m_args);
</span><span class="cx">                 generator.emitNode(callArguments.thisRegister(), oldList-&gt;m_expr);
</span><del>-                generator.emitCall(returnValue.get(), realFunction.get(), NoExpectedFunction, callArguments, divot(), divotStart(), divotEnd());
</del><ins>+                generator.emitCallInTailPosition(returnValue.get(), realFunction.get(), NoExpectedFunction, callArguments, divot(), divotStart(), divotEnd());
</ins><span class="cx">             } else {
</span><span class="cx">                 m_args-&gt;m_listNode = m_args-&gt;m_listNode-&gt;m_next;
</span><span class="cx">                 RefPtr&lt;RegisterID&gt; realFunction = generator.emitMove(generator.tempDestination(dst), base.get());
</span><span class="cx">                 CallArguments callArguments(generator, m_args);
</span><span class="cx">                 generator.emitNode(callArguments.thisRegister(), oldList-&gt;m_expr);
</span><del>-                generator.emitCall(returnValue.get(), realFunction.get(), NoExpectedFunction, callArguments, divot(), divotStart(), divotEnd());
</del><ins>+                generator.emitCallInTailPosition(returnValue.get(), realFunction.get(), NoExpectedFunction, callArguments, divot(), divotStart(), divotEnd());
</ins><span class="cx">             }
</span><span class="cx">             m_args-&gt;m_listNode = oldList;
</span><span class="cx">         } else {
</span><span class="cx">             RefPtr&lt;RegisterID&gt; realFunction = generator.emitMove(generator.tempDestination(dst), base.get());
</span><span class="cx">             CallArguments callArguments(generator, m_args);
</span><span class="cx">             generator.emitLoad(callArguments.thisRegister(), jsUndefined());
</span><del>-            generator.emitCall(returnValue.get(), realFunction.get(), NoExpectedFunction, callArguments, divot(), divotStart(), divotEnd());
</del><ins>+            generator.emitCallInTailPosition(returnValue.get(), realFunction.get(), NoExpectedFunction, callArguments, divot(), divotStart(), divotEnd());
</ins><span class="cx">         }
</span><span class="cx">     } else {
</span><span class="cx">         ASSERT(m_args-&gt;m_listNode &amp;&amp; m_args-&gt;m_listNode-&gt;m_next);
</span><span class="lines">@@ -990,14 +990,14 @@
</span><span class="cx">         while ((args = args-&gt;m_next))
</span><span class="cx">             generator.emitNode(args-&gt;m_expr);
</span><span class="cx"> 
</span><del>-        generator.emitCallVarargs(returnValue.get(), realFunction.get(), thisRegister.get(), argsRegister.get(), generator.newTemporary(), 0, profileHookRegister.get(), divot(), divotStart(), divotEnd());
</del><ins>+        generator.emitCallVarargsInTailPosition(returnValue.get(), realFunction.get(), thisRegister.get(), argsRegister.get(), generator.newTemporary(), 0, profileHookRegister.get(), divot(), divotStart(), divotEnd());
</ins><span class="cx">     }
</span><span class="cx">     if (emitCallCheck) {
</span><span class="cx">         generator.emitJump(end.get());
</span><span class="cx">         generator.emitLabel(realCall.get());
</span><span class="cx">         CallArguments callArguments(generator, m_args);
</span><span class="cx">         generator.emitMove(callArguments.thisRegister(), base.get());
</span><del>-        generator.emitCall(returnValue.get(), function.get(), NoExpectedFunction, callArguments, divot(), divotStart(), divotEnd());
</del><ins>+        generator.emitCallInTailPosition(returnValue.get(), function.get(), NoExpectedFunction, callArguments, divot(), divotStart(), divotEnd());
</ins><span class="cx">         generator.emitLabel(end.get());
</span><span class="cx">     }
</span><span class="cx">     generator.emitProfileType(returnValue.get(), divotStart(), divotEnd());
</span><span class="lines">@@ -1632,7 +1632,7 @@
</span><span class="cx">         generator.emitJumpIfFalse(temp.get(), target.get());
</span><span class="cx">     else
</span><span class="cx">         generator.emitJumpIfTrue(temp.get(), target.get());
</span><del>-    generator.emitNode(temp.get(), m_expr2);
</del><ins>+    generator.emitNodeInTailPosition(temp.get(), m_expr2);
</ins><span class="cx">     generator.emitLabel(target.get());
</span><span class="cx"> 
</span><span class="cx">     return generator.moveToDestinationIfNeeded(dst, temp.get());
</span><span class="lines">@@ -1663,12 +1663,12 @@
</span><span class="cx">     generator.emitLabel(beforeThen.get());
</span><span class="cx"> 
</span><span class="cx">     generator.emitProfileControlFlow(m_expr1-&gt;startOffset());
</span><del>-    generator.emitNode(newDst.get(), m_expr1);
</del><ins>+    generator.emitNodeInTailPosition(newDst.get(), m_expr1);
</ins><span class="cx">     generator.emitJump(afterElse.get());
</span><span class="cx"> 
</span><span class="cx">     generator.emitLabel(beforeElse.get());
</span><span class="cx">     generator.emitProfileControlFlow(m_expr1-&gt;endOffset() + 1);
</span><del>-    generator.emitNode(newDst.get(), m_expr2);
</del><ins>+    generator.emitNodeInTailPosition(newDst.get(), m_expr2);
</ins><span class="cx"> 
</span><span class="cx">     generator.emitLabel(afterElse.get());
</span><span class="cx"> 
</span><span class="lines">@@ -1927,7 +1927,7 @@
</span><span class="cx">     CommaNode* node = this;
</span><span class="cx">     for (; node &amp;&amp; node-&gt;next(); node = node-&gt;next())
</span><span class="cx">         generator.emitNode(generator.ignoredResult(), node-&gt;m_expr);
</span><del>-    return generator.emitNode(dst, node-&gt;m_expr);
</del><ins>+    return generator.emitNodeInTailPosition(dst, node-&gt;m_expr);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> // ------------------------------ SourceElements -------------------------------
</span><span class="lines">@@ -1941,7 +1941,7 @@
</span><span class="cx"> inline void SourceElements::emitBytecode(BytecodeGenerator&amp; generator, RegisterID* dst)
</span><span class="cx"> {
</span><span class="cx">     for (StatementNode* statement = m_head; statement; statement = statement-&gt;next())
</span><del>-        generator.emitNode(dst, statement);
</del><ins>+        generator.emitNodeInTailPosition(dst, statement);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> // ------------------------------ BlockNode ------------------------------------
</span><span class="lines">@@ -2095,7 +2095,7 @@
</span><span class="cx">     generator.emitProfileControlFlow(m_ifBlock-&gt;startOffset());
</span><span class="cx"> 
</span><span class="cx">     if (!didFoldIfBlock) {
</span><del>-        generator.emitNode(dst, m_ifBlock);
</del><ins>+        generator.emitNodeInTailPosition(dst, m_ifBlock);
</ins><span class="cx">         if (m_elseBlock)
</span><span class="cx">             generator.emitJump(afterElse.get());
</span><span class="cx">     }
</span><span class="lines">@@ -2104,7 +2104,7 @@
</span><span class="cx"> 
</span><span class="cx">     if (m_elseBlock) {
</span><span class="cx">         generator.emitProfileControlFlow(m_ifBlock-&gt;endOffset() + (m_ifBlock-&gt;isBlock() ? 1 : 0));
</span><del>-        generator.emitNode(dst, m_elseBlock);
</del><ins>+        generator.emitNodeInTailPosition(dst, m_elseBlock);
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     generator.emitLabel(afterElse.get());
</span><span class="lines">@@ -2123,7 +2123,7 @@
</span><span class="cx">     generator.emitLoopHint();
</span><span class="cx">     generator.emitDebugHook(WillExecuteStatement, lastLine(), startOffset(), lineStartOffset());
</span><span class="cx"> 
</span><del>-    generator.emitNode(dst, m_statement);
</del><ins>+    generator.emitNodeInTailPosition(dst, m_statement);
</ins><span class="cx"> 
</span><span class="cx">     generator.emitLabel(scope-&gt;continueTarget());
</span><span class="cx">     generator.emitDebugHook(WillExecuteStatement, lastLine(), startOffset(), lineStartOffset());
</span><span class="lines">@@ -2146,7 +2146,7 @@
</span><span class="cx">     generator.emitLoopHint();
</span><span class="cx">     
</span><span class="cx">     generator.emitProfileControlFlow(m_statement-&gt;startOffset());
</span><del>-    generator.emitNode(dst, m_statement);
</del><ins>+    generator.emitNodeInTailPosition(dst, m_statement);
</ins><span class="cx"> 
</span><span class="cx">     generator.emitLabel(scope-&gt;continueTarget());
</span><span class="cx">     generator.emitDebugHook(WillExecuteStatement, firstLine(), startOffset(), lineStartOffset());
</span><span class="lines">@@ -2180,7 +2180,7 @@
</span><span class="cx">     generator.emitLoopHint();
</span><span class="cx">     generator.emitProfileControlFlow(m_statement-&gt;startOffset());
</span><span class="cx"> 
</span><del>-    generator.emitNode(dst, m_statement);
</del><ins>+    generator.emitNodeInTailPosition(dst, m_statement);
</ins><span class="cx"> 
</span><span class="cx">     generator.emitLabel(scope-&gt;continueTarget());
</span><span class="cx">     generator.emitDebugHook(WillExecuteStatement, firstLine(), startOffset(), lineStartOffset());
</span><span class="lines">@@ -2557,7 +2557,7 @@
</span><span class="cx">     if (dst == generator.ignoredResult())
</span><span class="cx">         dst = 0;
</span><span class="cx"> 
</span><del>-    RefPtr&lt;RegisterID&gt; returnRegister = m_value ? generator.emitNode(dst, m_value) : generator.emitLoad(dst, jsUndefined());
</del><ins>+    RefPtr&lt;RegisterID&gt; returnRegister = m_value ? generator.emitNodeInTailPosition(dst, m_value) : generator.emitLoad(dst, jsUndefined());
</ins><span class="cx">     generator.emitProfileType(returnRegister.get(), ProfileTypeBytecodeFunctionReturnStatement, divotStart(), divotEnd());
</span><span class="cx">     if (generator.isInFinallyBlock()) {
</span><span class="cx">         returnRegister = generator.emitMove(generator.newTemporary(), returnRegister.get());
</span><span class="lines">@@ -2582,7 +2582,7 @@
</span><span class="cx">     RefPtr&lt;RegisterID&gt; scope = generator.emitNode(m_expr);
</span><span class="cx">     generator.emitExpressionInfo(m_divot, m_divot - m_expressionLength, m_divot);
</span><span class="cx">     generator.emitPushWithScope(scope.get());
</span><del>-    generator.emitNode(dst, m_statement);
</del><ins>+    generator.emitNodeInTailPosition(dst, m_statement);
</ins><span class="cx">     generator.emitPopWithScope();
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -2835,7 +2835,10 @@
</span><span class="cx"> 
</span><span class="cx">         generator.emitPushCatchScope(m_thrownValueIdent, thrownValueRegister.get(), m_catchEnvironment);
</span><span class="cx">         generator.emitProfileControlFlow(m_tryBlock-&gt;endOffset() + 1);
</span><del>-        generator.emitNode(dst, m_catchBlock);
</del><ins>+        if (m_finallyBlock)
+            generator.emitNode(dst, m_catchBlock);
+        else
+            generator.emitNodeInTailPosition(dst, m_catchBlock);
</ins><span class="cx">         generator.emitPopCatchScope(m_catchEnvironment);
</span><span class="cx">         generator.emitLabel(catchEndLabel.get());
</span><span class="cx">     }
</span><span class="lines">@@ -2851,7 +2854,7 @@
</span><span class="cx"> 
</span><span class="cx">         // Normal path: run the finally code, and jump to the end.
</span><span class="cx">         generator.emitProfileControlFlow(finallyStartOffset);
</span><del>-        generator.emitNode(dst, m_finallyBlock);
</del><ins>+        generator.emitNodeInTailPosition(dst, m_finallyBlock);
</ins><span class="cx">         generator.emitProfileControlFlow(m_finallyBlock-&gt;endOffset() + 1);
</span><span class="cx">         generator.emitJump(finallyEndLabel.get());
</span><span class="cx"> 
</span><span class="lines">@@ -2860,7 +2863,7 @@
</span><span class="cx">         RefPtr&lt;RegisterID&gt; thrownValueRegister = generator.newTemporary();
</span><span class="cx">         generator.popTryAndEmitCatch(tryData, exceptionRegister.get(), thrownValueRegister.get(), preFinallyLabel.get(), HandlerType::Finally);
</span><span class="cx">         generator.emitProfileControlFlow(finallyStartOffset);
</span><del>-        generator.emitNode(dst, m_finallyBlock);
</del><ins>+        generator.emitNodeInTailPosition(dst, m_finallyBlock);
</ins><span class="cx">         generator.emitThrow(exceptionRegister.get());
</span><span class="cx"> 
</span><span class="cx">         generator.emitLabel(finallyEndLabel.get());
</span></span></pre></div>
<a id="trunkSourceJavaScriptCorebytecompilerSetForScopeh"></a>
<div class="addfile"><h4>Added: trunk/Source/JavaScriptCore/bytecompiler/SetForScope.h (0 => 189336)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/bytecompiler/SetForScope.h                                (rev 0)
+++ trunk/Source/JavaScriptCore/bytecompiler/SetForScope.h        2015-09-04 03:05:46 UTC (rev 189336)
</span><span class="lines">@@ -0,0 +1,37 @@
</span><ins>+#ifndef SetForScope_h
+#define SetForScope_h
+
+#include &lt;wtf/StdLibExtras.h&gt;
+
+namespace JSC {
+
+template&lt;typename T&gt;
+class SetForScope {
+public:
+    SetForScope(T&amp; currentValue, const T&amp; newValue)
+        : m_ref(currentValue)
+        , m_oldValue(currentValue)
+    {
+        m_ref = newValue;
+    }
+
+    SetForScope(T&amp; currentValue, T&amp;&amp; newValue)
+        : m_ref(currentValue)
+        , m_oldValue(currentValue)
+    {
+        currentValue = WTF::move(newValue);
+    }
+
+    ~SetForScope()
+    {
+        m_ref = m_oldValue;
+    }
+
+private:
+    T&amp; m_ref;
+    T m_oldValue;
+};
+
+}; // namespace JSC
+
+#endif // SetForScope_h
</ins></span></pre></div>
<a id="trunkSourceJavaScriptCoreruntimeOptionsh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/runtime/Options.h (189335 => 189336)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/runtime/Options.h        2015-09-04 02:43:41 UTC (rev 189335)
+++ trunk/Source/JavaScriptCore/runtime/Options.h        2015-09-04 03:05:46 UTC (rev 189336)
</span><span class="lines">@@ -128,6 +128,7 @@
</span><span class="cx">     v(bool, forceProfilerBytecodeGeneration, false, nullptr) \
</span><span class="cx">     \
</span><span class="cx">     v(bool, enableFunctionDotArguments, true, nullptr) \
</span><ins>+    v(bool, enableTailCalls, true, nullptr) \
</ins><span class="cx">     \
</span><span class="cx">     /* showDisassembly implies showDFGDisassembly. */ \
</span><span class="cx">     v(bool, showDisassembly, false, &quot;dumps disassembly of all JIT compiled code upon compilation&quot;) \
</span></span></pre>
</div>
</div>

</body>
</html>