<div dir="ltr"><div>And last thing there's an absolutely cheap way to remove optimization: don't provide a block argument. For example provide a message send instead:<br></div><div><br></div><div>[true or: [false] yourself] bench.<br> '39,900,000 per second. 25 nanoseconds per run.'<br><br>[true or: [false]] bench.<br>'177,000,000 per second. 5.63 nanoseconds per run.'</div><div><br></div><div>If you like syntactic sugar, implement BlockClosure>>unoptimized as ^self and write:</div><div><br></div><div>    true or: [false] unoptimized.</div><div><br></div><div>And last, here is a draft that I wrote in 2015 in the pharo thread about mustBeBoolean workaround</div><div>(but I never sent that draft, I didn't want to sound too negative) :</div><div><h2 id="gmail-:13j" class="gmail-hP" tabindex="-1">[Pharo-dev] can or: be redefined?</h2></div><div>...snip...<br></div><div><div>> That's
 the way to go. I think some people like Camille are already working on 
it. Basically, you need abstraction over what is happening which is 
implemented in the image instead of the VM for simplicity and 
maintenance, and what the programmer wants to see which is relevant for 
him.</div><div><br></div><div>> For optimized selectors, one could mark 
the methods with pragmas as 'Do not show in debugger' and in addition 
rewire the bytecode to source code mapping from the method compiled 
on-the-fly executed in ExecuteUnoptimizedIn: to the regular method.</div><div><br></div><div>> But
 as I stated for Slots, it is more complicated. The debugger cannot 
detect if the stack is currently in a slot access, as it has access only
 to the bottom 20 frames. Having the debugger access the full stack is a
 bad idea as it would slow it considerably, making the debugger unusable
 on devices such as the raspberry pie, and hard to use to debug 
recursive code. Maybe a solution could be that if the compiled bytecode 
for a slot has an interrupt point (branch, back jump, send), then it 
could change a state in the process, probably encoded in the process 
instance variables, and as the debugger has access to the process it is 
showing it would know.</div><div> </div><div><br><div>It sounds like inserting an elephant in the stack and keep prretending it's turtle all the way down ;)<br>Isn't the cheat too visible?<br><br></div>Some essential Smalltalk principles/properties shall better not be lost:<br></div><div>- there's a well defined virtual machine which acts as boundary 
between Smalltalk code and non Smalltalk (primitive) code.<br>- everyone should be in a position to understand 
every single bit of Smalltalk code and the debugger is the ultimate 
introspective tool to do so.<br><br></div>There are times when you want to debug slot implementation itself, think of it...<br><div class="gmail_quote">And
 there will be times when you want to introspect how the machinery 
works, maybe because you want to understand time spent in a method or 
come with a similar trick.<br></div><div>I hope it does not imply debugging at bytecode level, this would be a great loss.<br></div><div><br></div><div>To me, the whole #or: story sounds like you came with a complex workaround for hiding an optimization.<br></div><div>And now you're trying to hide the workaround with an even more complex machinery which endanger first principles:<br><br>Just admitting and learning that there are a very few exceptions to the rules sounds very cheap in regard.<br></div>I wish you success, but it's scary!</div></div><div class="gmail_extra"><br><div class="gmail_quote">2017-09-18 19:22 GMT+02:00 Levente Uzonyi <span dir="ltr"><<a href="mailto:leves@caesar.elte.hu" target="_blank">leves@caesar.elte.hu</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
On Sun, 17 Sep 2017, Sean P. DeNigris wrote:<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
On the "Squeak Beginners" ML, a new Smalltalker wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
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>
</blockquote>
<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>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
   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>
</blockquote>
<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>
<br>
p.s. IIRC e.g. Opal has flags to modify this behavior, but could the actual<br>
messages be sent by default, and the flag be set to inline when that<br>
performance boost is actually required?<br>
</blockquote>
<br>
You can turn off all those optimizations in your image except for potentially infinite loops.<br>
<br>
The performance drop will be larger than you may think, because Cog has its own native implementation for most if not all those methods. So it'll skip both primitives and special bytecodes when possible and inline them into the jitted code (This can result in nasty debug situations when the jitter code's behavior differs from what the image side code suggests).<br>
<br>
Also, most of those methods are not newbie-safe. Changing any of them will probably freeze your image.<br>
<br>
Finally, these changes can only be done on the image side, so this question probably belongs to another list.<br>
<br>
Levente<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
<br>
<br>
-----<br>
Cheers,<br>
Sean<span class=""><br>
--<br>
Sent from: <a href="http://forum.world.st/Squeak-VM-f104410.html" rel="noreferrer" target="_blank">http://forum.world.st/Squeak-V<wbr>M-f104410.html</a><br>
</span></blockquote>
</blockquote></div><br></div>