Skip to content

bpo-42246: Don't eliminate jumps to jump, if it will break PEP 626. - #23896

Merged
markshannon merged 4 commits into
python:masterfrom
markshannon:fix-jump-to-jumps
Dec 23, 2020
Merged

markshannon merged 4 commits into
python:masterfrom
markshannon:fix-jump-to-jumps

Conversation

@markshannon

@markshannon markshannon commented Dec 22, 2020 •

Copy link
Copy Markdown
Member

Consider the following weird function:

def f(x):
    while True:
        if x:
            break
        continue

On master this produces the code:

  1     >>    0 NOP

  2           2 LOAD_FAST                0 (x)
              4 POP_JUMP_IF_FALSE        0

  3           6 LOAD_CONST               0 (None)
              8 RETURN_VALUE

which, when x is False will generate the trace 1, 2, 1, 2, 1, 2, ...

with this PR it produces the following correct, if slightly less efficient code:

  1     >>    0 NOP

  2           2 LOAD_FAST                0 (x)
              4 POP_JUMP_IF_FALSE       10

  3           6 LOAD_CONST               0 (None)
              8 RETURN_VALUE

  4     >>   10 JUMP_ABSOLUTE            0

which generates the correct trace 1, 2, 4, 1, 2, 4, 1, 2, 4, ...

When https://bugs.python.org/issue42719 is addressed we should be able to produce more efficient code.

https://bugs.python.org/issue42246

@markshannon
markshannon merged commit 28b75c8 into python:master Dec 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants