Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

bpo-47120: make JUMP_NO_INTERRUPT relative #32221

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 10 commits into from
Apr 5, 2022
Merged
Next Next commit
bpo-47120: replace JUMP_NO_INTERRUPT by the relative JUMP_BACKWARD_NO…
…_INTERRUPT
  • Loading branch information
iritkatriel committed Mar 31, 2022
commit d48b0266178ae47b13160fe90a3fa393366ccdbf
14 changes: 7 additions & 7 deletions 14 Doc/library/dis.rst
Original file line number Diff line number Diff line change
Expand Up @@ -902,6 +902,13 @@ iterations of the loop.
.. versionadded:: 3.11


.. opcode:: JUMP_BACKWARD_NO_INTERRUPT (delta)

Decrements bytecode counter by *delta*. Does not check for interrupts.

.. versionadded:: 3.11


.. opcode:: POP_JUMP_IF_TRUE (target)

If TOS is true, sets the bytecode counter to *target*. TOS is popped.
Expand Down Expand Up @@ -981,13 +988,6 @@ iterations of the loop.
.. versionadded:: 3.1


.. opcode:: JUMP_NO_INTERRUPT (target)

Set bytecode counter to *target*. Do not check for interrupts.

.. versionadded:: 3.11


.. opcode:: FOR_ITER (delta)

TOS is an :term:`iterator`. Call its :meth:`~iterator.__next__` method. If
Expand Down
6 changes: 3 additions & 3 deletions 6 Include/opcode.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion 4 Lib/importlib/_bootstrap_external.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,7 @@ def _write_atomic(path, data, mode=0o666):
# Python 3.11a6 3487 (Remove the adaptive "oparg counter" mechanism)
# Python 3.11a6 3488 (LOAD_GLOBAL can push additional NULL)
# Python 3.11a6 3489 (Add JUMP_BACKWARD, remove JUMP_ABSOLUTE)
# Python 3.11a6 3490 (Add JUMP_BACKWARD_NO_INTERRUPT, remove JUMP_NO_INTERRUPT)

# Python 3.12 will start with magic number 3500

Expand All @@ -411,7 +412,8 @@ def _write_atomic(path, data, mode=0o666):
# Whenever MAGIC_NUMBER is changed, the ranges in the magic_values array
# in PC/launcher.c must also be updated.

MAGIC_NUMBER = (3489).to_bytes(2, 'little') + b'\r\n'
MAGIC_NUMBER = (3490).to_bytes(2, 'little') + b'\r\n'

_RAW_MAGIC_NUMBER = int.from_bytes(MAGIC_NUMBER, 'little') # For import.c

_PYCACHE = '__pycache__'
Expand Down
2 changes: 1 addition & 1 deletion 2 Lib/opcode.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def jabs_op(name, op, entries=0):
def_op('GET_AWAITABLE', 131)
def_op('MAKE_FUNCTION', 132) # Flags
def_op('BUILD_SLICE', 133) # Number of items
jabs_op('JUMP_NO_INTERRUPT', 134) # Target byte offset from beginning of code
jrel_op('JUMP_BACKWARD_NO_INTERRUPT', 134) # Number of words to skip (backwards)
def_op('MAKE_CELL', 135)
hasfree.append(135)
def_op('LOAD_CLOSURE', 136)
Expand Down
3 changes: 2 additions & 1 deletion 3 Lib/test/test_dis.py
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,8 @@ def test_widths(self):
for opcode, opname in enumerate(dis.opname):
if opname in ('BUILD_MAP_UNPACK_WITH_CALL',
'BUILD_TUPLE_UNPACK_WITH_CALL',
'JUMP_IF_NOT_EXC_MATCH'):
'JUMP_IF_NOT_EXC_MATCH',
'JUMP_BACKWARD_NO_INTERRUPT'):
continue
with self.subTest(opname=opname):
width = dis._OPNAME_WIDTH
Expand Down
14 changes: 5 additions & 9 deletions 14 Objects/frameobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -237,15 +237,6 @@ mark_stacks(PyCodeObject *code_obj, int len)
stacks[i+1] = next_stack;
break;
}
case JUMP_NO_INTERRUPT:
j = get_arg(code, i);
assert(j < len);
if (stacks[j] == UNINITIALIZED && j < i) {
todo = 1;
}
assert(stacks[j] == UNINITIALIZED || stacks[j] == next_stack);
stacks[j] = next_stack;
break;
case POP_EXCEPT:
next_stack = pop_value(pop_value(pop_value(next_stack)));
stacks[i+1] = next_stack;
Expand All @@ -264,8 +255,13 @@ mark_stacks(PyCodeObject *code_obj, int len)
stacks[j] = next_stack;
break;
case JUMP_BACKWARD:
case JUMP_BACKWARD_NO_INTERRUPT:
j = i + 1 - get_arg(code, i);
assert(j >= 0);
assert(j < len);
if (stacks[j] == UNINITIALIZED && j < i) {
todo = 1;
}
assert(stacks[j] == UNINITIALIZED || stacks[j] == next_stack);
stacks[j] = next_stack;
break;
Expand Down
4 changes: 2 additions & 2 deletions 4 Python/ceval.c
Original file line number Diff line number Diff line change
Expand Up @@ -4058,13 +4058,13 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
DISPATCH();
}

