10000 gh-102859: remove opcodes JUMP_IF_FALSE_OR_POP and JUMP_IF_TRUE_OR_POP · iritkatriel/cpython@1e63ce0 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1e63ce0

Browse files
committed
pythongh-102859: remove opcodes JUMP_IF_FALSE_OR_POP and JUMP_IF_TRUE_OR_POP
1 parent ef000eb commit 1e63ce0

File tree

13 files changed

+156
-409
lines changed

13 files changed

+156
-409
lines changed

Doc/library/dis.rst

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1152,30 +1152,6 @@ iterations of the loop.
11521152
.. versionchanged:: 3.12
11531153
This is no longer a pseudo-instruction.
11541154

1155-
1156-
.. opcode:: JUMP_IF_TRUE_OR_POP (delta)
1157-
1158-
If ``STACK[-1]`` is true, increments the bytecode counter by *delta* and leaves
1159-
``STACK[-1]`` on the stack. Otherwise (``STACK[-1]`` is false), ``STACK[-1]``
1160-
is popped.
1161-
1162-
.. versionadded:: 3.1
1163-
1164-
.. versionchanged:: 3.11
1165-
The oparg is now a relative delta rather than an absolute target.
1166-
1167-
.. opcode:: JUMP_IF_FALSE_OR_POP (delta)
1168-
1169-
If ``STACK[-1]`` is false, increments the bytecode counter by *delta* and leaves
1170-
``STACK[-1]`` on the stack. Otherwise (``STACK[-1]`` is true), ``STACK[-1]`` is
1171-
popped.
1172-
1173-
.. versionadded:: 3.1
1174-
1175-
.. versionchanged:: 3.11
1176-
The oparg is now a relative delta rather than an absolute target.
1177-
1178-
11791155
.. opcode:: FOR_ITER (delta)
11801156

11811157
``STACK[-1]`` is an :term:`iterator`. Call its :meth:`~iterator.__next__` method.

Doc/whatsnew/3.12.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,9 @@ CPython bytecode changes
434434
:opcode:`LOAD_METHOD` instruction if the low bit of its oparg is set.
435435
(Contributed by Ken Jin in :gh:`93429`.)
436436

437+
* Removed the :opcode:`JUMP_IF_FALSE_OR_POP` and :opcode:`JUMP_IF_TRUE_OR_POP`
438+
instructions. (Contributed by Irit Katriel in :gh:`102859`.)
439+
437440

438441
Demos and Tools
439442
===============

Include/internal/pycore_opcode.h

Lines changed: 11 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/opcode.h

Lines changed: 8 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Lib/importlib/_bootstrap_external.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,7 @@ def _write_atomic(path, data, mode=0o666):
435435
# Python 3.12a6 3519 (Modify SEND instruction)
436436
# Python 3.12a6 3520 (Remove PREP_RERAISE_STAR, add CALL_INTRINSIC_2)
437437
# Python 3.12a7 3521 (Shrink the LOAD_GLOBAL caches)
438+
# Python 3.12a7 3522 (Removed JUMP_IF_FALSE_OR_POP/JUMP_IF_TRUE_OR_POP)
438439

439440
# Python 3.13 will start with 3550
440441

@@ -451,7 +452,7 @@ def _write_atomic(path, data, mode=0o666):
451452
# Whenever MAGIC_NUMBER is changed, the ranges in the magic_values array
452453
# in PC/launcher.c must also be updated.
453454

454-
MAGIC_NUMBER = (3521).to_bytes(2, 'little') + b'\r\n'
455+
MAGIC_NUMBER = (3522).to_bytes(2, 'little') + b'\r\n'
455456

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

Lib/opcode.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,6 @@ def pseudo_op(name, op, real_ops):
154154
name_op('IMPORT_NAME', 108) # Index in name list
155155
name_op('IMPORT_FROM', 109) # Index in name list
156156
jrel_op('JUMP_FORWARD', 110) # Number of words to skip
157-
jrel_op('JUMP_IF_FALSE_OR_POP', 111) # Number of words to skip
158-
jrel_op('JUMP_IF_TRUE_OR_POP', 112) # ""
159157
jrel_op('POP_JUMP_IF_FALSE', 114)
160158
jrel_op('POP_JUMP_IF_TRUE', 115)
161159
name_op('LOAD_GLOBAL', 116) # Index in name list

