<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=windows-1252"
http-equiv="Content-Type">
<title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
Hi Jaromir,<br>
<br>
(inline)<br>
On 4/30/2021 7:01 AM, Jaromir Matas via Cuis-dev wrote:
<blockquote
cite="mid:BN7PR08MB38422AE118D7EADA80DE7127EE5E9@BN7PR08MB3842.namprd08.prod.outlook.com"
type="cite">
<meta http-equiv="Content-Type" content="text/html;
charset=windows-1252">
<meta name="Generator" content="Microsoft Word 15 (filtered
medium)">
<!--[if !mso]><style>v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style><![endif]-->
<style><!--
/* Font Definitions */
@font-face
{font-family:Helvetica;
panose-1:2 11 5 4 2 2 2 2 2 4;}
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
font-size:11.0pt;
font-family:"Calibri",sans-serif;
color:windowtext;}
h1
{mso-style-priority:9;
mso-style-link:"Heading 1 Char";
mso-margin-top-alt:auto;
margin-right:0in;
mso-margin-bottom-alt:auto;
margin-left:0in;
font-size:24.0pt;
font-family:"Calibri",sans-serif;
color:black;
font-weight:bold;}
h2
{mso-style-priority:9;
mso-style-link:"Heading 2 Char";
mso-margin-top-alt:auto;
margin-right:0in;
mso-margin-bottom-alt:auto;
margin-left:0in;
font-size:18.0pt;
font-family:"Calibri",sans-serif;
color:black;
font-weight:bold;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
pre
{mso-style-priority:99;
mso-style-link:"HTML Preformatted Char";
margin:0in;
font-size:10.0pt;
font-family:"Courier New";
color:black;}
span.Heading1Char
{mso-style-name:"Heading 1 Char";
mso-style-priority:9;
mso-style-link:"Heading 1";
font-family:"Calibri",sans-serif;
color:black;
font-weight:bold;}
span.Heading2Char
{mso-style-name:"Heading 2 Char";
mso-style-priority:9;
mso-style-link:"Heading 2";
font-family:"Calibri",sans-serif;
color:black;
font-weight:bold;}
span.HTMLPreformattedChar
{mso-style-name:"HTML Preformatted Char";
mso-style-priority:99;
mso-style-link:"HTML Preformatted";
font-family:"Courier New";
color:black;}
.MsoChpDefault
{mso-style-type:export-only;}
@page WordSection1
{size:8.5in 11.0in;
margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
{page:WordSection1;}
--></style>
<div class="WordSection1">
<p class="MsoNormal">Hi Juan,</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Awesome! I remember the idea of using the
result of #runUntilErrorOrReturnFrom crossed my mind for a
fleeting moment… and then I lost it ;) With your permission
I’d like to use your fix in my Squeak version as well.</p>
</div>
</blockquote>
<o:p><br>
I'm glad you like it. Yes, of course. In these low level details,
it is a good thing to have as much common code as possible!<br>
<br>
Besides, in general, all the code we publish for Cuis is MIT
license, and free for any use.<br>
<br>
</o:p>
<blockquote
cite="mid:BN7PR08MB38422AE118D7EADA80DE7127EE5E9@BN7PR08MB3842.namprd08.prod.outlook.com"
type="cite">
<div class="WordSection1">
<p class="MsoNormal">I’ve tried to rewrite your #<span
style="color: black;">test1ATerminate
</span>without the method calls – and indeed it passes… and
that’s why I missed that – it was too simple; when using sends
is where your fix comes to the rescue – THANKS!</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"> | p a |</p>
<p class="MsoNormal"> a := Array new: 4 withAll: false.</p>
<p class="MsoNormal"> p := [</p>
<p class="MsoNormal"> [</p>
<p class="MsoNormal"> [ ] ensure: [</p>
<p class="MsoNormal">
[Processor activeProcess
suspend] ensure: [</p>
<p class="MsoNormal">
^a at: 1 put:
true]. "line L1"</p>
<p class="MsoNormal">
a at: 2 put:
true] "line L2"</p>
<p class="MsoNormal"> ] ensure: [a
at: 3 put: true].</p>
<p class="MsoNormal"> a at: 4 put:
true</p>
<p class="MsoNormal"> ] newProcess.</p>
<p class="MsoNormal"> p resume.</p>
<p class="MsoNormal"> Processor yield.</p>
<p class="MsoNormal"> "make sure p is suspended and none of
the unwind blocks has finished yet"</p>
<p class="MsoNormal"> self assert: p isSuspended.</p>
<p class="MsoNormal"> a noneSatisfy: [ :b | b ].</p>
<p class="MsoNormal"> "now terminate the process and make
sure all unwind blocks have finished"</p>
<p class="MsoNormal"> p terminate.</p>
<p class="MsoNormal"> self assert: p isTerminated.</p>
<p class="MsoNormal"> self assert: a first & a third.</p>
<p class="MsoNormal"> self assert: (a second | a fourth) not.</p>
</div>
</blockquote>
<br>
Yes it does. I just thought that a more real-life like test of non
local returns should also include actual method calls!<br>
<blockquote
cite="mid:BN7PR08MB38422AE118D7EADA80DE7127EE5E9@BN7PR08MB3842.namprd08.prod.outlook.com"
type="cite">
<div class="WordSection1">
<p class="MsoNormal">I’d like to raise a question here: I feel
the second item, on line L2 should ideally execute too because
it’s inside an unwind block halfway through it’s termination.
The problem is though the non-local return at line L1 invokes
it’s own unwind algorithm in #resume:through: which ignores
halfway through unwind blocks – the reason for that is
#resume:through: operates on the active process’s stack which
makes it extremely difficult to unwind halfway through blocks.
I tried to apply a similar tactics like in termination
(control the unwind from another stack) and it works well but
it’s very intrusive… I may open a separate discussion on that
later to share the results. Do you think it may be worth
exploring or it’s just not worth the bother?</p>
</div>
</blockquote>
<o:p><br>
Well. This is not just in the case of process #terminate, right?
To play with this without involving process handling, but
including actual method calls I just tried this:<br>
<br>
m1<br>
| a |<br>
a := Array new: 3.<br>
self m2: a.<br>
a at: 3 put: true.<br>
a print.<br>
<br>
m2: a "A"<br>
[1 + 2] ensure: [<br>
[ 3 + 4 ] ensure: [ "*1"<br>
true ifTrue: [<br>
^a at: 1 put: true ]]. "*2"<br>
a at: 2 put: true ]<br>
<br>
In this example, the *1ensure is there only to guarantee that *2is
ran, even if [3+4] happens to fail. If [3+4] it runs without
problems, the result should be exactly the same as</o:p>:<br>
<br>
m2: a "B"<br>
[1 + 2] ensure: [<br>
3 + 4.<br>
true ifTrue: [<br>
^a at: 1 put: true ].<br>
a at: 2 put: true ]<br>
<br>
Applying the same argument, the result should be the same as:<br>
<br>
m2: a "C"<br>
1 + 2.<br>
3 + 4.<br>
true ifTrue: [<br>
^a at: 1 put: true ].<br>
a at: 2 put: true<br>
<br>
In implementation C it is clear that a second isNil. So, the same
should be the case for B and A.<br>
<br>
I think that an ensured block should be guaranteed to run without
external interference. But if it decides on its own to exit before
running all its statements, it is it's own decision.<br>
<o:p><br>
</o:p>
<blockquote
cite="mid:BN7PR08MB38422AE118D7EADA80DE7127EE5E9@BN7PR08MB3842.namprd08.prod.outlook.com"
type="cite">
<div class="WordSection1">
<p class="MsoNormal">Another issue: I considered using the error
part of the result of #runUntilErrorOrReturnFrom: to deal with
situations like this (careful – crashes the Cuis image without
the terminate fix; with the fix it works “ok”):</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">x := nil.</p>
<p class="MsoNormal">[self error: 'x1'] ensure: [</p>
<p class="MsoNormal"> [self error: 'x2'] ensure: [</p>
<p class="MsoNormal"> [self error: 'x3'] ensure: [</p>
<p class="MsoNormal"> x:=3].</p>
<p class="MsoNormal"> x:=2].</p>
<p class="MsoNormal"> x:=1].</p>
<p class="MsoNormal">x</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Here you have nested errors and the
question is: If we abandon the Debugger window, what do we
want to see as a result? Without the fix the image crashes
badly with unwind errors, with the fix however the Debugger
closes without unwinding – it’s a consequence of #
runUntilErrorOrReturnFrom: behavior – it returns errors rather
than opens a debugger (and leaves the decision with the user).
So what do we want to see as a result – keep opening debugger
windows and abandoning them manually or ignoring the errors
and executing the assignments? That sounds like “resuming”
rather than abandoning to me so at the moment I don’t know and
will have to think about it. I just didn’t want to complicate
the #terminate prematurely :)</p>
</div>
</blockquote>
<o:p><br>
I think this case is very similar to the one above.. For example,
if we proceed the first debugger (the x1 error), the x2 debugger
opens. If we abandon it, we are abandoning the execution of the
first ensured block (that includes the x := 1 assignment at the
end). So, no assignment is done. I think that the behavior of our
fix is correct in this case. No need to simulate "resuming".<br>
<br>
</o:p>
<blockquote
cite="mid:BN7PR08MB38422AE118D7EADA80DE7127EE5E9@BN7PR08MB3842.namprd08.prod.outlook.com"
type="cite">
<div class="WordSection1">
<p class="MsoNormal">Juan, many thanks again, I’ll study your
tests and learn from them.</p>
</div>
</blockquote>
<br>
I'm happy to be of help. There's not nothing in those tests that
could be new to you. All I did was to add nested method calls, and
add the #resume cases, that already did work with the fix. Let me
thank you. You did a great analysis of the issues at hand, and your
fix is a great contribution.<br>
<br>
I'll integrate it right now. If any further analysis provides
additional changes, we'll integrate them too.<br>
<o:p><br>
</o:p>
<blockquote
cite="mid:BN7PR08MB38422AE118D7EADA80DE7127EE5E9@BN7PR08MB3842.namprd08.prod.outlook.com"
type="cite">
<div class="WordSection1">
<p class="MsoNormal">Best regards,</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">jaromir</p>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</blockquote>
<br>
Cheers,<br>
<pre class="moz-signature" cols="72">--
Juan Vuletich
<a class="moz-txt-link-abbreviated" href="http://www.cuis-smalltalk.org">www.cuis-smalltalk.org</a>
<a class="moz-txt-link-freetext" href="https://github.com/Cuis-Smalltalk/Cuis-Smalltalk-Dev">https://github.com/Cuis-Smalltalk/Cuis-Smalltalk-Dev</a>
<a class="moz-txt-link-freetext" href="https://github.com/jvuletich">https://github.com/jvuletich</a>
<a class="moz-txt-link-freetext" href="https://www.linkedin.com/in/juan-vuletich-75611b3">https://www.linkedin.com/in/juan-vuletich-75611b3</a>
@JuanVuletich</pre>
</body>
</html>