[squeak-dev] Undeclared -> WeakIdentityDictionary -> wrong tally -> wrong #size

Levente Uzonyi leves at caesar.elte.hu
Wed Feb 26 14:44:33 UTC 2020


Hi Marcel,

On Wed, 26 Feb 2020, Marcel Taeumel wrote:

> Hi Levente,
> hmm... but WeakSet does also not respond correctly to #isEmpty. Yes, there is a bug with tally calculation as you descrined. However, all weak collections can only support #maybeNotEmpty and never #isEmpty (because of the false case).

Right, my response is more related to one of the previous emails of yours.
But, weak collections can and should respond to #isEmpty by using 
Collection's implementation.
However, due to the way weak references are handled, the response is not 
entirely reliable. IMO, it's the sender's responsibility to take care of 
the possibility of the changed state (#isEmpty returns false, but the last 
element is gone before the next message is processed by the VM).
Instead of overriding #isEmpty in all weak subclasses, we can handle 
it in HashedCollection if we want to:

isEmpty
 	"TODO: Add a nice comment here."

 	^array class isWeak
 		ifFalse: [ tally = 0 ]
 		ifTrue: [ super isEmpty ]


Levente

> 
> Best,
> Marcel
>
>       Am 26.02.2020 14:54:46 schrieb Levente Uzonyi <leves at caesar.elte.hu>:
>
>       Hi Marcel,
>
>       The cause of the problem is that unlike other weak hashed collections,
>       WeakIdentityDictionary does not recalculate tally in
>       #noCheckNoGrowFillFrom:. And that's a bug, because it lets tally increase
>       indefinitely.
>
>       The bug appears now, because before Undeclared became a
>       WeakIdentityDictionary, #compact, which is part of what ReleaseBuilder
>       does, would recalculate the tally via #noCheckNoGrowFillFrom:.
>
>       So, even for weak hashed collections, tally should never be larger than
>       the actual capacity (not #capacity, which currently implemented as array
>       size is a misnomer) of the collection.
> 
>
>       Levente
>
>       On Wed, 26 Feb 2020, marcel.taeumel wrote:
>
>       > Maybe weak collections should never claim to be empty anymore after any
>       > element was added to them? I would understand that since repeated calls can
>       > return different results.
>       >
>       > Best,
>       > Marcel
>       >
>       >
>       >
>       > --
>       > Sent from: http://forum.world.st/Squeak-Dev-f45488.html
> 
> 
>


More information about the Squeak-dev mailing list