Message325644
| Author |
Peter Ebden |
| Recipients |
Peter Ebden |
| Date |
2018年09月18日.13:53:47 |
| SpamBayes Score |
-1.0 |
| Marked as misclassified |
Yes |
| Message-id |
<1537278827.47.0.956365154283.issue34722@psf.upfronthosting.co.za> |
| In-reply-to |
| Content |
We've found that the following code produces non-deterministic bytecode,
even post PEP-552:
def test(x):
if x in {'ONE', 'TWO', 'THREE'}:
pass
It's not too hard to test it:
$ python3.7 -m compileall --invalidation-mode=unchecked-hash test.py
Compiling 'test.py'...
$ sha1sum __pycache__/test.cpython-37.pyc
61e5682ca95e8707b4ef2a79f64566664dafd800 __pycache__/test.cpython-37.pyc
$ rm __pycache__/test.cpython-37.pyc
$ python3.7 -m compileall --invalidation-mode=unchecked-hash test.py
Compiling 'test.py'...
$ sha1sum __pycache__/test.cpython-37.pyc
222a06621b491879e5317b34e9dd715bacd89b7d __pycache__/test.cpython-37.pyc
It looks like the peephole optimiser is converting the LOAD_CONST instructions
for the set into a single LOAD_CONST for a frozenset which then serialises in
nondeterministic order. One can hence work around it by setting PYTHONHASHSEED
to a known value.
I'm happy to help out with this if needed, although I don't have a lot of
familiarity with the relevant code. |
|
History
|
|---|
| Date |
User |
Action |
Args |
| 2018年09月18日 13:53:47 | Peter Ebden | set | recipients:
+ Peter Ebden |
| 2018年09月18日 13:53:47 | Peter Ebden | set | messageid: <1537278827.47.0.956365154283.issue34722@psf.upfronthosting.co.za> |
| 2018年09月18日 13:53:47 | Peter Ebden | link | issue34722 messages |
| 2018年09月18日 13:53:47 | Peter Ebden | create |
|