[squeak-dev] #deepCopy seems broken for IdentitySet
Rein, Patrick
Patrick.Rein at hpi.de
Sat Mar 4 10:00:39 UTC 2023
Hi Stef,
potentially interesting sidenote: #veryDeepCopy works correctly because it forces a rehash (see Object>>#veryDeepCopyWith: at the bottom).
Cheers,
Patrick
________________________________________
From: Squeak-dev <squeak-dev-bounces at lists.squeakfoundation.org> on behalf of Stéphane Rollandin <lecteur at zogotounga.net>
Sent: Friday, March 3, 2023 4:39:43 PM
To: liste [Squeak-dev]
Subject: [squeak-dev] #deepCopy seems broken for IdentitySet
Hello all,
After spending way too long on a bug in my code, I found the culprit to
be that deep-copying an IdentitySet is not reliable. The copy may need a
#rehash.
To see this, do
iset := {1 at 1} asIdentitySet.
results := Set new.
100 timesRepeat: [
dcset := iset deepCopy.
results add: (dcset includes: dcset anyOne)].
results "explore it"
This should show both true and false in results.
The proportion is about 2/3 false, which seems to correspond to the
probability that #scanFor: will return a wrong index for a set of one
element that needs a rehash, since
{1 at 1} asIdentitySet array
may be either one of
{nil . nil . 1 at 1}
{nil . 1 at 1 . nil}
{1 at 1 . nil . nil}
This behavior has been there for ages though - so, am I missing something?
Stef
More information about the Squeak-dev
mailing list
|