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.

Title: Compiler hangs during jump elimination
Type: behavior Stage: resolved
Components: Interpreter Core Versions: Python 3.11
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: brandtbucher Nosy List: Mark.Shannon, brandtbucher, miss-islington, pablogsal
Priority: Keywords: patch

Created on 2021-11-09 19:56 by brandtbucher, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 29505 merged brandtbucher, 2021-11-09 21:13
PR 29526 merged brandtbucher, 2021-11-11 19:51
PR 31066 merged brandtbucher, 2022-02-01 23:13
PR 31101 merged miss-islington, 2022-02-03 15:29
Messages (6)
msg406046 - (view) Author: Brandt Bucher (brandtbucher) * (Python committer) Date: 2021-11-09 19:56
The following code hangs during compilation on 3.11 and 3.10:

>>> while True or spam: pass

Our peepholer gets stuck in a loop, repeatedly "optimizing" instruction 4 (POP_JUMP_IF_TRUE -> JUMP_ABSOLUTE):

  1           0 JUMP_ABSOLUTE            0 (to 0)
              2 LOAD_NAME                0 (spam)
              4 POP_JUMP_IF_TRUE         0 (to 0)

After optimizing jumps to jumps like these, we always back up and attempt to optimize the same instruction again (which makes it possible to optimize three or more chained jumps on the same line). The issue is that this particular optimization doesn't actually change the instruction, since both jumps target the same exact block. Since nothing changes, we loop forever.

The fix is really simple: just skip the optimization if instr->i_target == target->i_target. We already do this for several other types of jumps; it just looks like POP_JUMP_IF_TRUE and POP_JUMP_IF_FALSE might have been missed.

I'll have a PR up soon.
msg406174 - (view) Author: Brandt Bucher (brandtbucher) * (Python committer) Date: 2021-11-11 19:44
New changeset 27b69e60daa7b191ee6bc76fb6d5fb7d793062ab by Brandt Bucher in branch 'main':
bpo-45773: Stop "optimizing" certain jump patterns (GH-29505)
msg406179 - (view) Author: Brandt Bucher (brandtbucher) * (Python committer) Date: 2021-11-11 21:52
New changeset a89bbde83fe7f8cc347341e7ec57cda3ba312530 by Brandt Bucher in branch '3.10':
[3.10] bpo-45773: Stop "optimizing" certain jump patterns (GH-29526)
msg412318 - (view) Author: Brandt Bucher (brandtbucher) * (Python committer) Date: 2022-02-01 23:13
My fix for this seems to have erroneously added two invalid new jump threads:


The good news is that I can't get the compiler to actually emit these particular jump sequences. It still needs to be fixed ASAP, though.
msg412433 - (view) Author: Mark Shannon (Mark.Shannon) * (Python committer) Date: 2022-02-03 10:14
New changeset e0433c1e70254d4d0357a9e14596929a04bdf769 by Brandt Bucher in branch 'main':
bpo-45773: Remove invalid peephole optimizations (GH-31066)
msg412447 - (view) Author: miss-islington (miss-islington) Date: 2022-02-03 15:54
New changeset ff6948b1286c854ee77dfc0b23b9d828b36873e4 by Miss Islington (bot) in branch '3.10':
bpo-45773: Remove invalid peephole optimizations (GH-31066)
Date User Action Args
2022-04-11 14:59:52adminsetgithub: 89931
2022-02-03 16:04:53brandtbuchersetpriority: release blocker ->
status: open -> closed
resolution: fixed
stage: patch review -> resolved
2022-02-03 15:54:59miss-islingtonsetmessages: + msg412447
2022-02-03 15:29:01miss-islingtonsetnosy: + miss-islington
pull_requests: + pull_request29284
2022-02-03 10:14:48Mark.Shannonsetmessages: + msg412433
2022-02-01 23:13:54brandtbuchersetpull_requests: + pull_request29251
2022-02-01 23:13:36brandtbuchersetstatus: closed -> open
priority: high -> release blocker
type: crash -> behavior

nosy: + pablogsal
messages: + msg412318
resolution: fixed -> (no value)
stage: resolved -> patch review
2021-12-10 09:39:14iritkatrielsetstatus: pending -> closed
2021-11-13 15:46:18brandtbuchersetstatus: open -> pending
resolution: fixed
stage: patch review -> resolved
2021-11-11 21:52:53brandtbuchersetmessages: + msg406179
2021-11-11 19:51:33brandtbuchersetpull_requests: + pull_request27776
2021-11-11 19:44:39brandtbuchersetmessages: + msg406174
2021-11-09 21:13:45brandtbuchersetkeywords: + patch
stage: patch review
pull_requests: + pull_request27756
2021-11-09 19:56:22brandtbuchercreate