[squeak-dev] How to become immediate objects? :-)

Levente Uzonyi leves at caesar.elte.hu
Wed Apr 15 12:54:55 UTC 2020


Hi Jakob,

On Wed, 15 Apr 2020, Jakob Reschke wrote:

> Hi,
> The reason I read somewhere for the copyHash true default is that one would have to rehash collections that contain the involved objects if the hash did change.
> 
> Anything to be done in this regard of you change the default?

That is correct. If the identity hash is not copied over, then you have 
to rehash any hashed collection which
- holds the receiver of #becomeForward: (before the identity is 
forwarded), or the receiver or the argument of #become:
- derives the hash value from the objects' identity hash.

But the hash can't always be copied over, so it's a tough decision what 
the default should be:
- if the hash is not copied by default, the lack of rehashing will cause 
elements to be not found in the affected collections
- if the hash is copied, runtime errors will be raised when coping the 
hash is not possible.

Perhaps the best would be if before saving a method sending #become: or 
#becomeForward:, the code editor warned the user about the possible future 
consequences and suggested them to switch over to the #copyHash: 
variants.
There could also be lint rules covering these cases.


Levente

> 
> Kind regards,
> Jakob 
> 
> Marcel Taeumel <marcel.taeumel at hpi.de> schrieb am Mi., 15. Apr. 2020, 11:56:
>       Hi all!
> Thank you all for the clarification. Yes, please let's not copy the identity hash by default.
> 
> +1 on changing the default behind #becomeForward:
> 
> Best,
> Marcel
>
>       Am 15.04.2020 09:59:09 schrieb Levente Uzonyi <leves at caesar.elte.hu>:
>
>       Hi Chris,
>
>       On Tue, 14 Apr 2020, Chris Muller wrote:
>
>       > Hi Eliot,
>       >  
>       >
>       > Right.  A couple of questions are
>       > 1. what the f**k are become: becomeForward: becomeForward:copyHash: et al doing in ProtoObject?  (IMO, they should be in Object and have no business being in ProtoObject whatsoever).
>       >
>       >
>       > For Proxy's.  They don't typically inherit from Object, but must be able to become their normal object upon receiving a message it #doesNotUnderstand:.  Maybe you're implying those programs should be using
>       the mirror
>       > primitives, but those weren't always available, so hopefully that at least answers your question.
>
>       The primitives are defined on arrays. A proxy can and should always do
>
>       { self } elementsForwardIdentityTo: { proxiedObject }
>
>       So, that's not a reason to have those methods implemented by ProtoObject.
>
>       >
>       > 2. whether becomeForward: should do copyHash: true by default.  This seems wrong to me, and implementing is as copyHash: false makes more sense.  But I'm wondering if there are important use cases.
>       >
>       >
>       > Yes, changing the identityHash without changing the identity is basically "wrong", and even dangerous if it's a system Symbol used as keys in IdentityDictionary's like Environments, etc.
>       >
>       >    Object new becomeForward: #size   "do it = lock up your image"
>
>       The VM won't let you overwrite the Symbol's identityHash in current
>       Trunk, you'll get an error instead.
> 
>
>       Levente
>
>       >
>       >  - Chris
>       >
>       >
> 
> 
> 
>


More information about the Squeak-dev mailing list