<!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>[184318] 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/184318">184318</a></dd>
<dt>Author</dt> <dd>fpizlo@apple.com</dd>
<dt>Date</dt> <dd>2015-05-13 16:57:17 -0700 (Wed, 13 May 2015)</dd>
</dl>

<h3>Log Message</h3>
<pre>Creating a new blank document in icloud pages causes an AI error: Abstract value (CellBytecodedoubleBoolOther, TOP, TOP) for double node has type outside SpecFullDouble.
https://bugs.webkit.org/show_bug.cgi?id=144856

Reviewed by Benjamin Poulain.
        
First I made fixTypeForRepresentation() print out better diagnostics when it dies.
        
Then I fixed the bug: Node::convertToIdentityOn(Node*) needs to make sure that when it
converts to a representation-changing node, it needs to use one of the UseKinds that such
a node expects. For example, DoubleRep(UntypedUse:) doesn't make sense; it needs to be
something like DoubleRep(NumberUse:) since it will speculate that the input is a number.

* dfg/DFGAbstractInterpreter.h:
(JSC::DFG::AbstractInterpreter::setBuiltInConstant):
* dfg/DFGAbstractInterpreterInlines.h:
(JSC::DFG::AbstractInterpreter&lt;AbstractStateType&gt;::executeEffects):
* dfg/DFGAbstractValue.cpp:
(JSC::DFG::AbstractValue::fixTypeForRepresentation):
* dfg/DFGAbstractValue.h:
* dfg/DFGInPlaceAbstractState.cpp:
(JSC::DFG::InPlaceAbstractState::initialize):
* dfg/DFGNode.cpp:
(JSC::DFG::Node::convertToIdentityOn):
* tests/stress/cloned-arguments-get-by-val-double-array.js: Added.
(foo):</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceJavaScriptCoreChangeLog">trunk/Source/JavaScriptCore/ChangeLog</a></li>
<li><a href="#trunkSourceJavaScriptCoredfgDFGAbstractInterpreterh">trunk/Source/JavaScriptCore/dfg/DFGAbstractInterpreter.h</a></li>
<li><a href="#trunkSourceJavaScriptCoredfgDFGAbstractInterpreterInlinesh">trunk/Source/JavaScriptCore/dfg/DFGAbstractInterpreterInlines.h</a></li>
<li><a href="#trunkSourceJavaScriptCoredfgDFGAbstractValuecpp">trunk/Source/JavaScriptCore/dfg/DFGAbstractValue.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoredfgDFGAbstractValueh">trunk/Source/JavaScriptCore/dfg/DFGAbstractValue.h</a></li>
<li><a href="#trunkSourceJavaScriptCoredfgDFGInPlaceAbstractStatecpp">trunk/Source/JavaScriptCore/dfg/DFGInPlaceAbstractState.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoredfgDFGNodecpp">trunk/Source/JavaScriptCore/dfg/DFGNode.cpp</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkSourceJavaScriptCoretestsstressclonedargumentsgetbyvaldoublearrayjs">trunk/Source/JavaScriptCore/tests/stress/cloned-arguments-get-by-val-double-array.js</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceJavaScriptCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/ChangeLog (184317 => 184318)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/ChangeLog        2015-05-13 23:33:10 UTC (rev 184317)
+++ trunk/Source/JavaScriptCore/ChangeLog        2015-05-13 23:57:17 UTC (rev 184318)
</span><span class="lines">@@ -1,3 +1,31 @@
</span><ins>+2015-05-13  Filip Pizlo  &lt;fpizlo@apple.com&gt;
+
+        Creating a new blank document in icloud pages causes an AI error: Abstract value (CellBytecodedoubleBoolOther, TOP, TOP) for double node has type outside SpecFullDouble.
+        https://bugs.webkit.org/show_bug.cgi?id=144856
+
+        Reviewed by Benjamin Poulain.
+        
+        First I made fixTypeForRepresentation() print out better diagnostics when it dies.
+        
+        Then I fixed the bug: Node::convertToIdentityOn(Node*) needs to make sure that when it
+        converts to a representation-changing node, it needs to use one of the UseKinds that such
+        a node expects. For example, DoubleRep(UntypedUse:) doesn't make sense; it needs to be
+        something like DoubleRep(NumberUse:) since it will speculate that the input is a number.
+
+        * dfg/DFGAbstractInterpreter.h:
+        (JSC::DFG::AbstractInterpreter::setBuiltInConstant):
+        * dfg/DFGAbstractInterpreterInlines.h:
+        (JSC::DFG::AbstractInterpreter&lt;AbstractStateType&gt;::executeEffects):
+        * dfg/DFGAbstractValue.cpp:
+        (JSC::DFG::AbstractValue::fixTypeForRepresentation):
+        * dfg/DFGAbstractValue.h:
+        * dfg/DFGInPlaceAbstractState.cpp:
+        (JSC::DFG::InPlaceAbstractState::initialize):
+        * dfg/DFGNode.cpp:
+        (JSC::DFG::Node::convertToIdentityOn):
+        * tests/stress/cloned-arguments-get-by-val-double-array.js: Added.
+        (foo):
+
</ins><span class="cx"> 2015-05-13  Commit Queue  &lt;commit-queue@webkit.org&gt;
</span><span class="cx"> 
</span><span class="cx">         Unreviewed, rolling out r184313.
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoredfgDFGAbstractInterpreterh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/dfg/DFGAbstractInterpreter.h (184317 => 184318)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/dfg/DFGAbstractInterpreter.h        2015-05-13 23:33:10 UTC (rev 184317)
+++ trunk/Source/JavaScriptCore/dfg/DFGAbstractInterpreter.h        2015-05-13 23:57:17 UTC (rev 184318)
</span><span class="lines">@@ -168,7 +168,7 @@
</span><span class="cx">     {
</span><span class="cx">         AbstractValue&amp; abstractValue = forNode(node);
</span><span class="cx">         abstractValue.set(m_graph, value, m_state.structureClobberState());
</span><del>-        abstractValue.fixTypeForRepresentation(node);
</del><ins>+        abstractValue.fixTypeForRepresentation(m_graph, node);
</ins><span class="cx">     }
</span><span class="cx">     
</span><span class="cx">     void setConstant(Node* node, FrozenValue value)
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoredfgDFGAbstractInterpreterInlinesh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/dfg/DFGAbstractInterpreterInlines.h (184317 => 184318)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/dfg/DFGAbstractInterpreterInlines.h        2015-05-13 23:33:10 UTC (rev 184317)
+++ trunk/Source/JavaScriptCore/dfg/DFGAbstractInterpreterInlines.h        2015-05-13 23:57:17 UTC (rev 184318)
</span><span class="lines">@@ -348,7 +348,7 @@
</span><span class="cx">             break;
</span><span class="cx">         }
</span><span class="cx">         forNode(node).setType(m_graph, forNode(node-&gt;child1()).m_type);
</span><del>-        forNode(node).fixTypeForRepresentation(node);
</del><ins>+        forNode(node).fixTypeForRepresentation(m_graph, node);
</ins><span class="cx">         break;
</span><span class="cx">     }
</span><span class="cx">         
</span><span class="lines">@@ -371,7 +371,7 @@
</span><span class="cx">         }
</span><span class="cx">         
</span><span class="cx">         forNode(node).setType(m_graph, forNode(node-&gt;child1()).m_type &amp; ~SpecDoubleImpureNaN);
</span><del>-        forNode(node).fixTypeForRepresentation(node);
</del><ins>+        forNode(node).fixTypeForRepresentation(m_graph, node);
</ins><span class="cx">         break;
</span><span class="cx">     }
</span><span class="cx">         
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoredfgDFGAbstractValuecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/dfg/DFGAbstractValue.cpp (184317 => 184318)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/dfg/DFGAbstractValue.cpp        2015-05-13 23:33:10 UTC (rev 184317)
+++ trunk/Source/JavaScriptCore/dfg/DFGAbstractValue.cpp        2015-05-13 23:57:17 UTC (rev 184318)
</span><span class="lines">@@ -136,7 +136,7 @@
</span><span class="cx">     checkConsistency();
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void AbstractValue::fixTypeForRepresentation(NodeFlags representation)
</del><ins>+void AbstractValue::fixTypeForRepresentation(Graph&amp; graph, NodeFlags representation, Node* node)
</ins><span class="cx"> {
</span><span class="cx">     if (representation == NodeResultDouble) {
</span><span class="cx">         if (m_value) {
</span><span class="lines">@@ -148,39 +148,30 @@
</span><span class="cx">             m_type &amp;= ~SpecMachineInt;
</span><span class="cx">             m_type |= SpecInt52AsDouble;
</span><span class="cx">         }
</span><del>-        if (m_type &amp; ~SpecFullDouble) {
-            startCrashing();
-            dataLog(&quot;Abstract value &quot;, *this, &quot; for double node has type outside SpecFullDouble.\n&quot;);
-            CRASH();
-        }
</del><ins>+        if (m_type &amp; ~SpecFullDouble)
+            DFG_CRASH(graph, node, toCString(&quot;Abstract value &quot;, *this, &quot; for double node has type outside SpecFullDouble.\n&quot;).data());
</ins><span class="cx">     } else if (representation == NodeResultInt52) {
</span><span class="cx">         if (m_type &amp; SpecInt52AsDouble) {
</span><span class="cx">             m_type &amp;= ~SpecInt52AsDouble;
</span><span class="cx">             m_type |= SpecInt52;
</span><span class="cx">         }
</span><del>-        if (m_type &amp; ~SpecMachineInt) {
-            startCrashing();
-            dataLog(&quot;Abstract value &quot;, *this, &quot; for int52 node has type outside SpecMachineInt.\n&quot;);
-            CRASH();
-        }
</del><ins>+        if (m_type &amp; ~SpecMachineInt)
+            DFG_CRASH(graph, node, toCString(&quot;Abstract value &quot;, *this, &quot; for int52 node has type outside SpecMachineInt.\n&quot;).data());
</ins><span class="cx">     } else {
</span><span class="cx">         if (m_type &amp; SpecInt52) {
</span><span class="cx">             m_type &amp;= ~SpecInt52;
</span><span class="cx">             m_type |= SpecInt52AsDouble;
</span><span class="cx">         }
</span><del>-        if (m_type &amp; ~SpecBytecodeTop) {
-            startCrashing();
-            dataLog(&quot;Abstract value &quot;, *this, &quot; for value node has type outside SpecBytecodeTop.\n&quot;);
-            CRASH();
-        }
</del><ins>+        if (m_type &amp; ~SpecBytecodeTop)
+            DFG_CRASH(graph, node, toCString(&quot;Abstract value &quot;, *this, &quot; for value node has type outside SpecBytecodeTop.\n&quot;).data());
</ins><span class="cx">     }
</span><span class="cx">     
</span><span class="cx">     checkConsistency();
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void AbstractValue::fixTypeForRepresentation(Node* node)
</del><ins>+void AbstractValue::fixTypeForRepresentation(Graph&amp; graph, Node* node)
</ins><span class="cx"> {
</span><del>-    fixTypeForRepresentation(node-&gt;result());
</del><ins>+    fixTypeForRepresentation(graph, node-&gt;result(), node);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> FiltrationResult AbstractValue::filter(Graph&amp; graph, const StructureSet&amp; other)
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoredfgDFGAbstractValueh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/dfg/DFGAbstractValue.h (184317 => 184318)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/dfg/DFGAbstractValue.h        2015-05-13 23:33:10 UTC (rev 184317)
+++ trunk/Source/JavaScriptCore/dfg/DFGAbstractValue.h        2015-05-13 23:57:17 UTC (rev 184318)
</span><span class="lines">@@ -213,8 +213,8 @@
</span><span class="cx">         checkConsistency();
</span><span class="cx">     }
</span><span class="cx">     
</span><del>-    void fixTypeForRepresentation(NodeFlags representation);
-    void fixTypeForRepresentation(Node*);
</del><ins>+    void fixTypeForRepresentation(Graph&amp;, NodeFlags representation, Node* = nullptr);
+    void fixTypeForRepresentation(Graph&amp;, Node*);
</ins><span class="cx">     
</span><span class="cx">     bool operator==(const AbstractValue&amp; other) const
</span><span class="cx">     {
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoredfgDFGInPlaceAbstractStatecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/dfg/DFGInPlaceAbstractState.cpp (184317 => 184318)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/dfg/DFGInPlaceAbstractState.cpp        2015-05-13 23:33:10 UTC (rev 184317)
+++ trunk/Source/JavaScriptCore/dfg/DFGInPlaceAbstractState.cpp        2015-05-13 23:57:17 UTC (rev 184318)
</span><span class="lines">@@ -167,7 +167,7 @@
</span><span class="cx">             VariableAccessData* variable = node-&gt;variableAccessData();
</span><span class="cx">             FlushFormat format = variable-&gt;flushFormat();
</span><span class="cx">             target.merge(source);
</span><del>-            target.fixTypeForRepresentation(resultFor(format));
</del><ins>+            target.fixTypeForRepresentation(m_graph, resultFor(format));
</ins><span class="cx">         }
</span><span class="cx">         block-&gt;cfaShouldRevisit = true;
</span><span class="cx">     }
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoredfgDFGNodecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/dfg/DFGNode.cpp (184317 => 184318)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/dfg/DFGNode.cpp        2015-05-13 23:33:10 UTC (rev 184317)
+++ trunk/Source/JavaScriptCore/dfg/DFGNode.cpp        2015-05-13 23:57:17 UTC (rev 184318)
</span><span class="lines">@@ -116,17 +116,44 @@
</span><span class="cx">     }
</span><span class="cx">     switch (output) {
</span><span class="cx">     case NodeResultDouble:
</span><del>-        RELEASE_ASSERT(input == NodeResultInt52 || input == NodeResultJS);
</del><span class="cx">         setOpAndDefaultFlags(DoubleRep);
</span><del>-        return;
</del><ins>+        switch (input) {
+        case NodeResultInt52:
+            child1().setUseKind(Int52RepUse);
+            return;
+        case NodeResultJS:
+            child1().setUseKind(NumberUse);
+            return;
+        default:
+            RELEASE_ASSERT_NOT_REACHED();
+            return;
+        }
</ins><span class="cx">     case NodeResultInt52:
</span><del>-        RELEASE_ASSERT(input == NodeResultDouble || input == NodeResultJS);
</del><span class="cx">         setOpAndDefaultFlags(Int52Rep);
</span><del>-        return;
</del><ins>+        switch (input) {
+        case NodeResultDouble:
+            child1().setUseKind(DoubleRepMachineIntUse);
+            return;
+        case NodeResultJS:
+            child1().setUseKind(MachineIntUse);
+            return;
+        default:
+            RELEASE_ASSERT_NOT_REACHED();
+            return;
+        }
</ins><span class="cx">     case NodeResultJS:
</span><del>-        RELEASE_ASSERT(input == NodeResultDouble || input == NodeResultInt52);
</del><span class="cx">         setOpAndDefaultFlags(ValueRep);
</span><del>-        return;
</del><ins>+        switch (input) {
+        case NodeResultDouble:
+            child1().setUseKind(DoubleRepUse);
+            return;
+        case NodeResultInt52:
+            child1().setUseKind(Int52RepUse);
+            return;
+        default:
+            RELEASE_ASSERT_NOT_REACHED();
+            return;
+        }
</ins><span class="cx">     default:
</span><span class="cx">         RELEASE_ASSERT_NOT_REACHED();
</span><span class="cx">         return;
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoretestsstressclonedargumentsgetbyvaldoublearrayjs"></a>
<div class="addfile"><h4>Added: trunk/Source/JavaScriptCore/tests/stress/cloned-arguments-get-by-val-double-array.js (0 => 184318)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/tests/stress/cloned-arguments-get-by-val-double-array.js                                (rev 0)
+++ trunk/Source/JavaScriptCore/tests/stress/cloned-arguments-get-by-val-double-array.js        2015-05-13 23:57:17 UTC (rev 184318)
</span><span class="lines">@@ -0,0 +1,13 @@
</span><ins>+function foo() {
+    &quot;use strict&quot;;
+    return arguments[0] + 1.5;
+}
+
+noInline(foo);
+
+for (var i = 0; i &lt; 10000; ++i) {
+    var result = foo(4.2);
+    if (result != 5.7)
+        throw &quot;Error: bad result: &quot; + result;
+}
+
</ins></span></pre>
</div>
</div>

</body>
</html>