[Python-Dev] Generated Bytecode ...

Stéphane Wirtel stephane at wirtel.be
Thu Oct 22 13:05:53 EDT 2015


Thank you Brett,

I am going to read the source code, I am going to give a presentation at PyCon.IE about this part and I wanted to be sure about the dead branches.

Thanks

On 22 Oct 2015, at 19:02, Brett Cannon wrote:

> On Thu, 22 Oct 2015 at 09:37 Stéphane Wirtel <stephane at wirtel.be> wrote:
>
>> Hi all,
>>
>> When we compile a python script
>>
>> # test.py
>> if 0:
>>       x = 1
>>
>> python -mdis test.py
>>
>> There is no byte code for the condition.
>>
>> 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.
>
>
>>
>> What are the cases where the generator does not generate the byte codes ?
>>
>
> It's not specified anywhere; it's just what the peepholer decides to
> remove. The exact code can be found at
> https://hg.python.org/cpython/file/default/Python/peephole.c . There has
> been talk in the past for adding a -X flag to disable the peepholer, but it
> never went any farther beyond that.


--
Stéphane Wirtel - http://wirtel.be - @matrixise
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 801 bytes
Desc: OpenPGP digital signature
URL: <http://mail.python.org/pipermail/python-dev/attachments/20151022/5e2b7b2c/attachment.sig>


More information about the Python-Dev mailing list