Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 23, 2020

Conversation

markshannon
Copy link
Member

@markshannon markshannon commented Dec 22, 2020

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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants