On Aug 31, 2020, at 3:30 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

No it isn’t.  The vm detects an attempt to unwind across an unwind protect (either ensure: if ifCurtailed:), and sends aboutToReturn:to: to the current context.  Everything happens up in the image from that point.
For the third time see Context>>#resume:through: which runs the ensure: & ifCurtailed: blocks.