<div dir="ltr"><div dir="ltr">On Mon, Dec 7, 2020 at 9:12 PM Eliot Miranda <<a href="mailto:eliot.miranda@gmail.com">eliot.miranda@gmail.com</a>> wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="auto"><blockquote type="cite"><div dir="ltr"><div id="gmail-m_2222118066688630322divtagdefaultwrapper" style="font-size:12pt;color:rgb(0,0,0);font-family:Calibri,Helvetica,sans-serif" dir="ltr"><p>nil == thisContext pop</p>
<p><span style="font-size:12pt">I guess this is fine, because what alternatives would the execution machinery have? It could terminate the whole VM or we could introduce something like #cannotReturn: for invalid stack frame objects. Probably the current implementation is the best despite
 an invalid position in the context stack has been addressed.</span></p></div></div></blockquote></div></blockquote><div><br></div><div>Well, one pop is almost "fine" because there still is an object on the stack (the receiver). But if you were to do 2 pops then we would fetch from the void.</div><div> </div><div><img src="cid:ii_kjku37v21" alt="image.png" width="181" height="131" style="margin-right: 0px;"><br></div><div><br></div><div>after stepping over #pop it looks like this</div><div><br></div><div><img src="cid:ii_kjku4d0v2" alt="image.png" width="180" height="120" style="margin-right: 0px;"><br></div><div><br></div><div>... when there really should be 2 nils on the stack (in slots 6 and 7). After stepping once more:</div><div><br></div><div><img src="cid:ii_kjku6xeu3" alt="image.png" width="180" height="108" style="margin-right: 0px;"><br></div><div><br></div><div>... it actually replaced the receiver slot, going "below" the stack.</div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="auto"><div><blockquote type="cite"><div dir="ltr"><div id="gmail-m_2222118066688630322divtagdefaultwrapper" style="font-size:12pt;color:rgb(0,0,0);font-family:Calibri,Helvetica,sans-serif" dir="ltr"><p><span style="font-size:12pt">However, the simulation machinery treats the same snippet differently, and it throws:</span></p>
<p><span>Error: subscript is out of bounds: 0</span></p></div></div></blockquote></div></div></blockquote><div>If we did bounds checking for stack access in SqueakJS (which I used for the above screenshots) then yes we could produce an error. But that would be really expensive.</div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="auto"><div><blockquote type="cite"><div dir="ltr"><div id="gmail-m_2222118066688630322divtagdefaultwrapper" style="font-size:12pt;color:rgb(0,0,0);font-family:Calibri,Helvetica,sans-serif" dir="ltr">
<p><span>I wonder whether it is acceptable to have diverging behaviors for such an ill-defined edge case between simulation and production (btw did I choose the right terms for them? :)). Might it a better alternative to raise a Warning (#notify:) only and
 then return nil such as the VM appears to do?</span></p></div></div></blockquote>It’s a very good question.  I’m going to provide a very lazy and pragmatic answer, forced by lack of resources to address the issue properly.  It’s clear that the behaviour is at best undefined.  It is good that the simulation produces an error. The only regrettable thing is that what is reported is a low-level error rather than a high-level one that says, fir example, “undefined behaviour encountered”.  Achieving a specification which states that this is undefined behaviour allows the JIT to get away with not dealing with the issue, and that’s important because dealing with the issue such that the JIT could detect this as an error would likely destroy lots of performance gains it is able to make by assuming it is given valid defined execution sequences.</div><div><br></div><div>That’s a long winded way of saying that, given limited resources, I’m giving the same response as a doctor that when told by a patient that it hurts when the patient does X says “then stop doing X”.</div></div></blockquote><div><br></div><div>Exactly.</div><div><br></div><div>Dr. Vanessa </div></div></div>