[New-bugs-announce] [issue15368] bytecode generation is not deterministic
Meador Inge
report at bugs.python.org
Mon Jul 16 14:52:36 CEST 2012
New submission from Meador Inge <meadori at gmail.com>:
Consider this small example (you might have to run sample program multiple
times to see a difference):
$ cat dis-closure.py
import dis
def adder(a, b):
def add():
return a + b
return add
print(dis.dis(adder(1, 2).__code__))
$ ./python.exe dis-closure.py
5 0 LOAD_DEREF 0 (a)
3 LOAD_DEREF 1 (b)
6 BINARY_ADD
7 RETURN_VALUE
None
$ ./python.exe dis-closure.py
5 0 LOAD_DEREF 1 (a)
3 LOAD_DEREF 0 (b)
6 BINARY_ADD
7 RETURN_VALUE
None
The order of 'co_cellvars' and 'co_freevars' can be different from compile to
compile, thus the bytecode can be different from compile to compile.
This is due to the fact that these variable sets are managed with hashes and
the ordering may come out different when the names in the hashes are given
indexes (via 'dictbytype' in 'compile.c').
I am not sure if these are the only areas that causes bytecode generation
to be non-deterministic. I found this behavior surprising.
----------
components: Interpreter Core
messages: 165596
nosy: meador.inge
priority: normal
severity: normal
stage: needs patch
status: open
title: bytecode generation is not deterministic
type: behavior
versions: Python 3.3
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue15368>
_______________________________________
More information about the New-bugs-announce
mailing list