Lib/test/test__opcode.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,6 @@ def test_stack_effect(self):
3434
self.assertRaises(ValueError, stack_effect, code, 0)
3535

3636
def test_stack_effect_jump(self):
37-
JUMP_IF_TRUE_OR_POP = dis.opmap['JUMP_IF_TRUE_OR_POP']
38-
self.assertEqual(stack_effect(JUMP_IF_TRUE_OR_POP, 0), 0)
39-
self.assertEqual(stack_effect(JUMP_IF_TRUE_OR_POP, 0, jump=True), 0)
40-
self.assertEqual(stack_effect(JUMP_IF_TRUE_OR_POP, 0, jump=False), -1)
4137
FOR_ITER = dis.opmap['FOR_ITER']
4238
self.assertEqual(stack_effect(FOR_ITER, 0), 1)
4339
self.assertEqual(stack_effect(FOR_ITER, 0, jump=True), 1)

Objects/frameobject.c

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -306,8 +306,6 @@ mark_stacks(PyCodeObject *code_obj, int len)
306306
}
307307
opcode = code[i].op.code;
308308
switch (opcode) {
309-
case JUMP_IF_FALSE_OR_POP:
310-
case JUMP_IF_TRUE_OR_POP:
311309
case POP_JUMP_IF_FALSE:
312310
case POP_JUMP_IF_TRUE:
313311
{
@@ -318,16 +316,8 @@ mark_stacks(PyCodeObject *code_obj, int len)
318316
if (stacks[j] == UNINITIALIZED && j < i) {
319317
todo = 1;
320318
}
321-
if (opcode == JUMP_IF_FALSE_OR_POP ||
322-
opcode == JUMP_IF_TRUE_OR_POP)
323-
{
324-
target_stack = next_stack;
325-
next_stack = pop_value(next_stack);
326-
}
327-
else {
328-
next_stack = pop_value(next_stack);
329-
target_stack = next_stack;
330-
}
319+
next_stack = pop_value(next_stack);
320+
target_stack = next_stack;
331321
assert(stacks[j] == UNINITIALIZED || stacks[j] == target_stack);
332322
stacks[j] = target_stack;
333323
stacks[i+1] = next_stack;

Python/bytecodes.c

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1919,56 +1919,6 @@ dummy_func(
19191919
}
19201920
}
19211921

1922-
inst(JUMP_IF_FALSE_OR_POP, (cond -- cond if (jump))) {
1923-
bool jump = false;
1924-
int err;
1925-
if (Py_IsTrue(cond)) {
1926-
_Py_DECREF_NO_DEALLOC(cond);
1927-
}
1928-
else if (Py_IsFalse(cond)) {
1929-
JUMPBY(oparg);
1930-
jump = true;
1931-
}
1932-
else {
1933-
err = PyObject_IsTrue(cond);
1934-
if (err > 0) {
< 10000 code>1935-
Py_DECREF(cond);
1936-
}
1937-
else if (err == 0) {
1938-
JUMPBY(oparg);
1939-
jump = true;
1940-
}
1941-
else {
1942-
goto error;
1943-
}
1944-
}
1945-
}
1946-
1947-
inst(JUMP_IF_TRUE_OR_POP, (cond -- cond if (jump))) {
1948-
bool jump = false;
1949-
int err;
1950-
if (Py_IsFalse(cond)) {
1951-
_Py_DECREF_NO_DEALLOC(cond);
1952-
}
1953-
else if (Py_IsTrue(cond)) {
1954-
JUMPBY(oparg);
1955-
jump = true;
1956-
}
1957-
else {
1958-
err = PyObject_IsTrue(cond);
1959-
if (err > 0) {
1960-
JUMPBY(oparg);
1961-
jump = true;
1962-
}
1963-
else if (err == 0) {
1964-
Py_DECREF(cond);
1965-
}
1966-
else {
1967-
goto error;
1968-
}
1969-
}
1970-
}
1971-
19721922
inst(JUMP_BACKWARD_NO_INTERRUPT, (--)) {
19731923
/* This bytecode is used in the `yield from` or `await` loop.
19741924
* If there is an interrupt, we want it handled in the innermost

0 commit comments

Comments
 (0)
0