[Python-Dev] JUMP_ABSOLUTE in nested if statements (original) (raw)

Victor Stinner victor.stinner at gmail.com
Sat Jun 18 18🔞42 EDT 2016


Python has a peephole optimizer which does not remove dead code that it just created.

Victor Le 18 juin 2016 23:14, "Obiesie ike-nwosu via Python-Dev" < python-dev at python.org> a écrit :

Hi,

Could some one give a hand with explaining to me why we have a JUMPABSOLUTE followed by a JUMPFORWARD op code when this function is disassembled. >>> def f1(): ... a, b = 10, 11 ... if a >= 10: ... if b >= 11: ... print("hello world") … The disassembled function is shown below. >>> dis(f1) 2 0 LOADCONST 4 ((10, 11)) 3 UNPACKSEQUENCE 2 6 STOREFAST 0 (a) 9 STOREFAST 1 (b) 3 12 LOADFAST 0 (a) 15 LOADCONST 1 (10) 18 COMPAREOP 5 (>=) 21 POPJUMPIFFALSE 47 4 24 LOADFAST 1 (b) 27 LOADCONST 2 (11) 30 COMPAREOP 5 (>=) 33 POPJUMPIFFALSE 47 5 36 LOADCONST 3 ('hello world') 39 PRINTITEM 40 PRINTNEWLINE 41 JUMPABSOLUTE 47 44 JUMPFORWARD 0 (to 47) >> 47 LOADCONST 0 (None) 50 RETURNVALUE From my understanding, once JUMPABSOLUTE is executed, then JUMPFORWARD is never gotten to so must be dead code so why is it being generated? Furthermore why is JUMPABSOLUTE rather than JUMPFORWARD used in this particular case of nested if statements? I have tried other types of nested if statements and it has always been JUMPFORWARD that is generated.


Python-Dev mailing list Python-Dev at python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/victor.stinner%40gmail.com -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-dev/attachments/20160619/338ec8a3/attachment.html>



More information about the Python-Dev mailing list