develooper Front page | perl.perl5.porters | Postings from August 2020

Re: PERL_PERTURB_KEYS=2 (solved)

Thread Previous | Thread Next
From:
hv
Date:
August 1, 2020 04:21
Subject:
Re: PERL_PERTURB_KEYS=2 (solved)
Message ID:
202008010339.0713dFP16284@crypt.org
Earler I wrote:
:Below is as short as I've got it so far.

It's shorter now:

#!/opt/v5.32.0-d/bin/perl
use strict ();
my $dict = [ {} ];
{
    my %tr = map +($_ => 1), ([], []);
}
$dict->[0]{'a'} = 1;
$dict->[0]{'b'} = 1;
print keys %{ $dict->[0] };
__END__

To test, expect "ab 100" or "ba 100" for a hash seed if it is
deterministic:

% PERL_PERTURB_KEYS=2 perl -wle '
  for my $h (1 .. 10) {
    local $ENV{PERL_HASH_SEED} = $h;
    %s = ();
    ++$s{`./axiom`} for 1 .. 100;
    print "$h: ", join(" ", map "$_ $s{$_}", sort keys %s);
  }
'
1: ab 100
2: ab 100
3: ba 100
4: ab 9 ba 91
5: ab 6 ba 94
6: ba 100
7: ab 10 ba 90
8: ab 100
9: ab 5 ba 95
10: ab 100
% 

In my original post I asked:
:Before I dig further to try and cut down the larger application to a
:test case, does anyone have suggestions as to:
:- what other (non-obvious) non-deterministic behaviour I might have?
:[...]

So I now have the answer: I'm constructing hash keys as stringified
references, and somehow even an invocation as simple as 'use strict ()'
introduces enough non-determinism into _memory addresses_ that those
hash keys can vary. And that seems to be enough to change the course
for later key ordering under DETERMINISTIC.

I don't know whether that's a flaw in DETERMINISTIC or simply something
we have to caveat; certainly it makes it a lot less useful to me, since
stringified references as hash keys is something I use very regularly.

Hugo

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About