pony icon indicating copy to clipboard operation
pony copied to clipboard

handle POP_JUMP_IF_NONE, POP_JUMP_IF_NOT_NONE

Open nburns opened this issue 10 months ago • 4 comments

fixes issues with POP_JUMP_IF_NONE, and POP_JUMP_IF_NOT_NONE that happen in python 3.12:

  • https://github.com/ponyorm/pony/issues/702
  • https://github.com/ponyorm/pony/issues/725

previously when queries contain if _ is None or if _ is not None a decompiling error would be raised

nburns avatar Feb 20 '25 23:02 nburns

@kozlovsky thanks for upgrading to support 3.12, I think this fixes some of the issues that we're having with python 3.12 (missed opcodes?) was hoping you'd be able to take a look

nburns avatar Feb 20 '25 23:02 nburns

ran into some issues with the changes to support python 3.12: https://github.com/ponyorm/pony/pull/741/files#diff-6161515a22afc5b06c02f3c115043d3676eb49a9285a6e8251a053aa30e97832R243-R262

nburns avatar Feb 25 '25 18:02 nburns

Hello! Thanks for your work. I'll take it for the test and come back as soon as possible.

sashaaero avatar Apr 09 '25 18:04 sashaaero

Just incase it helps, I found that python will return different bytecode with newlines (tripped me up pretty hard with those tests)

source = """(m
    for m in []
    if (x is None or y))"""

In [8]: dis.dis(compile(re.sub("\n", "", source), "", "eval"))
  0           0 RESUME                   0

  1           2 LOAD_CONST               0 (<code object <genexpr> at 0x103175e30, file "", line 1>)
              4 MAKE_FUNCTION            0
              6 LOAD_CONST               1 (())
              8 GET_ITER
             10 CALL                     0
             18 RETURN_VALUE

Disassembly of <code object <genexpr> at 0x103175e30, file "", line 1>:
  1           0 RETURN_GENERATOR
              2 POP_TOP
              4 RESUME                   0
              6 LOAD_FAST                0 (.0)
        >>    8 FOR_ITER                19 (to 50)
             12 STORE_FAST               1 (m)
             14 LOAD_GLOBAL              0 (x)
             24 POP_JUMP_IF_NONE         7 (to 40)
             26 LOAD_GLOBAL              2 (y)
             36 POP_JUMP_IF_TRUE         1 (to 40)
             38 JUMP_BACKWARD           16 (to 8)
        >>   40 LOAD_FAST                1 (m)
             42 YIELD_VALUE              1
             44 RESUME                   1
             46 POP_TOP
             48 JUMP_BACKWARD           21 (to 8)
        >>   50 END_FOR
             52 RETURN_CONST             0 (None)
        >>   54 CALL_INTRINSIC_1         3 (INTRINSIC_STOPITERATION_ERROR)
             56 RERAISE                  1
ExceptionTable:
  4 to 36 -> 54 [0] lasti
  40 to 52 -> 54 [0] lasti

In [9]: dis.dis(compile(source, "", "eval"))
  0           0 RESUME                   0

  1           2 LOAD_CONST               0 (<code object <genexpr> at 0x1030abc30, file "", line 1>)
              4 MAKE_FUNCTION            0

  2           6 LOAD_CONST               1 (())
              8 GET_ITER

  1          10 CALL                     0
             18 RETURN_VALUE

Disassembly of <code object <genexpr> at 0x1030abc30, file "", line 1>:
  1           0 RETURN_GENERATOR
              2 POP_TOP
              4 RESUME                   0
              6 LOAD_FAST                0 (.0)

  2     >>    8 FOR_ITER                18 (to 48)
             12 STORE_FAST               1 (m)

  3          14 LOAD_GLOBAL              0 (x)
             24 POP_JUMP_IF_NONE         6 (to 38)
             26 LOAD_GLOBAL              2 (y)
             36 POP_JUMP_IF_FALSE        4 (to 46)

  1     >>   38 LOAD_FAST                1 (m)
             40 YIELD_VALUE              1
             42 RESUME                   1
             44 POP_TOP
        >>   46 JUMP_BACKWARD           20 (to 8)

  2     >>   48 END_FOR
             50 RETURN_CONST             0 (None)
        >>   52 CALL_INTRINSIC_1         3 (INTRINSIC_STOPITERATION_ERROR)
             54 RERAISE                  1
ExceptionTable:
  4 to 50 -> 52 [0] lasti

nburns avatar Apr 09 '25 18:04 nburns

Sorry for long response. I just found I made same changes in my 3.13 support branch so I thought I would merge this altogether.

sashaaero avatar Jul 03 '25 18:07 sashaaero