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

bpo-42246: Don't eliminate jumps to jump, if it will break PEP 626.#23896
markshannon merged 4 commits into
python:masterfrom
markshannon:fix-jump-to-jumps

Conversation

@markshannon

@markshannonmarkshannon commented Dec 22, 2020

Copy link
Copy Markdown
Member

Consider the following weird function:

deff(x):
whileTrue:
ifx:
breakcontinue

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

Sign up for freeto 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

@markshannon@the-knights-who-say-ni@bedevere-bot