A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://mail.python.org/pipermail/python-dev/2015-October/142028.html below:

[Python-Dev] Generated Bytecode ...

[Python-Dev] Generated Bytecode ...Raymond Hettinger raymond.hettinger at gmail.com
Sun Oct 25 15:50:40 EDT 2015
> 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(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

More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4