This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Control flow not optimized
Type: performance Stage:
Components: Interpreter Core Versions: Python 2.5
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: benjamin.peterson, georg.brandl, quotemstr
Priority: normal Keywords:

Created on 2008-07-03 20:43 by quotemstr, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (3)
msg69230 - (view) Author: Daniel Colascione (quotemstr) Date: 2008-07-03 20:43
Consider:

import dis
def foo():
  if 0 and 1: return "hi"

dis.dis(foo)

What I get is 

  2           0 LOAD_CONST               1 (0)
              3 JUMP_IF_FALSE           15 (to 21)
              6 POP_TOP             
              7 LOAD_CONST               2 (1)
             10 JUMP_IF_FALSE            8 (to 21)
             13 POP_TOP             
             14 LOAD_CONST               3 ('hi')
             17 RETURN_VALUE        
             18 JUMP_FORWARD             1 (to 22)
        >>   21 POP_TOP             
        >>   22 LOAD_CONST               0 (None)
             25 RETURN_VALUE        

What I'd expect to see is:

  1           0 LOAD_CONST               0 (None)
              3 RETURN_VALUE
msg69231 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2008-07-03 20:51
A patch for this was just recently rejected. See #1394.
msg69248 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2008-07-04 09:05
What real-life use case do you have for a condition that is a boolean
operation on two constant values anyway? Things like

while 1:
   ...

are properly optimized since they serve a useful purpose.
History
Date User Action Args
2022-04-11 14:56:36adminsetgithub: 47525
2008-07-04 09:05:53georg.brandlsetnosy: + georg.brandl
messages: + msg69248
2008-07-03 20:51:29benjamin.petersonsetstatus: open -> closed
resolution: rejected
messages: + msg69231
nosy: + benjamin.peterson
2008-07-03 20:43:13quotemstrcreate