TARGET(JUMP_NO_INTERRUPT) {
TARGET(JUMP_BACKWARD_NO_INTERRUPT) {
/* This bytecode is used in the `yield from` or `await` loop.
* If there is an interrupt, we want it handled in the innermost
* generator or coroutine, so we deliberately do not check it here.
* (see bpo-30039).
*/
JUMPTO(oparg);
JUMPBY(-oparg);
DISPATCH();
}

Expand Down
14 changes: 8 additions & 6 deletions 14 Python/compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -990,7 +990,7 @@ stack_effect(int opcode, int oparg, int jump)
case JUMP_FORWARD:
case JUMP_BACKWARD:
case JUMP:
case JUMP_NO_INTERRUPT:
case JUMP_BACKWARD_NO_INTERRUPT:
return 0;

case JUMP_IF_TRUE_OR_POP:
Expand Down Expand Up @@ -1891,7 +1891,7 @@ compiler_add_yield_from(struct compiler *c, int await)
compiler_use_next_block(c, resume);
ADDOP(c, YIELD_VALUE);
ADDOP_I(c, RESUME, await ? 3 : 2);
ADDOP_JUMP(c, JUMP_NO_INTERRUPT, start);
ADDOP_JUMP(c, JUMP_BACKWARD_NO_INTERRUPT, start);
compiler_use_next_block(c, exit);
return 1;
}
Expand Down Expand Up @@ -7051,7 +7051,7 @@ stackdepth(struct compiler *c)
depth = new_depth;
assert(instr->i_opcode != JUMP_FORWARD);
assert(instr->i_opcode != JUMP_BACKWARD);
if (instr->i_opcode == JUMP_NO_INTERRUPT ||
if (instr->i_opcode == JUMP_BACKWARD_NO_INTERRUPT ||
instr->i_opcode == JUMP ||
instr->i_opcode == RETURN_VALUE ||
instr->i_opcode == RAISE_VARARGS ||
Expand Down Expand Up @@ -7608,11 +7608,13 @@ assemble_jump_offsets(struct assembler *a, struct compiler *c)
instr->i_oparg = instr->i_target->b_offset;
if (is_relative_jump(instr)) {
if (instr->i_oparg < bsize) {
assert(instr->i_opcode == JUMP_BACKWARD);
assert(instr->i_opcode == JUMP_BACKWARD ||
instr->i_opcode == JUMP_BACKWARD_NO_INTERRUPT);
instr->i_oparg = bsize - instr->i_oparg;
}
else {
assert(instr->i_opcode != JUMP_BACKWARD);
assert(instr->i_opcode != JUMP_BACKWARD_NO_INTERRUPT);
instr->i_oparg -= bsize;
}
}
Expand Down Expand Up @@ -8951,7 +8953,7 @@ normalize_basic_block(basicblock *bb) {
bb->b_nofallthrough = 1;
break;
case JUMP:
case JUMP_NO_INTERRUPT:
case JUMP_BACKWARD_NO_INTERRUPT:
bb->b_nofallthrough = 1;
/* fall through */
case POP_JUMP_IF_NOT_NONE:
Expand Down Expand Up @@ -9138,7 +9140,7 @@ optimize_cfg(struct compiler *c, struct assembler *a, PyObject *consts)
assert(b_last_instr->i_opcode != JUMP_FORWARD);
assert(b_last_instr->i_opcode != JUMP_BACKWARD);
if (b_last_instr->i_opcode == JUMP ||
b_last_instr->i_opcode == JUMP_NO_INTERRUPT) {
b_last_instr->i_opcode == JUMP_BACKWARD_NO_INTERRUPT) {
if (b_last_instr->i_target == b->b_next) {
assert(b->b_next->b_iused);
b->b_nofallthrough = 0;
Expand Down
2 changes: 1 addition & 1 deletion 2 Python/opcode_targets.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Morty Proxy This is a proxified and sanitized view of the page, visit original site.