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.

classification
Title: Make virtual opcodes in the compiler negative and is_jump() identify only proper jumps
Type: enhancement Stage: resolved
Components: Interpreter Core Versions: Python 3.11
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: iritkatriel Nosy List: Mark.Shannon, brandtbucher, iritkatriel
Priority: normal Keywords: patch

Created on 2022-03-30 17:28 by iritkatriel, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 32200 merged iritkatriel, 2022-03-30 17:37
Messages (2)
msg416386 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2022-03-30 17:28
There are a few "virtual opcodes" which are internal to the compiler. They can have values > 256. This way we don't waste any valid opcodes on them, and it is easier to detect when one of them escapes the compiler into the assemble stage.

In addition, there is an is_jump() function that treats the exception handling opcodes as jumps (and also assumes that any opcode >= SETUP_WITH is a jump):

static inline int
 is_jump(struct instr *i)
 {
    return i->i_opcode >= SETUP_WITH || is_bit_set_in_table(_PyOpcode_Jump, i->i_opcode);
 }

Then there is is_block_push just for the three virtual exception block opcodes:

static inline int
is_block_push(struct instr *instr)
{
    int opcode = instr->i_opcode;
    return opcode == SETUP_FINALLY || opcode == SETUP_WITH || opcode == SETUP_CLEANUP;
}

We can make is_jump return true just for jumps, and call is_block_push as well when it is needed (currently sometimes we call is_jump when there cannot be virtual opcodes anymore so we can assert that instead, and in one place we call is_jump and then exclude the virtual opcodes. Both of these will become clearer after we make this change).
msg416490 - (view) Author: Mark Shannon (Mark.Shannon) * (Python committer) Date: 2022-04-01 14:50
New changeset 997ba5d126f5040d5b7536f73bc89049e9f9421d by Irit Katriel in branch 'main':
bpo-47172: Compiler enhancements (GH-32200)
https://github.com/python/cpython/commit/997ba5d126f5040d5b7536f73bc89049e9f9421d
History
Date User Action Args
2022-04-11 14:59:57adminsetgithub: 91328
2022-04-01 14:52:14iritkatrielsetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2022-04-01 14:50:27Mark.Shannonsetnosy: + Mark.Shannon
messages: + msg416490
2022-03-31 17:14:51iritkatrielsettitle: Make virtual opcodes in the compiler > 256 and is_jump() identify only proper jumps -> Make virtual opcodes in the compiler negative and is_jump() identify only proper jumps
2022-03-30 17:57:35brandtbuchersetnosy: + brandtbucher
2022-03-30 17:37:14iritkatrielsetkeywords: + patch
stage: patch review
pull_requests: + pull_request30277
2022-03-30 17:28:54iritkatrielcreate