Thank you for your confirmation, I am going to read the devguide.
> On 25 oct. 2015, at 7:50 PM, Raymond Hettinger <raymond.hettin...@gmail.com> > wrote: > > >>> On Oct 25, 2015, at 12:33 PM, Raymond Hettinger >>> <raymond.hettin...@gmail.com> wrote: >>> >>> On Oct 22, 2015, at 10:02 AM, Brett Cannon <br...@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(PyBytes_Check(code)); > codelen = PyBytes_GET_SIZE(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 LOAD_GLOBAL 0 (print) > 3 LOAD_CONST 1 ('Second') > 6 CALL_FUNCTION 1 (1 positional, 0 keyword pair) > 9 POP_TOP > 10 LOAD_CONST 0 (None) > 13 RETURN_VALUE > _______________________________________________ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com