<div dir="ltr"><div>Hi</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">We don't want to give up that performance, but we would like to not get caught cheating either. This would be very simple if instead of raising the "must be boolean" error, we could simply retry the send as a regular message send. </blockquote><div><br></div><div>This is already in Pharo :)</div></div><div class="gmail_extra"><br><div class="gmail_quote">2017-09-18 15:32 GMT+02:00 Bert Freudenberg <span dir="ltr"><<a href="mailto:bert@freudenbergs.de" target="_blank">bert@freudenbergs.de</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"> <br><div dir="ltr"><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small;color:rgb(0,0,0)"><span style="font-family:arial,sans-serif;color:rgb(34,34,34)">On Sun, Sep 17, 2017 at 3:51 PM, Sean P. DeNigris </span><span dir="ltr" style="font-family:arial,sans-serif;color:rgb(34,34,34)"><<a href="mailto:sean@clipperadams.com" target="_blank">sean@clipperadams.com</a>></span><span style="font-family:arial,sans-serif;color:rgb(34,34,34)"> wrote:</span><br></div><div class="gmail_extra"><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"><br>
On the "Squeak Beginners" ML, a new Smalltalker wrote:<br>
> I don't understand why Smalltalk doesn't allow me to have an or:<br>
> method that takes a block argument (except on Boolean).<br>
<br>
The answer apparently was that the compiler replaces the code with an<br>
optimization that is usually what one wants, and the actual message never<br>
gets sent:<br>
>    Ralph Johnson wrote<br>
>    Yes, when the compiler sees   exp or: [ ... ] then it assumes that<br>
> "exp" is<br>
>   a boolean-valued expression and generates code that fails if it isn't.<br>
<br>
I remember the pain of tripping over these little "everything is a message<br>
send to an object*" sins as a new Smalltalker. I wonder now, with the<br>
incredible speed of Cog, Spur, Sista, etc., if these devil's bargains from<br>
prior decades are still necessary. It would be psychologically satisfying<br>
(and nice for newbies) to remove the asterisk from the principle above.<br></blockquote><div> </div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small;color:rgb(0,0,0)">​Yes, optimization of boolean-looking expressions is cheating that gets caught once in a while. </div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small;color:rgb(0,0,0)"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small;color:rgb(0,0,0)">But even in Cog it's still 400% faster:</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small;color:rgb(0,0,0)"><br></div><div class="gmail_default"><font color="#000000" face="arial, helvetica, sans-serif">[false or: [true]] bench</font></div><div class="gmail_default"><font color="#000000" face="arial, helvetica, sans-serif"><br></font></div><div class="gmail_default"><font color="#000000" face="arial, helvetica, sans-serif"> '198,000,000 per second. 5.06 nanoseconds per run.'</font></div><div class="gmail_default"><font color="#000000" face="arial, helvetica, sans-serif"> '211,000,000 per second. 4.75 nanoseconds per run.'</font></div><div class="gmail_default"><font color="#000000" face="arial, helvetica, sans-serif"> '209,000,000 per second. 4.79 nanoseconds per run.'</font></div><div class="gmail_default"><font color="#000000" face="arial, helvetica, sans-serif"><br></font></div><div class="gmail_default"><font color="#000000" face="arial, helvetica, sans-serif">... and again with #transformOr: disabled:</font></div><div class="gmail_default"><font color="#000000" face="arial, helvetica, sans-serif"><br></font></div><div class="gmail_default"><font color="#000000" face="arial, helvetica, sans-serif"> '47,100,000 per second. 21.2 nanoseconds per run.'</font></div><div class="gmail_default"><font color="#000000" face="arial, helvetica, sans-serif"> '47,500,000 per second. 21.1 nanoseconds per run.' </font></div><div class="gmail_default"><font color="#000000" face="arial, helvetica, sans-serif">'48,000,000 per second. 20.8 nanoseconds per run.'</font></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small;color:rgb(0,0,0)">​</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small;color:rgb(0,0,0)">We don't want to give up that performance, but we would like to not get caught cheating either. This would be very simple if instead of raising the "must be boolean" error, we could simply retry the send as a regular message send. </div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small;color:rgb(0,0,0)"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small;color:rgb(0,0,0)">The major complication here is that in the byte code we don't know the original method selector (e.g. ifTrue:ifFalse: etc), and we do not have the original block closure arguments, because they never got constructed in the first place.</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small;color:rgb(0,0,0)"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small;color:rgb(0,0,0)">There are various ways to tackle that problem with different speed/space tradeoffs. If we don't care too much about the non-boolean receiver performance (it's the slow path after all) then no modifications to the VM would be needed.</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small;color:rgb(0,0,0)"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small;color:rgb(0,0,0)">You should be able to do it all in the #mustBeBoolean handler: perform the original selector with the block arguments, then jump to after the optimized block. Sounds like a fun, if not exactly trivial project :) </div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small;color:rgb(0,0,0)"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small;color:rgb(0,0,0)">- Bert -</div></div></div></div>
<br></blockquote></div><br></div>