Author serhiy.storchaka
Recipients benjamin.peterson, brett.cannon, inada.naoki, ncoghlan, pitrou, rhettinger, serhiy.storchaka, yselivanov
Date 2019-03-07.15:44:58
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1551973498.92.0.934638258252.issue32477@roundup.psfhosted.org>
In-reply-to
Content
After analyzing the difference between bytecodes generated by the current peepholer and the new optimizer I have found that he peepholer do not optimizes jumps in case of some multiline expressions. For example:

[x
 for x in a if x]

  1           0 BUILD_LIST               0
              2 LOAD_FAST                0 (.0)
        >>    4 FOR_ITER                12 (to 18)

  2           6 STORE_FAST               1 (x)
              8 LOAD_FAST                1 (x)
             10 POP_JUMP_IF_FALSE       16

  1          12 LOAD_FAST                1 (x)
             14 LIST_APPEND              2
        >>   16 JUMP_ABSOLUTE            4
        >>   18 RETURN_VALUE

if x:
    if (y and
        z):
        foo()
else:
    bar()

  1           0 LOAD_NAME                0 (x)
              2 POP_JUMP_IF_FALSE       20

  2           4 LOAD_NAME                1 (y)
              6 POP_JUMP_IF_FALSE       18

  3           8 LOAD_NAME                2 (z)

  2          10 POP_JUMP_IF_FALSE       18

  4          12 LOAD_NAME                3 (foo)
             14 CALL_FUNCTION            0
             16 POP_TOP
        >>   18 JUMP_FORWARD             6 (to 26)

  6     >>   20 LOAD_NAME                4 (bar)
             22 CALL_FUNCTION            0
             24 POP_TOP
        >>   26 LOAD_CONST               0 (None)
             28 RETURN_VALUE

It preserves jumps to jump instructions. I do not know the cause. All works with single-line expressions.

The new optimizer does not have this bug.
History
Date User Action Args
2019-03-07 15:44:58serhiy.storchakasetrecipients: + serhiy.storchaka, brett.cannon, rhettinger, ncoghlan, pitrou, benjamin.peterson, inada.naoki, yselivanov
2019-03-07 15:44:58serhiy.storchakasetmessageid: <1551973498.92.0.934638258252.issue32477@roundup.psfhosted.org>
2019-03-07 15:44:58serhiy.storchakalinkissue32477 messages
2019-03-07 15:44:58serhiy.storchakacreate