summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIrit Katriel <1055913+iritkatriel@users.noreply.github.com>2022-01-04 10:37:12 (GMT)
committerGitHub <noreply@github.com>2022-01-04 10:37:12 (GMT)
commita94461d7189d7f1147ab304a332c8684263dc17e (patch)
treebda2df4f74cc58205d548dce76337260984962fd
parenta09062c267a94200ad299f779429fea1b571ee35 (diff)
downloadcpython-a94461d7189d7f1147ab304a332c8684263dc17e.zip
cpython-a94461d7189d7f1147ab304a332c8684263dc17e.tar.gz
cpython-a94461d7189d7f1147ab304a332c8684263dc17e.tar.bz2
bpo-46202: Remove opcode POP_EXCEPT_AND_RERAISE (GH-30302)
* bpo-46202: remove opcode POP_EXCEPT_AND_RERAISE * do not assume that an exception group is truthy
-rw-r--r--Doc/library/dis.rst10
-rw-r--r--Include/opcode.h73
-rw-r--r--Lib/importlib/_bootstrap_external.py3
-rw-r--r--Lib/opcode.py2
-rw-r--r--Lib/test/test_code.py4
-rw-r--r--Lib/test/test_dis.py107
-rw-r--r--Misc/NEWS.d/next/Core and Builtins/2021-12-30-11-06-27.bpo-46202.IKx4v6.rst2
-rw-r--r--Objects/frameobject.c1
-rw-r--r--Python/ceval.c25
-rw-r--r--Python/compile.c37
-rw-r--r--Python/opcode_targets.h20
11 files changed, 138 insertions, 146 deletions
diff --git a/Doc/library/dis.rst b/Doc/library/dis.rst
index 14de191..87ec584 100644
--- a/Doc/library/dis.rst
+++ b/Doc/library/dis.rst
@@ -603,16 +603,6 @@ iterations of the loop.
The ``__exit__`` function is in position 4 of the stack rather than 7.
Exception representation on the stack now consist of one, not three, items.
-.. opcode:: POP_EXCEPT_AND_RERAISE
-
- Pops the exception currently on top of the stack. Pops the integer value on top
- of the stack and sets the ``f_lasti`` attribute of the frame with that value.
- Then pops the next exception from the stack uses it to restore the current exception.
- Finally it re-raises the originally popped exception.
- Used in exception handler cleanup.
-
- .. versionadded:: 3.11
-
.. opcode:: LOAD_ASSERTION_ERROR
diff --git a/Include/opcode.h b/Include/opcode.h
index 0556526..ef334de 100644
--- a/Include/opcode.h
+++ b/Include/opcode.h
@@ -24,7 +24,6 @@ extern "C" {
#define MATCH_SEQUENCE 32
#define MATCH_KEYS 33
#define PUSH_EXC_INFO 35
-#define POP_EXCEPT_AND_RERAISE 37
#define WITH_EXCEPT_START 49
#define GET_AITER 50
#define GET_ANEXT 51
@@ -132,42 +131,42 @@ extern "C" {
#define BINARY_SUBSCR_TUPLE_INT 29
#define BINARY_SUBSCR_DICT 34
#define STORE_SUBSCR_ADAPTIVE 36
-#define STORE_SUBSCR_LIST_INT 38
-#define STORE_SUBSCR_DICT 39
-#define CALL_NO_KW_ADAPTIVE 40
-#define CALL_NO_KW_BUILTIN_O 41
-#define CALL_NO_KW_BUILTIN_FAST 42
-#define CALL_NO_KW_LEN 43
-#define CALL_NO_KW_ISINSTANCE 44
-#define CALL_NO_KW_PY_SIMPLE 45
-#define CALL_NO_KW_LIST_APPEND 46
-#define CALL_NO_KW_METHOD_DESCRIPTOR_O 47
-#define CALL_NO_KW_TYPE_1 48
-#define CALL_NO_KW_BUILTIN_CLASS_1 55
-#define CALL_NO_KW_METHOD_DESCRIPTOR_FAST 56
-#define JUMP_ABSOLUTE_QUICK 57
-#define LOAD_ATTR_ADAPTIVE 58
-#define LOAD_ATTR_INSTANCE_VALUE 59
-#define LOAD_ATTR_WITH_HINT 62
-#define LOAD_ATTR_SLOT 63
-#define LOAD_ATTR_MODULE 64
-#define LOAD_GLOBAL_ADAPTIVE 65
-#define LOAD_GLOBAL_MODULE 66
-#define LOAD_GLOBAL_BUILTIN 67
-#define LOAD_METHOD_ADAPTIVE 72
-#define LOAD_METHOD_CACHED 75
-#define LOAD_METHOD_CLASS 76
-#define LOAD_METHOD_MODULE 77
-#define LOAD_METHOD_NO_DICT 78
-#define STORE_ATTR_ADAPTIVE 79
-#define STORE_ATTR_INSTANCE_VALUE 80
-#define STORE_ATTR_SLOT 81
-#define STORE_ATTR_WITH_HINT 87
-#define LOAD_FAST__LOAD_FAST 128
-#define STORE_FAST__LOAD_FAST 131
-#define LOAD_FAST__LOAD_CONST 134
-#define LOAD_CONST__LOAD_FAST 140
-#define STORE_FAST__STORE_FAST 141
+#define STORE_SUBSCR_LIST_INT 37
+#define STORE_SUBSCR_DICT 38
+#define CALL_NO_KW_ADAPTIVE 39
+#define CALL_NO_KW_BUILTIN_O 40
+#define CALL_NO_KW_BUILTIN_FAST 41
+#define CALL_NO_KW_LEN 42
+#define CALL_NO_KW_ISINSTANCE 43
+#define CALL_NO_KW_PY_SIMPLE 44
+#define CALL_NO_KW_LIST_APPEND 45
+#define CALL_NO_KW_METHOD_DESCRIPTOR_O 46
+#define CALL_NO_KW_TYPE_1 47
+#define CALL_NO_KW_BUILTIN_CLASS_1 48
+#define CALL_NO_KW_METHOD_DESCRIPTOR_FAST 55
+#define JUMP_ABSOLUTE_QUICK 56
+#define LOAD_ATTR_ADAPTIVE 57
+#define LOAD_ATTR_INSTANCE_VALUE 58
+#define LOAD_ATTR_WITH_HINT 59
+#define LOAD_ATTR_SLOT 62
+#define LOAD_ATTR_MODULE 63
+#define LOAD_GLOBAL_ADAPTIVE 64
+#define LOAD_GLOBAL_MODULE 65
+#define LOAD_GLOBAL_BUILTIN 66
+#define LOAD_METHOD_ADAPTIVE 67
+#define LOAD_METHOD_CACHED 72
+#define LOAD_METHOD_CLASS 75
+#define LOAD_METHOD_MODULE 76
+#define LOAD_METHOD_NO_DICT 77
+#define STORE_ATTR_ADAPTIVE 78
+#define STORE_ATTR_INSTANCE_VALUE 79
+#define STORE_ATTR_SLOT 80
+#define STORE_ATTR_WITH_HINT 81
+#define LOAD_FAST__LOAD_FAST 87
+#define STORE_FAST__LOAD_FAST 128
+#define LOAD_FAST__LOAD_CONST 131
+#define LOAD_CONST__LOAD_FAST 134
+#define STORE_FAST__STORE_FAST 140
#define DO_TRACING 255
#ifdef NEED_OPCODE_JUMP_TABLES
static uint32_t _PyOpcode_RelativeJump[8] = {
diff --git a/Lib/importlib/_bootstrap_external.py b/Lib/importlib/_bootstrap_external.py
index 095c127..2932466 100644
--- a/Lib/importlib/_bootstrap_external.py
+++ b/Lib/importlib/_bootstrap_external.py
@@ -376,6 +376,7 @@ _code_type = type(_write_atomic.__code__)
# Python 3.11a4 3468 (Add SEND opcode)
# Python 3.11a4 3469 (bpo-45711: remove type, traceback from exc_info)
# Python 3.11a4 3470 (bpo-46221: PREP_RERAISE_STAR no longer pushes lasti)
+# Python 3.11a4 3471 (bpo-46202: remove pop POP_EXCEPT_AND_RERAISE)
#
# MAGIC must change whenever the bytecode emitted by the compiler may no
@@ -385,7 +386,7 @@ _code_type = type(_write_atomic.__code__)
# Whenever MAGIC_NUMBER is changed, the ranges in the magic_values array
# in PC/launcher.c must also be updated.
-MAGIC_NUMBER = (3470).to_bytes(2, 'little') + b'\r\n'
+MAGIC_NUMBER = (3471).to_bytes(2, 'little') + b'\r\n'
_RAW_MAGIC_NUMBER = int.from_bytes(MAGIC_NUMBER, 'little') # For import.c
_PYCACHE = '__pycache__'
diff --git a/Lib/opcode.py b/Lib/opcode.py
index e654a10..9bbff18 100644
--- a/Lib/opcode.py
+++ b/Lib/opcode.py
@@ -77,8 +77,6 @@ def_op('MATCH_KEYS', 33)
def_op('PUSH_EXC_INFO', 35)
-def_op('POP_EXCEPT_AND_RERAISE', 37)
-
def_op('WITH_EXCEPT_START', 49)
def_op('GET_AITER', 50)
def_op('GET_ANEXT', 51)
diff --git a/Lib/test/test_code.py b/Lib/test/test_code.py
index b42213b..88f6c78 100644
--- a/Lib/test/test_code.py
+++ b/Lib/test/test_code.py
@@ -383,7 +383,9 @@ class CodeTest(unittest.TestCase):
("STORE_NAME", "e"), # XX: we know the location for this
("DELETE_NAME", "e"),
("RERAISE", 1),
- ("POP_EXCEPT_AND_RERAISE", None)
+ ("COPY", 3),
+ ("POP_EXCEPT", None),
+ ("RERAISE", 1)
]
)
diff --git a/Lib/test/test_dis.py b/Lib/test/test_dis.py
index 93b24da..7857458 100644
--- a/Lib/test/test_dis.py
+++ b/Lib/test/test_dis.py
@@ -329,7 +329,9 @@ dis_traceback = """\
46 RERAISE 1
%3d >> 48 RERAISE 0
- >> 50 POP_EXCEPT_AND_RERAISE
+ >> 50 COPY 3
+ 52 POP_EXCEPT
+ 54 RERAISE 1
ExceptionTable:
2 to 8 -> 14 [0]
14 to 20 -> 50 [1] lasti
@@ -390,7 +392,9 @@ dis_tryfinally = """\
16 CALL_NO_KW 0
18 POP_TOP
20 RERAISE 0
- >> 22 POP_EXCEPT_AND_RERAISE
+ >> 22 COPY 3
+ 24 POP_EXCEPT
+ 26 RERAISE 1
ExceptionTable:
2 to 2 -> 12 [0]
12 to 20 -> 22 [1] lasti
@@ -414,7 +418,9 @@ dis_tryfinallyconst = """\
18 CALL_NO_KW 0
20 POP_TOP
22 RERAISE 0
- >> 24 POP_EXCEPT_AND_RERAISE
+ >> 24 COPY 3
+ 26 POP_EXCEPT
+ 28 RERAISE 1
ExceptionTable:
14 to 22 -> 24 [1] lasti
""" % (_tryfinallyconst.__code__.co_firstlineno + 1,
@@ -1105,7 +1111,7 @@ expected_opinfo_jumpy = [
Instruction(opname='LOAD_CONST', opcode=100, arg=7, argval=0, argrepr='0', offset=108, starts_line=None, is_jump_target=False, positions=None),
Instruction(opname='BINARY_OP', opcode=122, arg=11, argval=11, argrepr='/', offset=110, starts_line=None, is_jump_target=False, positions=None),
Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=112, starts_line=None, is_jump_target=False, positions=None),
- Instruction(opname='JUMP_FORWARD', opcode=110, arg=12, argval=140, argrepr='to 140', offset=114, starts_line=None, is_jump_target=False, positions=None),
+ Instruction(opname='JUMP_FORWARD', opcode=110, arg=14, argval=144, argrepr='to 144', offset=114, starts_line=None, is_jump_target=False, positions=None),
Instruction(opname='PUSH_EXC_INFO', opcode=35, arg=None, argval=None, argrepr='', offset=116, starts_line=None, is_jump_target=False, positions=None),
Instruction(opname='LOAD_GLOBAL', opcode=116, arg=2, argval='ZeroDivisionError', argrepr='ZeroDivisionError', offset=118, starts_line=22, is_jump_target=False, positions=None),
Instruction(opname='JUMP_IF_NOT_EXC_MATCH', opcode=121, arg=68, argval=136, argrepr='to 136', offset=120, starts_line=None, is_jump_target=False, positions=None),
@@ -1115,52 +1121,57 @@ expected_opinfo_jumpy = [
Instruction(opname='CALL_NO_KW', opcode=169, arg=1, argval=1, argrepr='', offset=128, starts_line=None, is_jump_target=False, positions=None),
Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=130, starts_line=None, is_jump_target=False, positions=None),
Instruction(opname='POP_EXCEPT', opcode=89, arg=None, argval=None, argrepr='', offset=132, starts_line=None, is_jump_target=False, positions=None),
- Instruction(opname='JUMP_FORWARD', opcode=110, arg=30, argval=196, argrepr='to 196', offset=134, starts_line=None, is_jump_target=False, positions=None),
+ Instruction(opname='JUMP_FORWARD', opcode=110, arg=34, argval=204, argrepr='to 204', offset=134, starts_line=None, is_jump_target=False, positions=None),
Instruction(opname='RERAISE', opcode=119, arg=0, argval=0, argrepr='', offset=136, starts_line=22, is_jump_target=True, positions=None),
- Instruction(opname='POP_EXCEPT_AND_RERAISE', opcode=37, arg=None, argval=None, argrepr='', offset=138, starts_line=None, is_jump_target=False, positions=None),
- Instruction(opname='LOAD_FAST', opcode=124, arg=0, argval='i', argrepr='i', offset=140, starts_line=25, is_jump_target=True, positions=None),
- Instruction(opname='BEFORE_WITH', opcode=53, arg=None, argval=None, argrepr='', offset=142, starts_line=None, is_jump_target=False, positions=None),
- Instruction(opname='STORE_FAST', opcode=125, arg=1, argval='dodgy', argrepr='dodgy', offset=144, starts_line=None, is_jump_target=False, positions=None),
- Instruction(opname='LOAD_GLOBAL', opcode=116, arg=1, argval='print', argrepr='print', offset=146, starts_line=26, is_jump_target=False, positions=None),
- Instruction(opname='LOAD_CONST', opcode=100, arg=9, argval='Never reach this', argrepr="'Never reach this'", offset=148, starts_line=None, is_jump_target=False, positions=None),
- Instruction(opname='CALL_NO_KW', opcode=169, arg=1, argval=1, argrepr='', offset=150, starts_line=None, is_jump_target=False, positions=None),
- Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=152, starts_line=None, is_jump_target=False, positions=None),
- Instruction(opname='LOAD_CONST', opcode=100, arg=0, argval=None, argrepr='None', offset=154, starts_line=25, is_jump_target=False, positions=None),
- Instruction(opname='DUP_TOP', opcode=4, arg=None, argval=None, argrepr='', offset=156, starts_line=None, is_jump_target=False, positions=None),
- Instruction(opname='DUP_TOP', opcode=4, arg=None, argval=None, argrepr='', offset=158, starts_line=None, is_jump_target=False, positions=None),
- Instruction(opname='CALL_NO_KW', opcode=169, arg=3, argval=3, argrepr='', offset=160, starts_line=None, is_jump_target=False, positions=None),
- Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=162, starts_line=None, is_jump_target=False, positions=None),
- Instruction(opname='JUMP_FORWARD', opcode=110, arg=9, argval=184, argrepr='to 184', offset=164, starts_line=None, is_jump_target=False, positions=None),
- Instruction(opname='PUSH_EXC_INFO', opcode=35, arg=None, argval=None, argrepr='', offset=166, starts_line=None, is_jump_target=False, positions=None),
- Instruction(opname='WITH_EXCEPT_START', opcode=49, arg=None, argval=None, argrepr='', offset=168, starts_line=None, is_jump_target=False, positions=None),
- Instruction(opname='POP_JUMP_IF_TRUE', opcode=115, arg=88, argval=176, argrepr='to 176', offset=170, starts_line=None, is_jump_target=False, positions=None),
- Instruction(opname='RERAISE', opcode=119, arg=2, argval=2, argrepr='', offset=172, starts_line=None, is_jump_target=False, positions=None),
- Instruction(opname='POP_EXCEPT_AND_RERAISE', opcode=37, arg=None, argval=None, argrepr='', offset=174, starts_line=None, is_jump_target=False, positions=None),
- Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=176, starts_line=None, is_jump_target=True, positions=None),
- Instruction(opname='POP_EXCEPT', opcode=89, arg=None, argval=None, argrepr='', offset=178, starts_line=None, is_jump_target=False, positions=None),
- Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=180, starts_line=None, is_jump_target=False, positions=None),
- Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=182, starts_line=None, is_jump_target=False, positions=None),
- Instruction(opname='LOAD_GLOBAL', opcode=116, arg=1, argval='print', argrepr='print', offset=184, starts_line=28, is_jump_target=True, positions=None),
- Instruction(opname='LOAD_CONST', opcode=100, arg=10, argval="OK, now we're done", argrepr='"OK, now we\'re done"', offset=186, starts_line=None, is_jump_target=False, positions=None),
- Instruction(opname='CALL_NO_KW', opcode=169, arg=1, argval=1, argrepr='', offset=188, starts_line=None, is_jump_target=False, positions=None),
+ Instruction(opname='COPY', opcode=120, arg=3, argval=3, argrepr='', offset=138, starts_line=None, is_jump_target=False, positions=None),
+ Instruction(opname='POP_EXCEPT', opcode=89, arg=None, argval=None, argrepr='', offset=140, starts_line=None, is_jump_target=False, positions=None),
+ Instruction(opname='RERAISE', opcode=119, arg=1, argval=1, argrepr='', offset=142, starts_line=None, is_jump_target=False, positions=None),
+ Instruction(opname='LOAD_FAST', opcode=124, arg=0, argval='i', argrepr='i', offset=144, starts_line=25, is_jump_target=True, positions=None),
+ Instruction(opname='BEFORE_WITH', opcode=53, arg=None, argval=None, argrepr='', offset=146, starts_line=None, is_jump_target=False, positions=None),
+ Instruction(opname='STORE_FAST', opcode=125, arg=1, argval='dodgy', argrepr='dodgy', offset=148, starts_line=None, is_jump_target=False, positions=None),
+ Instruction(opname='LOAD_GLOBAL', opcode=116, arg=1, argval='print', argrepr='print', offset=150, starts_line=26, is_jump_target=False, positions=None),
+ Instruction(opname='LOAD_CONST', opcode=100, arg=9, argval='Never reach this', argrepr="'Never reach this'", offset=152, starts_line=None, is_jump_target=False, positions=None),
+ Instruction(opname='CALL_NO_KW', opcode=169, arg=1, argval=1, argrepr='', offset=154, starts_line=None, is_jump_target=False, positions=None),
+ Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=156, starts_line=None, is_jump_target=False, positions=None),
+ Instruction(opname='LOAD_CONST', opcode=100, arg=0, argval=None, argrepr='None', offset=158, starts_line=25, is_jump_target=False, positions=None),
+ Instruction(opname='DUP_TOP', opcode=4, arg=None, argval=None, argrepr='', offset=160, starts_line=None, is_jump_target=False, positions=None),
+ Instruction(opname='DUP_TOP', opcode=4, arg=None, argval=None, argrepr='', offset=162, starts_line=None, is_jump_target=False, positions=None),
+ Instruction(opname='CALL_NO_KW', opcode=169, arg=3, argval=3, argrepr='', offset=164, starts_line=None, is_jump_target=False, positions=None),
+ Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=166, starts_line=None, is_jump_target=False, positions=None),
+ Instruction(opname='JUMP_FORWARD', opcode=110, arg=11, argval=192, argrepr='to 192', offset=168, starts_line=None, is_jump_target=False, positions=None),
+ Instruction(opname='PUSH_EXC_INFO', opcode=35, arg=None, argval=None, argrepr='', offset=170, starts_line=None, is_jump_target=False, positions=None),
+ Instruction(opname='WITH_EXCEPT_START', opcode=49, arg=None, argval=None, argrepr='', offset=172, starts_line=None, is_jump_target=False, positions=None),
+ Instruction(opname='POP_JUMP_IF_TRUE', opcode=115, arg=92, argval=184, argrepr='to 184', offset=174, starts_line=None, is_jump_target=False, positions=None),
+ Instruction(opname='RERAISE', opcode=119, arg=2, argval=2, argrepr='', offset=176, starts_line=None, is_jump_target=False, positions=None),
+ Instruction(opname='COPY', opcode=120, arg=3, argval=3, argrepr='', offset=178, starts_line=None, is_jump_target=False, positions=None),
+ Instruction(opname='POP_EXCEPT', opcode=89, arg=None, argval=None, argrepr='', offset=180, starts_line=None, is_jump_target=False, positions=None),
+ Instruction(opname='RERAISE', opcode=119, arg=1, argval=1, argrepr='', offset=182, starts_line=None, is_jump_target=False, positions=None),
+ Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=184, starts_line=None, is_jump_target=True, positions=None),
+ Instruction(opname='POP_EXCEPT', opcode=89, arg=None, argval=None, argrepr='', offset=186, starts_line=None, is_jump_target=False, positions=None),
+ Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=188, starts_line=None, is_jump_target=False, positions=None),
Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=190, starts_line=None, is_jump_target=False, positions=None),
- Instruction(opname='LOAD_CONST', opcode=100, arg=0, argval=None, argrepr='None', offset=192, starts_line=None, is_jump_target=False, positions=None),
- Instruction(opname='RETURN_VALUE', opcode=83, arg=None, argval=None, argrepr='', offset=194, starts_line=None, is_jump_target=False, positions=None),
- Instruction(opname='NOP', opcode=9, arg=None, argval=None, argrepr='', offset=196, starts_line=23, is_jump_target=True, positions=None),
- Instruction(opname='LOAD_GLOBAL', opcode=116, arg=1, argval='print', argrepr='print', offset=198, starts_line=28, is_jump_target=False, positions=None),
- Instruction(opname='LOAD_CONST', opcode=100, arg=10, argval="OK, now we're done", argrepr='"OK, now we\'re done"', offset=200, starts_line=None, is_jump_target=False, positions=None),
- Instruction(opname='CALL_NO_KW', opcode=169, arg=1, argval=1, argrepr='', offset=202, starts_line=None, is_jump_target=False, positions=None),
- Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=204, starts_line=None, is_jump_target=False, positions=None),
- Instruction(opname='LOAD_CONST', opcode=100, arg=0, argval=None, argrepr='None', offset=206, starts_line=None, is_jump_target=False, positions=None),
- Instruction(opname='RETURN_VALUE', opcode=83, arg=None, argval=None, argrepr='', offset=208, starts_line=None, is_jump_target=False, positions=None),
- Instruction(opname='PUSH_EXC_INFO', opcode=35, arg=None, argval=None, argrepr='', offset=210, starts_line=None, is_jump_target=False, positions=None),
- Instruction(opname='LOAD_GLOBAL', opcode=116, arg=1, argval='print', argrepr='print', offset=212, starts_line=None, is_jump_target=False, positions=None),
- Instruction(opname='LOAD_CONST', opcode=100, arg=10, argval="OK, now we're done", argrepr='"OK, now we\'re done"', offset=214, starts_line=None, is_jump_target=False, positions=None),
- Instruction(opname='CALL_NO_KW', opcode=169, arg=1, argval=1, argrepr='', offset=216, starts_line=None, is_jump_target=False, positions=None),
- Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=218, starts_line=None, is_jump_target=False, positions=None),
- Instruction(opname='RERAISE', opcode=119, arg=0, argval=0, argrepr='', offset=220, starts_line=None, is_jump_target=False, positions=None),
- Instruction(opname='POP_EXCEPT_AND_RERAISE', opcode=37, arg=None, argval=None, argrepr='', offset=222, starts_line=None, is_jump_target=False, positions=None),
-]
+ Instruction(opname='LOAD_GLOBAL', opcode=116, arg=1, argval='print', argrepr='print', offset=192, starts_line=28, is_jump_target=True, positions=None),
+ Instruction(opname='LOAD_CONST', opcode=100, arg=10, argval="OK, now we're done", argrepr='"OK, now we\'re done"', offset=194, starts_line=None, is_jump_target=False, positions=None),
+ Instruction(opname='CALL_NO_KW', opcode=169, arg=1, argval=1, argrepr='', offset=196, starts_line=None, is_jump_target=False, positions=None),
+ Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=198, starts_line=None, is_jump_target=False, positions=None),
+ Instruction(opname='LOAD_CONST', opcode=100, arg=0, argval=None, argrepr='None', offset=200, starts_line=None, is_jump_target=False, positions=None),
+ Instruction(opname='RETURN_VALUE', opcode=83, arg=None, argval=None, argrepr='', offset=202, starts_line=None, is_jump_target=False, positions=None),
+ Instruction(opname='NOP', opcode=9, arg=None, argval=None, argrepr='', offset=204, starts_line=23, is_jump_target=True, positions=None),
+ Instruction(opname='LOAD_GLOBAL', opcode=116, arg=1, argval='print', argrepr='print', offset=206, starts_line=28, is_jump_target=False, positions=None),
+ Instruction(opname='LOAD_CONST', opcode=100, arg=10, argval="OK, now we're done", argrepr='"OK, now we\'re done"', offset=208, starts_line=None, is_jump_target=False, positions=None),
+ Instruction(opname='CALL_NO_KW', opcode=169, arg=1, argval=1, argrepr='', offset=210, starts_line=None, is_jump_target=False, positions=None),
+ Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=212, starts_line=None, is_jump_target=False, positions=None),
+ Instruction(opname='LOAD_CONST', opcode=100, arg=0, argval=None, argrepr='None', offset=214, starts_line=None, is_jump_target=False, positions=None),
+ Instruction(opname='RETURN_VALUE', opcode=83, arg=None, argval=None, argrepr='', offset=216, starts_line=None, is_jump_target=False, positions=None),
+ Instruction(opname='PUSH_EXC_INFO', opcode=35, arg=None, argval=None, argrepr='', offset=218, starts_line=None, is_jump_target=False, positions=None),
+ Instruction(opname='LOAD_GLOBAL', opcode=116, arg=1, argval='print', argrepr='print', offset=220, starts_line=None, is_jump_target=False, positions=None),
+ Instruction(opname='LOAD_CONST', opcode=100, arg=10, argval="OK, now we're done", argrepr='"OK, now we\'re done"', offset=222, starts_line=None, is_jump_target=False, positions=None),
+ Instruction(opname='CALL_NO_KW', opcode=169, arg=1, argval=1, argrepr='', offset=224, starts_line=None, is_jump_target=False, positions=None),
+ Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=226, starts_line=None, is_jump_target=False, positions=None),
+ Instruction(opname='RERAISE', opcode=119, arg=0, argval=0, argrepr='', offset=228, starts_line=None, is_jump_target=False, positions=None),
+ Instruction(opname='COPY', opcode=120, arg=3, argval=3, argrepr='', offset=230, starts_line=None, is_jump_target=False, positions=None),
+ Instruction(opname='POP_EXCEPT', opcode=89, arg=None, argval=None, argrepr='', offset=232, starts_line=None, is_jump_target=False, positions=None),
+ Instruction(opname='RERAISE', opcode=119, arg=1, argval=1, argrepr='', offset=234, starts_line=None, is_jump_target=False, positions=None)]
# One last piece of inspect fodder to check the default line number handling
def simple(): pass
diff --git a/Misc/NEWS.d/next/Core and Builtins/2021-12-30-11-06-27.bpo-46202.IKx4v6.rst b/Misc/NEWS.d/next/Core and Builtins/2021-12-30-11-06-27.bpo-46202.IKx4v6.rst
new file mode 100644
index 0000000..ee0a903
--- /dev/null
+++ b/Misc/NEWS.d/next/Core and Builtins/2021-12-30-11-06-27.bpo-46202.IKx4v6.rst
@@ -0,0 +1,2 @@
+Remove :opcode:`POP_EXCEPT_AND_RERAISE` and replace it by an equivalent
+sequence of other opcodes.
diff --git a/Objects/frameobject.c b/Objects/frameobject.c
index fc62713..078fcfc 100644
--- a/Objects/frameobject.c
+++ b/Objects/frameobject.c
@@ -289,7 +289,6 @@ mark_stacks(PyCodeObject *code_obj, int len)
case RETURN_VALUE:
case RAISE_VARARGS:
case RERAISE:
- case POP_EXCEPT_AND_RERAISE:
/* End of block */
break;
case GEN_START:
diff --git a/Python/ceval.c b/Python/ceval.c
index 43925e6..81bea44 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -2725,31 +2725,6 @@ check_eval_breaker:
DISPATCH();
}
- TARGET(POP_EXCEPT_AND_RERAISE) {
- PyObject *lasti = PEEK(2);
- if (PyLong_Check(lasti)) {
- frame->f_lasti = PyLong_AsLong(lasti);
- assert(!_PyErr_Occurred(tstate));
- }
- else {
- _PyErr_SetString(tstate, PyExc_SystemError, "lasti is not an int");
- goto error;
- }
- PyObject *value = POP();
- assert(value);
- assert(PyExceptionInstance_Check(value));
- PyObject *type = Py_NewRef(PyExceptionInstance_Class(value));
- PyObject *traceback = PyException_GetTraceback(value);
- Py_DECREF(POP()); /* lasti */
- _PyErr_Restore(tstate, type, value, traceback);
-
- _PyErr_StackItem *exc_info = tstate->exc_info;
- value = exc_info->exc_value;
- exc_info->exc_value = POP();
- Py_XDECREF(value);
- goto exception_unwind;
- }
-
TARGET(RERAISE) {
if (oparg) {
PyObject *lasti = PEEK(oparg + 1);
diff --git a/Python/compile.c b/Python/compile.c
index 48250b5..9d37529 100644
--- a/Python/compile.c
+++ b/Python/compile.c
@@ -1049,8 +1049,6 @@ stack_effect(int opcode, int oparg, int jump)
return 0;
case POP_EXCEPT:
return -1;
- case POP_EXCEPT_AND_RERAISE:
- return -3;
case STORE_NAME:
return -1;
@@ -1669,6 +1667,9 @@ compiler_addop_j_noline(struct compiler *c, int opcode, basicblock *b)
#define ADD_YIELD_FROM(C) \
RETURN_IF_FALSE(compiler_add_yield_from((C)))
+#define POP_EXCEPT_AND_RERAISE(C) \
+ RETURN_IF_FALSE(compiler_pop_except_and_reraise((C)))
+
#define VISIT(C, TYPE, V) {\
if (!compiler_visit_ ## TYPE((C), (V))) \
return 0; \
@@ -1839,6 +1840,22 @@ compiler_add_yield_from(struct compiler *c)
return 1;
}
+static int
+compiler_pop_except_and_reraise(struct compiler *c)
+{
+ /* Stack contents
+ * [exc_info, lasti, exc] COPY 3
+ * [exc_info, lasti, exc, exc_info] POP_EXCEPT
+ * [exc_info, lasti, exc] RERAISE 1
+ * (exception_unwind clears the stack)
+ */
+
+ ADDOP_I(c, COPY, 3);
+ ADDOP(c, POP_EXCEPT);
+ ADDOP_I(c, RERAISE, 1);
+ return 1;
+}
+
/* Unwind a frame block. If preserve_tos is true, the TOS before
* popping the blocks will be restored afterwards, unless another
* return, break or continue is found. In which case, the TOS will
@@ -3235,7 +3252,7 @@ compiler_try_finally(struct compiler *c, stmt_ty s)
compiler_pop_fblock(c, FINALLY_END, end);
ADDOP_I(c, RERAISE, 0);
compiler_use_next_block(c, cleanup);
- ADDOP(c, POP_EXCEPT_AND_RERAISE);
+ POP_EXCEPT_AND_RERAISE(c);
compiler_use_next_block(c, exit);
return 1;
}
@@ -3290,7 +3307,7 @@ compiler_try_star_finally(struct compiler *c, stmt_ty s)
compiler_pop_fblock(c, FINALLY_END, end);
ADDOP_I(c, RERAISE, 0);
compiler_use_next_block(c, cleanup);
- ADDOP(c, POP_EXCEPT_AND_RERAISE);
+ POP_EXCEPT_AND_RERAISE(c);
compiler_use_next_block(c, exit);
return 1;
}
@@ -3446,7 +3463,7 @@ compiler_try_except(struct compiler *c, stmt_ty s)
compiler_pop_fblock(c, EXCEPTION_HANDLER, NULL);
ADDOP_I(c, RERAISE, 0);
compiler_use_next_block(c, cleanup);
- ADDOP(c, POP_EXCEPT_AND_RERAISE);
+ POP_EXCEPT_AND_RERAISE(c);
compiler_use_next_block(c, orelse);
VISIT_SEQ(c, stmt, s->v.Try.orelse);
ADDOP_JUMP(c, JUMP_FORWARD, end);
@@ -3497,7 +3514,7 @@ compiler_try_except(struct compiler *c, stmt_ty s)
[exc] RER: ROT_TWO
[exc, prev_exc_info] POP_EXCEPT
- [exc] RERAISE 0
+ [exc] RERAISE 0
[] L0: <next statement>
*/
@@ -3677,7 +3694,7 @@ compiler_try_star_except(struct compiler *c, stmt_ty s)
ADDOP(c, POP_EXCEPT);
ADDOP_I(c, RERAISE, 0);
compiler_use_next_block(c, cleanup);
- ADDOP(c, POP_EXCEPT_AND_RERAISE);
+ POP_EXCEPT_AND_RERAISE(c);
compiler_use_next_block(c, orelse);
VISIT_SEQ(c, stmt, s->v.TryStar.orelse);
ADDOP_JUMP(c, JUMP_FORWARD, end);
@@ -5429,7 +5446,7 @@ compiler_with_except_finish(struct compiler *c, basicblock * cleanup) {
NEXT_BLOCK(c);
ADDOP_I(c, RERAISE, 2);
compiler_use_next_block(c, cleanup);
- ADDOP(c, POP_EXCEPT_AND_RERAISE);
+ POP_EXCEPT_AND_RERAISE(c);
compiler_use_next_block(c, exit);
ADDOP(c, POP_TOP); /* exc_value */
ADDOP(c, POP_BLOCK);
@@ -7032,8 +7049,7 @@ stackdepth(struct compiler *c)
instr->i_opcode == JUMP_FORWARD ||
instr->i_opcode == RETURN_VALUE ||
instr->i_opcode == RAISE_VARARGS ||
- instr->i_opcode == RERAISE ||
- instr->i_opcode == POP_EXCEPT_AND_RERAISE)
+ instr->i_opcode == RERAISE)
{
/* remaining code is dead */
next = NULL;
@@ -8756,7 +8772,6 @@ normalize_basic_block(basicblock *bb) {
case RETURN_VALUE:
case RAISE_VARARGS:
case RERAISE:
- case POP_EXCEPT_AND_RERAISE:
bb->b_exit = 1;
bb->b_nofallthrough = 1;
break;
diff --git a/Python/opcode_targets.h b/Python/opcode_targets.h
index 3ee0b9c..a8f1398 100644
--- a/Python/opcode_targets.h
+++ b/Python/opcode_targets.h
@@ -36,7 +36,6 @@ static void *opcode_targets[256] = {
&&TARGET_BINARY_SUBSCR_DICT,
&&TARGET_PUSH_EXC_INFO,
&&TARGET_STORE_SUBSCR_ADAPTIVE,
- &&TARGET_POP_EXCEPT_AND_RERAISE,
&&TARGET_STORE_SUBSCR_LIST_INT,
&&TARGET_STORE_SUBSCR_DICT,
&&TARGET_CALL_NO_KW_ADAPTIVE,
@@ -48,45 +47,46 @@ static void *opcode_targets[256] = {
&&TARGET_CALL_NO_KW_LIST_APPEND,
&&TARGET_CALL_NO_KW_METHOD_DESCRIPTOR_O,
&&TARGET_CALL_NO_KW_TYPE_1,
+ &&TARGET_CALL_NO_KW_BUILTIN_CLASS_1,
&&TARGET_WITH_EXCEPT_START,
&&TARGET_GET_AITER,
&&TARGET_GET_ANEXT,
&&TARGET_BEFORE_ASYNC_WITH,
&&TARGET_BEFORE_WITH,
&&TARGET_END_ASYNC_FOR,
- &&TARGET_CALL_NO_KW_BUILTIN_CLASS_1,
&&TARGET_CALL_NO_KW_METHOD_DESCRIPTOR_FAST,
&&TARGET_JUMP_ABSOLUTE_QUICK,
&&TARGET_LOAD_ATTR_ADAPTIVE,
&&TARGET_LOAD_ATTR_INSTANCE_VALUE,
+ &&TARGET_LOAD_ATTR_WITH_HINT,
&&TARGET_STORE_SUBSCR,
&&TARGET_DELETE_SUBSCR,
- &&TARGET_LOAD_ATTR_WITH_HINT,
&&TARGET_LOAD_ATTR_SLOT,
&&TARGET_LOAD_ATTR_MODULE,
&&TARGET_LOAD_GLOBAL_ADAPTIVE,
&&TARGET_LOAD_GLOBAL_MODULE,
&&TARGET_LOAD_GLOBAL_BUILTIN,
+ &&TARGET_LOAD_METHOD_ADAPTIVE,
&&TARGET_GET_ITER,
&&TARGET_GET_YIELD_FROM_ITER,
&&TARGET_PRINT_EXPR,
&&TARGET_LOAD_BUILD_CLASS,
- &&TARGET_LOAD_METHOD_ADAPTIVE,
+ &&TARGET_LOAD_METHOD_CACHED,
&&TARGET_GET_AWAITABLE,
&&TARGET_LOAD_ASSERTION_ERROR,
- &&TARGET_LOAD_METHOD_CACHED,
&&TARGET_LOAD_METHOD_CLASS,
&&TARGET_LOAD_METHOD_MODULE,
&&TARGET_LOAD_METHOD_NO_DICT,
&&TARGET_STORE_ATTR_ADAPTIVE,
&&TARGET_STORE_ATTR_INSTANCE_VALUE,
&&TARGET_STORE_ATTR_SLOT,
+ &&TARGET_STORE_ATTR_WITH_HINT,
&&TARGET_LIST_TO_TUPLE,
&&TARGET_RETURN_VALUE,
&&TARGET_IMPORT_STAR,
&&TARGET_SETUP_ANNOTATIONS,
&&TARGET_YIELD_VALUE,
- &&TARGET_STORE_ATTR_WITH_HINT,
+ &&TARGET_LOAD_FAST__LOAD_FAST,
&&TARGET_PREP_RERAISE_STAR,
&&TARGET_POP_EXCEPT,
&&TARGET_STORE_NAME,
@@ -127,20 +127,20 @@ static void *opcode_targets[256] = {
&&TARGET_STORE_FAST,
&&TARGET_DELETE_FAST,
&&TARGET_JUMP_IF_NOT_EG_MATCH,
- &&TARGET_LOAD_FAST__LOAD_FAST,
+ &&TARGET_STORE_FAST__LOAD_FAST,
&&TARGET_GEN_START,
&&TARGET_RAISE_VARARGS,
- &&TARGET_STORE_FAST__LOAD_FAST,
+ &&TARGET_LOAD_FAST__LOAD_CONST,
&&TARGET_MAKE_FUNCTION,
&&TARGET_BUILD_SLICE,
- &&TARGET_LOAD_FAST__LOAD_CONST,
+ &&TARGET_LOAD_CONST__LOAD_FAST,
&&TARGET_MAKE_CELL,
&&TARGET_LOAD_CLOSURE,
&&TARGET_LOAD_DEREF,
&&TARGET_STORE_DEREF,
&&TARGET_DELETE_DEREF,
- &&TARGET_LOAD_CONST__LOAD_FAST,
&&TARGET_STORE_FAST__STORE_FAST,
+ &&_unknown_opcode,
&&TARGET_CALL_FUNCTION_EX,
&&_unknown_opcode,
&&TARGET_EXTENDED_ARG,