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.

Author pablogsal
Recipients pablogsal, scoder, serhiy.storchaka, tcaswell, vstinner
Date 2019-06-15.15:20:39
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1560612040.29.0.311538230651.issue37289@roundup.psfhosted.org>
In-reply-to
Content
Serhiy, this is the code that was incorrectly optimized:

  3           0 LOAD_GLOBAL              0 (g)
              2 LOAD_ATTR                1 (__code__)
              4 POP_JUMP_IF_FALSE        8
              6 JUMP_FORWARD             4 (to 12)
        >>    8 LOAD_CONST               0 (None)
             10 POP_JUMP_IF_FALSE       20

  4     >>   12 LOAD_GLOBAL              2 (print)
             14 LOAD_CONST               2 ('Called!')
             16 CALL_FUNCTION            1
             18 POP_TOP
        >>   20 LOAD_CONST               0 (None)
             22 RETURN_VALUE

def g():
    if True if g.__code__ else None:
        print("Called!")

g()

The problem is that [LOAD_CONST               0 (None)] made the peephole to delete the block because it does not detect that previous conditions in the same conditional could be True. The general case was made by looking back for POP_JUMP_IF_{FALSE,TRUE} but with this construct JUMP_FORWARD appears.

I think handling this condition in the peephole optimizer can be very dangerous error prone to get right because all the information is lost, but doing it at the ast level makes us lose syntax errors in optimized blocks, which is also wrong. Any ideas?

It happens here in Cython:

https://github.com/cython/cython/blob/master/Cython/Compiler/Nodes.py#L5131

That's why the errors manifest as pickling errors
History
Date User Action Args
2019-06-15 15:20:40pablogsalsetrecipients: + pablogsal, scoder, vstinner, serhiy.storchaka, tcaswell
2019-06-15 15:20:40pablogsalsetmessageid: <1560612040.29.0.311538230651.issue37289@roundup.psfhosted.org>
2019-06-15 15:20:40pablogsallinkissue37289 messages
2019-06-15 15:20:39pablogsalcreate