[Cuis-dev] Code duplication around unwinding

Jaromir Matas mail at jaromir.net
Fri Feb 24 14:16:51 PST 2023


Hi Juan,

this is the latest Squeak trunk version replacing all duplicate unwind code with #unwindTo:safely: (sent already as part of the other changeset with #terminate).

The modified version of #unwindTo: just adds a Boolean distinguishing between the "old" unwind semantics, i.e. only evaluating unwind blocks that haven't started executing yet, and the "new" unwind semantics applied in #terminate (safely: true enables the new semantics).

As a bonus we can experiment with setting safely: true even for "normal" returns, extending the unwind semantics for non-local returns and exceptions. It's more or less working but haven't been tested properly so this is my project for later this year :)

Best regards,

Jaromir


--

Jaromír Matas

mail at jaromir.net


From: Jaromir Matas via Cuis-dev<mailto:cuis-dev at lists.cuis.st>
Sent: Friday, February 24, 2023 12:50
To: Juan Vuletich<mailto:juan at cuis.st>; Discussion of Cuis Smalltalk<mailto:cuis-dev at lists.cuis.st>
Cc: Jaromir Matas<mailto:mail at jaromir.net>; Hernán Wilkinson<mailto:hernan.wilkinson at 10pines.com>
Subject: Re: [Cuis-dev] Code duplication around unwinding

Hi Juan,

> I think this is a good idea, and I agree with the desire to go back to the older Squeak design. However, I don't know why it was made more complicated. It would be good to understand the rationale behind those changes, unless we can be sure that the behavior is identical.

Precisely, I'm trying to understand *why* the changes were made first. I hoped you might remember something :) No feedback from Squeak, the authors behind the rewrite are probably no longer following the forum. However, I've made the first step in Squeak and replaced the duplicate code with unwindTo: because it very much looks like a copy/paste issue as Hernan suggested :) All tests work fine and the semantics is identical as before. It's in Squeak trunk and so far no problems reported. I'll send you the same cleaned up version as in Squeak.

As part of the effort I discussed the purpose of ContextPart #terminateTo: method that's being used in #resume{...] methods as part of the unwind procedure. My conclusion is we *must* use #terminateTo because a similar code is used inside the VM to process non-local returns without any unwind blocks present. The real rationale behind the #terminateTo code however, is to prevent any contexts that were "returned over" from being run in the future, as a precaution. Here's a link if interested: http://lists.squeakfoundation.org/pipermail/squeak-dev/2023-February/223500.html

As for the idea to reverse the exceptions design back to the original I tried it and it works fine but the current code looks cleaner which might be one of the reasons behind the rewrite. I'll keep thinking about it but will leave this for later. So, please don't waste any time with this idea yet :)

Many thanks,
Best,
Jaromir


--

Jaromír Matas

mail at jaromir.net


From: Juan Vuletich<mailto:juan at cuis.st>
Sent: Friday, February 24, 2023 12:01
To: Discussion of Cuis Smalltalk<mailto:cuis-dev at lists.cuis.st>
Cc: Hernán Wilkinson<mailto:hernan.wilkinson at 10pines.com>; Jaromir Matas<mailto:mail at jaromir.net>
Subject: Re: [Cuis-dev] Code duplication around unwinding

Hi Jaromir,

I think this is a good idea, and I agree with the desire to go back to the older Squeak design. However, I don't know why it was made more complicated. It would be good to understand the rationale behind those changes, unless we can be sure that the behavior is identical.

Did you get any relevant feedback from the Squeak list? Maybe someone who is aware of the history of these changes is still available to tell.

If not, I can spend a little more time and try to do a proper review of the changes myself, although, as you know, this is a bit beyond my comfort zone!

Thanks!

On 2/2/2023 3:28 PM, Jaromir Matas via Cuis-dev wrote:
Hi Hernán,

Thanks for your message!

> I'll take a look at the code you sent but I prefer for Juan to return to integrate it

