<br><br><div class="gmail_quote">On Fri, Dec 2, 2011 at 8:04 PM, Eliot Miranda <span dir="ltr">&lt;<a href="mailto:eliot.miranda@gmail.com">eliot.miranda@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<br><br><div class="gmail_quote"><div class="im">On Fri, Dec 2, 2011 at 10:55 AM, Mariano Martinez Peck <span dir="ltr">&lt;<a href="mailto:marianopeck@gmail.com" target="_blank">marianopeck@gmail.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Thanks both. I am right to assume that if the block refers to temp vars, parameters, or whatever in another scope, then such solution won&#39;t work. I mean, if I have this example for example:<br><br>| bytes result blah |<br>


blah := 42.<br>bytes := FLSerializer serializeToByteArray: (SortedCollection sortBlock: [:a :b | (a + blah) &gt; b ]).<br><br>Then the &#39;blah&#39; is in a different context. So the mentioned solution works for &quot;clean&quot; closures, which are &quot;self contained&quot;. In the other cases (such as this example), we should serialize the whole stack. Is this correct?<br>

</blockquote><div><br></div></div><div>No.  The closure implementation arranges that any and all temporary variables accessed by the closure are directly accessible from the closure without accessing the outer contexts.  </div>
</div></blockquote><div><br>Ahhhhhhh :)<br> </div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"><div class="gmail_quote"><div>You were there for my presentation Mariano :)  And you understood the issue then right ? :)  </div>
</div></blockquote><div><br>Well, yes, but I usually understand in the second or third time ;)<br> </div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<div class="gmail_quote"><div>Remember the closure compiler *copies* any temporary variables that are not changed after being closed over into a closure&#39;s copiedValues, and *moves* any temporary variables that could be changed after being closed over into indirection vectors, and these indirection vectors are copied into the copied values of the closure.  </div>
</div></blockquote><div><br>Excellent. So everything is inside the closure. When you say &quot;copiedValues&quot; I guess you use the variable part of BlockClosure, is that right?<br> </div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<div class="gmail_quote"><div>But, as I just said, the receiver and method are not copied (to save time at closure creation) since these are in the outerContext already.  These are fetched from the outerContext when the closure is activated.</div>
</div></blockquote><div><br>Got it. <br> </div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"><div class="gmail_quote">
<div><br></div><div>That&#39;s the trade-off, slower closure creation and larger closures and duplication if a closure refers to its method and receiver directly, faster closure creation, smaller closures, less duplication and very slightly slower activation if closures refer to their receiver and method indirectly.  The additional trade-off is this issue; the indirect approach entails more problems for serialization and for implementing compile-time clean closures (since the compiler needs to create an outerContext for the method and nil for the non-existent receiver - clean closures can&#39;t refer to self).</div>

<div><br></div><div>Is this clear or as clear as mud?</div></div></blockquote><div><br>Much clear now. One last question. So far, then, I didn&#39;t find/think a scenario where serializing the whole stack (from a closure)  make sense. So, if I just want to serialize a closure and be able to materialize it, then it is *never* necessary the whole stack, in all scenarios?  or I am missing a case where the whole stack is needed?   I am talking only about when serializing closures, because if I directly serialize a MethodContext, it may happen that I want the whole stack (like the example I showed in ESUG where I serialized the whole Debugger and then I continue debugging in another image). <br>
<br>Thanks!<br> </div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"><div class="gmail_quote"><div><div class="h5"><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<br>Thanks!<div><div></div><div><br><br><div class="gmail_quote">On Fri, Dec 2, 2011 at 7:41 PM, Eliot Miranda <span dir="ltr">&lt;<a href="mailto:eliot.miranda@gmail.com" target="_blank">eliot.miranda@gmail.com</a>&gt;</span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br><br><div class="gmail_quote"><div><div>On Fri, Dec 2, 2011 at 10:20 AM, Nicolas Cellier <span dir="ltr">&lt;<a href="mailto:nicolas.cellier.aka.nice@gmail.com" target="_blank">nicolas.cellier.aka.nice@gmail.com</a>&gt;</span> wrote:<br>


