Author nedbat
Recipients nedbat
Date 2019-07-05.03:02:39
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1562295759.87.0.390556054321.issue37500@roundup.psfhosted.org>
In-reply-to
Content
CPython 3.8.0b2 behaves differently than previous releases: it no longer optimizes away "if 0:" branches.  This is something that has been done since at least 2.4.  It was done in 3.8.0b1, but no longer is.

Was this a purposeful change? Why? It seems like 3.8 is adding more optimizations, why was this removed?

Test code (/tmp/no0.py):

import dis
import sys

print(sys.version)

def with_if_0():
    print(1)
    if 0:
        print(2)
    print(3)

dis.dis(with_if_0)


$ /usr/local/pythonz/pythons/CPython-3.8.0b2/bin/python3.8 /tmp/no0.py
3.8.0b2 (default, Jul  4 2019, 22:38:04)
[Clang 10.0.0 (clang-1000.10.44.4)]
  7           0 LOAD_GLOBAL              0 (print)
              2 LOAD_CONST               1 (1)
              4 CALL_FUNCTION            1
              6 POP_TOP

  8           8 LOAD_CONST               2 (0)
             10 POP_JUMP_IF_FALSE       20

  9          12 LOAD_GLOBAL              0 (print)
             14 LOAD_CONST               3 (2)
             16 CALL_FUNCTION            1
             18 POP_TOP

 10     >>   20 LOAD_GLOBAL              0 (print)
             22 LOAD_CONST               4 (3)
             24 CALL_FUNCTION            1
             26 POP_TOP
             28 LOAD_CONST               0 (None)
             30 RETURN_VALUE

$ /usr/local/pythonz/pythons/CPython-3.8.0b1/bin/python3.8 /tmp/no0.py
3.8.0b1 (default, Jun  4 2019, 21:21:14)
[Clang 10.0.0 (clang-1000.10.44.4)]
  7           0 LOAD_GLOBAL              0 (print)
              2 LOAD_CONST               1 (1)
              4 CALL_FUNCTION            1
              6 POP_TOP

 10           8 LOAD_GLOBAL              0 (print)
             10 LOAD_CONST               4 (3)
             12 CALL_FUNCTION            1
             14 POP_TOP
             16 LOAD_CONST               0 (None)
             18 RETURN_VALUE

$ python3.7 /tmp/no0.py
3.7.3 (default, Apr 10 2019, 10:27:53)
[Clang 10.0.0 (clang-1000.10.44.4)]
  7           0 LOAD_GLOBAL              0 (print)
              2 LOAD_CONST               1 (1)
              4 CALL_FUNCTION            1
              6 POP_TOP

 10           8 LOAD_GLOBAL              0 (print)
             10 LOAD_CONST               2 (3)
             12 CALL_FUNCTION            1
             14 POP_TOP
             16 LOAD_CONST               0 (None)
             18 RETURN_VALUE

$ python2.7 /tmp/no0.py
2.7.14 (default, Oct  4 2017, 09:45:53)
[GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.37)]
  7           0 LOAD_CONST               1 (1)
              3 PRINT_ITEM
              4 PRINT_NEWLINE

 10           5 LOAD_CONST               2 (3)
              8 PRINT_ITEM
              9 PRINT_NEWLINE
             10 LOAD_CONST               0 (None)
             13 RETURN_VALUE

$ python2.4 /tmp/no0.py
2.4.6 (#1, Jun 18 2016, 17:49:14)
[GCC 4.2.1 Compatible Apple LLVM 7.0.2 (clang-700.1.81)]
  7           0 LOAD_CONST               1 (1)
              3 PRINT_ITEM
              4 PRINT_NEWLINE

 10           5 LOAD_CONST               2 (3)
              8 PRINT_ITEM
              9 PRINT_NEWLINE
             10 LOAD_CONST               0 (None)
             13 RETURN_VALUE
History
Date User Action Args
2019-07-05 03:02:39nedbatsetrecipients: + nedbat
2019-07-05 03:02:39nedbatsetmessageid: <1562295759.87.0.390556054321.issue37500@roundup.psfhosted.org>
2019-07-05 03:02:39nedbatlinkissue37500 messages
2019-07-05 03:02:39nedbatcreate