On Mon, Aug 31, 2020 at 6:29 PM Florin Mateoc <florin.mateoc@gmail.com> wrote:



On Mon, Aug 31, 2020 at 6:00 PM Eliot Miranda <eliot.miranda@gmail.com> wrote:
 


On Mon, Aug 31, 2020 at 2:00 PM Florin Mateoc <florin.mateoc@gmail.com> wrote:
 
I think this is especially confusing since the comment says that the primitive always fails, and then the expectation is that the Smalltalk code that follows is executed instead. But that code does not do what the method actually does

I disagree.  It does exactly what the method does (it *is* the implementation of the method) unless the stack is unwound.  Yes, the comment could point the reader to Context>>#resume:through: which runs the ensure: & ifCurtailed: blocks on unwind.  Bit otherwise ifCurtailed: is not somehow magically not executed.  It is what it is ;-)

As I said earlier,  ifCurtailed: only evaluates its argument if a non-local return or exception return is taken and the normal return path is not taken.  See Context>>#resume:through: which runs the ensure: & ifCurtailed: blocks.

Can I confirm that your dissatisfaction is with the comment?  Or do you really think the ifCurtailed: method does not execute verbatim in the absence of unwinds?  If the former, you're welcome to submit an improved comment.  If the latter, you're mistaken.



Of course I agree that the ifCurtailed: method does execute verbatim in the absence of unwind. But the method does not only execute in the absence of unwinds. So my "dissatisfaction" is not just with the comment. While it could be somewhat be addressed by a comment, I think this is an instance where the vm is caught cheating. The shown Smalltalk code is not what gets executed in the presence of unwinds (as opposed to the code shown in #ensure: ). The execution of the argument block is hidden inside the vm


To be more pedantic, neither #ensure: nor #ifCurtailed: disclose what is really happening on the unwind path, but at least #ensure: shows some code that conceptually matches its semantics.
In both cases, there is magic happening inside #valueNoContextSwitch, which, although it does not take any arguments, it knows how to (call a method that knows how to) invoke, if necessary, its caller's argument.
Yes, by walking the stack and peeking inside the contexts' temps and then acting upon them anything is possible, but the resulting code is anything but readable.

I would argue for passing the #ensure: and #ifCurtailed: arguments to the #valueNoContextSwitch method/primitive, thus making it possible to avoid #resume:through: - I think such methods are fine for simulation/debugger, but not for runtime.