<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
2011/12/2 Martin Dias &lt;<a href="mailto:tinchodias@gmail.com" target="_blank">tinchodias@gmail.com</a>&gt;:<br>
<div><div></div><div>&gt; Hi folks<br>
&gt;<br>
&gt; In Fuel, we serialize a block closure with its state, including its<br>
&gt; outerContext. This enables to serialize a sorted collection with its<br>
&gt; sortBlock:<br>
&gt;<br>
&gt; | bytes result |<br>
&gt; bytes := FLSerializer serializeToByteArray: (SortedCollection sortBlock: [:a<br>
&gt; :b | a &gt; b ]).<br>
&gt; result := FLMaterializer materializeFromByteArray: bytes.<br>
&gt; result<br>
&gt; addAll: #(1 2 3);<br>
&gt; yourself.<br>
&gt; ---&gt; a SortedCollection(3 2 1)<br>
&gt;<br>
&gt; Here the problem: the byte array is huge! (800kb) because we are serializing<br>
&gt; unneeded context for the sort block.<br>
&gt;<br>
&gt; We wonder how to prune it and save time and space.<br>
&gt;<br>
&gt; Thanks in advance<br>
&gt; Martín<br>
<br>
</div></div>In the case of such clean block, there is no need of outer context<br>
during block execution.<br>
However I don&#39;t know if implementation makes it possible to ignore the<br>
context...<br>
That&#39;s more a question directed to Eliot ;)<br></blockquote><div><br></div></div></div><div>Arguably there is a bug in my closure implementation, which is that both the receiver and the method are fetched from the outerContext.  That&#39;s not a bug which can be fixed without a new VM/image combination and may be something I&#39;ll look at long-term, but is something we have to live with at the moment.  This means that you *do* have to serialize the outerContext.  But the outerContext is used only for the receiver and method.  So you don&#39;t need to full serialize the outerContext.  In particular you don&#39;t need to serialize any of the outerContext&#39;s stack contents or its sender.  This needs special handling, I guess in BlockClosure, to substitute a suitably reduced outerContext, but it shouldn&#39;t be hard to do.  e.g.</div>



<div><br></div><div>BlockClosure methods for: &#39;*Fuel-serialization&#39;</div><div>outerContextForSerialization</div><div><span style="white-space:pre-wrap">        </span>^MethodContext</div><div><span style="white-space:pre-wrap">                </span>sender: nil</div>



<div><span style="white-space:pre-wrap">                </span>receiver outerContext receiver</div><div><span style="white-space:pre-wrap">                </span>method: outerContext method</div><div><span style="white-space:pre-wrap">                </span>args: #()</div>



<div><br></div><div><br></div><div>BlockClosure methods for: &#39;*Fuel-serialization&#39;</div><div>outerContextForSerialization</div><div><span style="white-space:pre-wrap">        </span>^MethodContext</div>
<div><span style="white-space:pre-wrap">                </span>sender: nil</div><div><span style="white-space:pre-wrap">                </span>receiver self receiver</div><div><span style="white-space:pre-wrap">                </span>method: self method</div>
<div><span style="white-space:pre-wrap">                </span>args: #()</div><div><br></div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<font color="#888888"><br>
Nicolas<br>
<br><span><font color="#888888">
</font></span></font></blockquote></div><span><font color="#888888"><br><br clear="all"><div><br></div>-- <br>best,<div>Eliot</div><br>
</font></span><br><br>
<br></blockquote></div><br><br clear="all"><br></div></div><font color="#888888">-- <br>Mariano<br><a href="http://marianopeck.wordpress.com" target="_blank">http://marianopeck.wordpress.com</a><br><br>
</font><br><br>
<br></blockquote></div></div></div><span class="HOEnZb"><font color="#888888"><br><br clear="all"><div><br></div>-- <br>best,<div>Eliot</div><br>
</font></span><br><br>
<br></blockquote></div><br><br clear="all"><br>-- <br>Mariano<br><a href="http://marianopeck.wordpress.com" target="_blank">http://marianopeck.wordpress.com</a><br><br>