[Python-Dev] Generated Bytecode ... (original) (raw)

Stephane Wirtel stephane at wirtel.be
Sun Oct 25 16:10:39 EDT 2015


Thank you for your confirmation,

I am going to read the devguide.

On 25 oct. 2015, at 7:50 PM, Raymond Hettinger <raymond.hettinger at gmail.com> wrote:

On Oct 25, 2015, at 12:33 PM, Raymond Hettinger <raymond.hettinger at gmail.com> wrote:

On Oct 22, 2015, at 10:02 AM, Brett Cannon <brett at python.org> wrote: So my question is, the byte code generator removes the unused functions, variables etc…, is it right? Technically the peepholer removes the dead branch, but since the peepholer is run on all bytecode you can't avoid it. IIRC, the code was never generated in the first place (before the peephole pass). This used to be true before the AST branch was added and I think it may still be true. I just verified this. So Brett's post was incorrect and misleading. Raymond ----------- Verify by turning-off the optimizations ---------- cpython $ hg diff Python/peephole.c diff --git a/Python/peephole.c b/Python/peephole.c --- a/Python/peephole.c +++ b/Python/peephole.c @@ -383,7 +383,7 @@ /* Avoid situations where jump retargeting could overflow */ assert(PyBytesCheck(code)); codelen = PyBytesGETSIZE(code); - if (codelen > 32700) + if (codelen > 0) goto exitUnchanged; -------- Then run a simple disassembly ----------------------- from dis import dis def f(x): if 0: print('First') print('Second') dis(f) -------- The output is --------------------------------------------------- $ py tmp.py 6 0 LOADGLOBAL 0 (print) 3 LOADCONST 1 ('Second') 6 CALLFUNCTION 1 (1 positional, 0 keyword pair) 9 POPTOP 10 LOADCONST 0 (None) 13 RETURNVALUE



More information about the Python-Dev mailing list