… of course, there’s no rush, the duplication has been around for 20 years :D

Most of all, I’m interested in your opinions. As an example, I find this call sequence desperately begging for simplification:

Exception>>resume: --> resumeUnchecked: --> resumeEvaluating: --> Context>>returnEvaluating: --> resumeEvaluating:

I mean: in order to resume from an exception you have to traverse four other methods rather than just getting it done in Exception>>resume: as was originally implemented in Squeak 2.8 through 3.5. My aim is to get back to this design - unless I’ve missed some fundamental reason why not to. Any feedback *very* welcome.

Thanks again,


--

Jaromír Matas

mail at jaromir.net<mailto:mail at jaromir.net>


From: Hernán Wilkinson<mailto:hernan.wilkinson at 10pines.com>
Sent: Thursday, February 2, 2023 19:00
To: Discussion of Cuis Smalltalk<mailto:cuis-dev at lists.cuis.st>
Cc: juan at cuis.st<mailto:juan at cuis.st>; Jaromir Matas<mailto:mail at jaromir.net>
Subject: Re: [Cuis-dev] Code duplication around unwinding

Hi Jaromir,
 thank you for this proposal!
 Juan is on vacation, deserved vacations :-)
 I'll take a look at the code you sent but I prefer for Juan to return to integrate it because he was more involved in the changes you sent.

 About the reason of the duplication of code you see the answer could be really simple: copy & paste!!! :-)
 I also sometimes spend time trying to understand why the code is duplicated and most of the time it is just that, copy & paste without any intention or knowledge to do it better. I mean, usually it is a human reason, not a technical one.

Cheers!
Hernan.

On Thu, Feb 2, 2023 at 1:38 PM Jaromir Matas via Cuis-dev <cuis-dev at lists.cuis.st<mailto:cuis-dev at lists.cuis.st>> wrote:
Hi Juan,

I'm enclosing a changeset for your review. I've just sent a similar suggestion to Squeak list hoping to get some feedback.

The aim is to reduce the code duplication in ContextPart>>#restart, #resume:through:, #resumeEvaluating: methods that are implementing the same unwind mechanism we already have in unwindTo:. I've always wondered why the same algorithm is duplicated so many times (it used to be in terminate too!) but never really found out.

At the same time this code duplication was introduced in Squeak 3.6, the unwind mechanism was moved from the Exception class to ContextPart and, but this is just my hypothesis, never cleaned up properly.

I'd be very thankful for your thoughts and your opinion about the enclosed changeset.

Many thanks,

Jaromir


--

Jaromír Matas

mail at jaromir.net<mailto:mail at jaromir.net>


--
Cuis-dev mailing list
Cuis-dev at lists.cuis.st<mailto:Cuis-dev at lists.cuis.st>
https://lists.cuis.st/mailman/listinfo/cuis-dev


--
Hernán Wilkinson
Agile Software Development, Teaching & Coaching
Phone: +54-011-4893-2057
Twitter: @HernanWilkinson
site: http://www.10Pines.com<http://www.10pines.com/>
Address: Alem 896, Floor 6, Buenos Aires, Argentina




--

Juan Vuletich

cuis.st

github.com/jvuletich

researchgate.net/profile/Juan-Vuletich

independent.academia.edu/JuanVuletich

patents.justia.com/inventor/juan-manuel-vuletich

linkedin.com/in/juan-vuletich-75611b3

twitter.com/JuanVuletich


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cuis.st/mailman/archives/cuis-dev/attachments/20230224/eb7d25c8/attachment-0001.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 5669-CuisCore-unwind-duplicity-JaromirMatas-jar.001.cs.st
Type: application/octet-stream
Size: 1465 bytes
Desc: 5669-CuisCore-unwind-duplicity-JaromirMatas-jar.001.cs.st
URL: <http://lists.cuis.st/mailman/archives/cuis-dev/attachments/20230224/eb7d25c8/attachment-0001.obj>


More information about the Cuis-dev mailing list