From 48a18d53e7168eaf68f956b06e0f507da4805720 Mon Sep 17 00:00:00 2001 From: "C.A.M. Gerlach" Date: Thu, 20 Oct 2022 17:38:58 -0500 Subject: [PATCH 01/13] Fix Sphinx syntax in bytecode section and tweak phrasing --- Doc/whatsnew/3.11.rst | 41 ++++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/Doc/whatsnew/3.11.rst b/Doc/whatsnew/3.11.rst index 79afc1f99e99d9..e7db371623645c 100644 --- a/Doc/whatsnew/3.11.rst +++ b/Doc/whatsnew/3.11.rst @@ -1414,51 +1414,54 @@ CPython bytecode changes taken when reading or modifying raw, adaptive bytecode containing quickened data. -* Replaced all numeric ``BINARY_*`` and ``INPLACE_*`` instructions with a single - :opcode:`BINARY_OP` implementation. +* Replaced all numeric :opcode:`!BINARY_*` and :opcode:`!INPLACE_*` instructions + with a single :opcode:`BINARY_OP` implementation. -* Replaced the three call instructions: :opcode:`CALL_FUNCTION`, - :opcode:`CALL_FUNCTION_KW` and :opcode:`CALL_METHOD` with +* Replaced the three call instructions :opcode:`!CALL_FUNCTION`, + :opcode:`!CALL_FUNCTION_KW` and :opcode:`!CALL_METHOD` with :opcode:`PUSH_NULL`, :opcode:`PRECALL`, :opcode:`CALL`, and :opcode:`KW_NAMES`. This decouples the argument shifting for methods from the handling of keyword arguments and allows better specialization of calls. -* Removed ``COPY_DICT_WITHOUT_KEYS`` and ``GEN_START``. +* Removed :opcode:`!COPY_DICT_WITHOUT_KEYS` and :opcode:`!GEN_START`. * :opcode:`MATCH_CLASS` and :opcode:`MATCH_KEYS` no longer push an additional boolean value indicating whether the match succeeded or failed. Instead, they - indicate failure with :const:`None` (where a tuple of extracted values would + indicate failure with ``None`` (where a tuple of extracted values would otherwise be). -* Replace several stack manipulation instructions (``DUP_TOP``, ``DUP_TOP_TWO``, - ``ROT_TWO``, ``ROT_THREE``, ``ROT_FOUR``, and ``ROT_N``) with new - :opcode:`COPY` and :opcode:`SWAP` instructions. +* Replaced several stack manipulation instructions + (:opcode:`!DUP_TOP`, :opcode:`!DUP_TOP_TWO`, :opcode:`!ROT_TWO`, + :opcode:`!ROT_THREE`, :opcode:`!ROT_FOUR`, and :opcode:`!ROT_N`) + with new :opcode:`COPY` and :opcode:`SWAP` instructions. -* Replaced :opcode:`JUMP_IF_NOT_EXC_MATCH` by :opcode:`CHECK_EXC_MATCH` which +* Replaced :opcode:`!JUMP_IF_NOT_EXC_MATCH` by :opcode:`CHECK_EXC_MATCH`, which performs the check but does not jump. -* Replaced :opcode:`JUMP_IF_NOT_EG_MATCH` by :opcode:`CHECK_EG_MATCH` which +* Replaced :opcode:`!JUMP_IF_NOT_EG_MATCH` by :opcode:`CHECK_EG_MATCH` which performs the check but does not jump. -* Replaced :opcode:`JUMP_ABSOLUTE` by the relative :opcode:`JUMP_BACKWARD`. +* Replaced :opcode:`!JUMP_ABSOLUTE` by the relative :opcode:`JUMP_BACKWARD`. -* Added :opcode:`JUMP_BACKWARD_NO_INTERRUPT`, which is used in certain loops where it - is undesirable to handle interrupts. +* Added :opcode:`JUMP_BACKWARD_NO_INTERRUPT`, + which is used in certain loops where it is undesirable to handle interrupts. -* Replaced :opcode:`POP_JUMP_IF_TRUE` and :opcode:`POP_JUMP_IF_FALSE` by - the relative :opcode:`POP_JUMP_FORWARD_IF_TRUE`, :opcode:`POP_JUMP_BACKWARD_IF_TRUE`, +* Replaced :opcode:`!POP_JUMP_IF_TRUE` and :opcode:`!POP_JUMP_IF_FALSE` by + the relative :opcode:`POP_JUMP_FORWARD_IF_TRUE`, + :opcode:`POP_JUMP_BACKWARD_IF_TRUE`, :opcode:`POP_JUMP_FORWARD_IF_FALSE` and :opcode:`POP_JUMP_BACKWARD_IF_FALSE`. -* Added :opcode:`POP_JUMP_FORWARD_IF_NOT_NONE`, :opcode:`POP_JUMP_BACKWARD_IF_NOT_NONE`, +* Added :opcode:`POP_JUMP_FORWARD_IF_NOT_NONE`, + :opcode:`POP_JUMP_BACKWARD_IF_NOT_NONE`, :opcode:`POP_JUMP_FORWARD_IF_NONE` and :opcode:`POP_JUMP_BACKWARD_IF_NONE` opcodes to speed up conditional jumps. * :opcode:`JUMP_IF_TRUE_OR_POP` and :opcode:`JUMP_IF_FALSE_OR_POP` are now relative rather than absolute. -* :opcode:`RESUME` has been added. It is a no-op. Performs internal tracing, - debugging and optimization checks. +* :opcode:`RESUME` has been added. It is a no-op, + and performs internal tracing, debugging and optimization checks. .. _whatsnew311-deprecated: From 4a3d83028b716f5328583e92f5efe8fe1d50b557 Mon Sep 17 00:00:00 2001 From: "C.A.M. Gerlach" Date: Thu, 20 Oct 2022 17:58:02 -0500 Subject: [PATCH 02/13] Use clear, consistant phrasing on all Bytecode entries --- Doc/whatsnew/3.11.rst | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/Doc/whatsnew/3.11.rst b/Doc/whatsnew/3.11.rst index e7db371623645c..62684e83abf286 100644 --- a/Doc/whatsnew/3.11.rst +++ b/Doc/whatsnew/3.11.rst @@ -1426,21 +1426,20 @@ CPython bytecode changes * Removed :opcode:`!COPY_DICT_WITHOUT_KEYS` and :opcode:`!GEN_START`. -* :opcode:`MATCH_CLASS` and :opcode:`MATCH_KEYS` no longer push an additional - boolean value indicating whether the match succeeded or failed. Instead, they - indicate failure with ``None`` (where a tuple of extracted values would - otherwise be). +* Changed :opcode:`MATCH_CLASS` and :opcode:`MATCH_KEYS` + to no longer push an additional boolean value + indicating whether the match succeeded or failed. + Instead, they indicate failure with ``None`` + (where a tuple of extracted values would otherwise be). * Replaced several stack manipulation instructions (:opcode:`!DUP_TOP`, :opcode:`!DUP_TOP_TWO`, :opcode:`!ROT_TWO`, :opcode:`!ROT_THREE`, :opcode:`!ROT_FOUR`, and :opcode:`!ROT_N`) with new :opcode:`COPY` and :opcode:`SWAP` instructions. -* Replaced :opcode:`!JUMP_IF_NOT_EXC_MATCH` by :opcode:`CHECK_EXC_MATCH`, which - performs the check but does not jump. - -* Replaced :opcode:`!JUMP_IF_NOT_EG_MATCH` by :opcode:`CHECK_EG_MATCH` which - performs the check but does not jump. +* Replaced :opcode:`!JUMP_IF_NOT_EXC_MATCH` with :opcode:`CHECK_EXC_MATCH` + and :opcode:`!JUMP_IF_NOT_EG_MATCH` with :opcode:`CHECK_EG_MATCH`, + which perform the check but do not jump. * Replaced :opcode:`!JUMP_ABSOLUTE` by the relative :opcode:`JUMP_BACKWARD`. @@ -1457,10 +1456,10 @@ CPython bytecode changes :opcode:`POP_JUMP_FORWARD_IF_NONE` and :opcode:`POP_JUMP_BACKWARD_IF_NONE` opcodes to speed up conditional jumps. -* :opcode:`JUMP_IF_TRUE_OR_POP` and :opcode:`JUMP_IF_FALSE_OR_POP` are now - relative rather than absolute. +* Changed :opcode:`JUMP_IF_TRUE_OR_POP` and :opcode:`JUMP_IF_FALSE_OR_POP` + to now be relative rather than absolute. -* :opcode:`RESUME` has been added. It is a no-op, +* Added the :opcode:`RESUME` opcode. It is a no-op, and performs internal tracing, debugging and optimization checks. From 611a62807c3747bc178b171d0c40625e1494d7fd Mon Sep 17 00:00:00 2001 From: "C.A.M. Gerlach" Date: Thu, 20 Oct 2022 18:35:07 -0500 Subject: [PATCH 03/13] Re-order opcode changes to Added, Replaced, Removed, Changed --- Doc/whatsnew/3.11.rst | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/Doc/whatsnew/3.11.rst b/Doc/whatsnew/3.11.rst index 62684e83abf286..36968d70780e15 100644 --- a/Doc/whatsnew/3.11.rst +++ b/Doc/whatsnew/3.11.rst @@ -1414,6 +1414,17 @@ CPython bytecode changes taken when reading or modifying raw, adaptive bytecode containing quickened data. +* Added :opcode:`JUMP_BACKWARD_NO_INTERRUPT`, + which is used in certain loops where it is undesirable to handle interrupts. + +* Added :opcode:`POP_JUMP_FORWARD_IF_NOT_NONE`, + :opcode:`POP_JUMP_BACKWARD_IF_NOT_NONE`, + :opcode:`POP_JUMP_FORWARD_IF_NONE` and :opcode:`POP_JUMP_BACKWARD_IF_NONE` + opcodes to speed up conditional jumps. + +* Added the :opcode:`RESUME` opcode. It is a no-op, + and performs internal tracing, debugging and optimization checks. + * Replaced all numeric :opcode:`!BINARY_*` and :opcode:`!INPLACE_*` instructions with a single :opcode:`BINARY_OP` implementation. @@ -1424,14 +1435,6 @@ CPython bytecode changes This decouples the argument shifting for methods from the handling of keyword arguments and allows better specialization of calls. -* Removed :opcode:`!COPY_DICT_WITHOUT_KEYS` and :opcode:`!GEN_START`. - -* Changed :opcode:`MATCH_CLASS` and :opcode:`MATCH_KEYS` - to no longer push an additional boolean value - indicating whether the match succeeded or failed. - Instead, they indicate failure with ``None`` - (where a tuple of extracted values would otherwise be). - * Replaced several stack manipulation instructions (:opcode:`!DUP_TOP`, :opcode:`!DUP_TOP_TWO`, :opcode:`!ROT_TWO`, :opcode:`!ROT_THREE`, :opcode:`!ROT_FOUR`, and :opcode:`!ROT_N`) @@ -1443,24 +1446,21 @@ CPython bytecode changes * Replaced :opcode:`!JUMP_ABSOLUTE` by the relative :opcode:`JUMP_BACKWARD`. -* Added :opcode:`JUMP_BACKWARD_NO_INTERRUPT`, - which is used in certain loops where it is undesirable to handle interrupts. - * Replaced :opcode:`!POP_JUMP_IF_TRUE` and :opcode:`!POP_JUMP_IF_FALSE` by the relative :opcode:`POP_JUMP_FORWARD_IF_TRUE`, :opcode:`POP_JUMP_BACKWARD_IF_TRUE`, :opcode:`POP_JUMP_FORWARD_IF_FALSE` and :opcode:`POP_JUMP_BACKWARD_IF_FALSE`. -* Added :opcode:`POP_JUMP_FORWARD_IF_NOT_NONE`, - :opcode:`POP_JUMP_BACKWARD_IF_NOT_NONE`, - :opcode:`POP_JUMP_FORWARD_IF_NONE` and :opcode:`POP_JUMP_BACKWARD_IF_NONE` - opcodes to speed up conditional jumps. +* Removed :opcode:`!COPY_DICT_WITHOUT_KEYS` and :opcode:`!GEN_START`. * Changed :opcode:`JUMP_IF_TRUE_OR_POP` and :opcode:`JUMP_IF_FALSE_OR_POP` to now be relative rather than absolute. -* Added the :opcode:`RESUME` opcode. It is a no-op, - and performs internal tracing, debugging and optimization checks. +* Changed :opcode:`MATCH_CLASS` and :opcode:`MATCH_KEYS` + to no longer push an additional boolean value + indicating whether the match succeeded or failed. + Instead, they indicate failure with ``None`` + (where a tuple of extracted values would otherwise be). .. _whatsnew311-deprecated: From 68bef2a95d066a6c42a6b602d98050ed56ed51fd Mon Sep 17 00:00:00 2001 From: "C.A.M. Gerlach" Date: Fri, 21 Oct 2022 01:57:28 -0500 Subject: [PATCH 04/13] Add missing added and removed opcodes to section --- Doc/whatsnew/3.11.rst | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/Doc/whatsnew/3.11.rst b/Doc/whatsnew/3.11.rst index 36968d70780e15..e3c96839782881 100644 --- a/Doc/whatsnew/3.11.rst +++ b/Doc/whatsnew/3.11.rst @@ -1414,17 +1414,29 @@ CPython bytecode changes taken when reading or modifying raw, adaptive bytecode containing quickened data. +* Added :opcode:`COPY_FREE_VARS` to avoid needing special caller-side code + to handle calling closures. + * Added :opcode:`JUMP_BACKWARD_NO_INTERRUPT`, which is used in certain loops where it is undesirable to handle interrupts. +* Added :opcode:`MAKE_CELL` to create a new :ref:`cell object `. + * Added :opcode:`POP_JUMP_FORWARD_IF_NOT_NONE`, :opcode:`POP_JUMP_BACKWARD_IF_NOT_NONE`, :opcode:`POP_JUMP_FORWARD_IF_NONE` and :opcode:`POP_JUMP_BACKWARD_IF_NONE` opcodes to speed up conditional jumps. +* Added :opcode:`PUSH_EXC_INFO` for use in exception handlers + and :opcode:`PREP_RERAISE_STAR` for the new + :ref:`exception groups and except* `. + * Added the :opcode:`RESUME` opcode. It is a no-op, and performs internal tracing, debugging and optimization checks. +* Added :opcode:`RETURN_GENERATOR`, :opcode:`SEND` and :opcode:`ASYNC_GEN_WRAP`, + used in generators and co-routines. + * Replaced all numeric :opcode:`!BINARY_*` and :opcode:`!INPLACE_*` instructions with a single :opcode:`BINARY_OP` implementation. @@ -1451,7 +1463,11 @@ CPython bytecode changes :opcode:`POP_JUMP_BACKWARD_IF_TRUE`, :opcode:`POP_JUMP_FORWARD_IF_FALSE` and :opcode:`POP_JUMP_BACKWARD_IF_FALSE`. -* Removed :opcode:`!COPY_DICT_WITHOUT_KEYS` and :opcode:`!GEN_START`. +* Replaced :opcode:`!SETUP_WITH` and :opcode:`!SETUP_ASYNC_WITH` + with :opcode:`BEFORE_WITH`. + +* Removed opcodes :opcode:`!COPY_DICT_WITHOUT_KEYS`, :opcode:`!GEN_START`, + :opcode:`!POP_BLOCK`, :opcode:`!SETUP_FINALLY` and :opcode:`!YIELD_FROM`. * Changed :opcode:`JUMP_IF_TRUE_OR_POP` and :opcode:`JUMP_IF_FALSE_OR_POP` to now be relative rather than absolute. From f34698cd61b658dd8c13b4d7d3f008dde38cfc19 Mon Sep 17 00:00:00 2001 From: "C.A.M. Gerlach" Date: Fri, 21 Oct 2022 23:21:38 -0500 Subject: [PATCH 05/13] Add table with all added/replace/removed opcodes --- Doc/whatsnew/3.11.rst | 53 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/Doc/whatsnew/3.11.rst b/Doc/whatsnew/3.11.rst index e3c96839782881..9d7de75608c9bf 100644 --- a/Doc/whatsnew/3.11.rst +++ b/Doc/whatsnew/3.11.rst @@ -1407,6 +1407,59 @@ contributors are volunteers from the community. CPython bytecode changes ======================== ++-------------------------------------------+-------------------------------------------+ +| Old Opcode(s) | New Opcode(s) | ++===============+===========================+===========================================+ +| | | :opcode:`ASYNC_GEN_WRAP` | +| | | :opcode:`CACHE` | +| | | :opcode:`COPY_FREE_VARS` | +| | | :opcode:`JUMP_BACKWARD_NO_INTERRUPT` | +| | | :opcode:`MAKE_CELL` | +| | | :opcode:`POP_JUMP_BACKWARD_IF_NONE` | +| | | :opcode:`POP_JUMP_BACKWARD_IF_NOT_NONE` | +| | | :opcode:`POP_JUMP_FORWARD_IF_NOT_NONE` | +| | | :opcode:`POP_JUMP_FORWARD_IF_NONE` | +| | | :opcode:`PREP_RERAISE_STAR` | +| | | :opcode:`PUSH_EXC_INFO` | +| | | :opcode:`RESUME` | +| | | :opcode:`RETURN_GENERATOR` | +| | | :opcode:`SEND` | ++-------------------------------------------+-------------------------------------------+ +| | :opcode:`!BINARY_*` | :opcode:`BINARY_OP` | +| | :opcode:`!INPLACE_*` | | ++-------------------------------------------+-------------------------------------------+ +| | :opcode:`!CALL_FUNCTION` | | :opcode:`CALL` | +| | :opcode:`!CALL_FUNCTION_KW` | | :opcode:`KW_NAMES` | +| | :opcode:`!CALL_METHOD` | | :opcode:`PRECALL` | +| | | :opcode:`PUSH_NULL` | ++-------------------------------------------+-------------------------------------------+ +| | :opcode:`!DUP_TOP` | | :opcode:`COPY` | +| | :opcode:`!DUP_TOP_TWO` | | :opcode:`SWAP` | +| | :opcode:`!ROT_TWO` | | +| | :opcode:`!ROT_THREE` | | +| | :opcode:`!ROT_FOUR` | | +| | :opcode:`!ROT_N` | | ++-------------------------------------------+-------------------------------------------+ +| :opcode:`!JUMP_ABSOLUTE` | :opcode:`JUMP_BACKWARD` | ++-------------------------------------------+-------------------------------------------+ +| :opcode:`!JUMP_IF_NOT_EXC_MATCH` | :opcode:`CHECK_EXC_MATCH` | ++-------------------------------------------+-------------------------------------------+ +| :opcode:`!JUMP_IF_NOT_EG_MATCH` | :opcode:`CHECK_EG_MATCH` | ++-------------------------------------------+-------------------------------------------+ +| :opcode:`!POP_JUMP_IF_FALSE` | | :opcode:`POP_JUMP_BACKWARD_IF_FALSE` | +| | | :opcode:`POP_JUMP_FORWARD_IF_FALSE` | ++-------------------------------------------+-------------------------------------------+ +| :opcode:`!POP_JUMP_IF_TRUE` | | :opcode:`POP_JUMP_BACKWARD_IF_TRUE` | +| | | :opcode:`POP_JUMP_FORWARD_IF_TRUE` | ++-------------------------------------------+-------------------------------------------+ +| | :opcode:`!COPY_DICT_WITHOUT_KEYS` | | +| | :opcode:`!GEN_START` | | +| | :opcode:`!POP_BLOCK` | | +| | :opcode:`!SETUP_FINALLY` | | +| | :opcode:`!YIELD_FROM` | | ++-------------------------------------------+-------------------------------------------+ + + * The bytecode now contains inline cache entries, which take the form of :opcode:`CACHE` instructions. Many opcodes expect to be followed by an exact number of caches, and instruct the interpreter to skip over them at runtime. From 650b4e45b18a598b0286cbfb88ab901583e64faf Mon Sep 17 00:00:00 2001 From: "C.A.M. Gerlach" Date: Sat, 22 Oct 2022 00:30:07 -0500 Subject: [PATCH 06/13] Merge opcode information from list into tables --- Doc/whatsnew/3.11.rst | 224 +++++++++++++++++++++--------------------- 1 file changed, 110 insertions(+), 114 deletions(-) diff --git a/Doc/whatsnew/3.11.rst b/Doc/whatsnew/3.11.rst index 9d7de75608c9bf..79b9e9a3576f00 100644 --- a/Doc/whatsnew/3.11.rst +++ b/Doc/whatsnew/3.11.rst @@ -1407,120 +1407,116 @@ contributors are volunteers from the community. CPython bytecode changes ======================== -+-------------------------------------------+-------------------------------------------+ -| Old Opcode(s) | New Opcode(s) | -+===============+===========================+===========================================+ -| | | :opcode:`ASYNC_GEN_WRAP` | -| | | :opcode:`CACHE` | -| | | :opcode:`COPY_FREE_VARS` | -| | | :opcode:`JUMP_BACKWARD_NO_INTERRUPT` | -| | | :opcode:`MAKE_CELL` | -| | | :opcode:`POP_JUMP_BACKWARD_IF_NONE` | -| | | :opcode:`POP_JUMP_BACKWARD_IF_NOT_NONE` | -| | | :opcode:`POP_JUMP_FORWARD_IF_NOT_NONE` | -| | | :opcode:`POP_JUMP_FORWARD_IF_NONE` | -| | | :opcode:`PREP_RERAISE_STAR` | -| | | :opcode:`PUSH_EXC_INFO` | -| | | :opcode:`RESUME` | -| | | :opcode:`RETURN_GENERATOR` | -| | | :opcode:`SEND` | -+-------------------------------------------+-------------------------------------------+ -| | :opcode:`!BINARY_*` | :opcode:`BINARY_OP` | -| | :opcode:`!INPLACE_*` | | -+-------------------------------------------+-------------------------------------------+ -| | :opcode:`!CALL_FUNCTION` | | :opcode:`CALL` | -| | :opcode:`!CALL_FUNCTION_KW` | | :opcode:`KW_NAMES` | -| | :opcode:`!CALL_METHOD` | | :opcode:`PRECALL` | -| | | :opcode:`PUSH_NULL` | -+-------------------------------------------+-------------------------------------------+ -| | :opcode:`!DUP_TOP` | | :opcode:`COPY` | -| | :opcode:`!DUP_TOP_TWO` | | :opcode:`SWAP` | -| | :opcode:`!ROT_TWO` | | -| | :opcode:`!ROT_THREE` | | -| | :opcode:`!ROT_FOUR` | | -| | :opcode:`!ROT_N` | | -+-------------------------------------------+-------------------------------------------+ -| :opcode:`!JUMP_ABSOLUTE` | :opcode:`JUMP_BACKWARD` | -+-------------------------------------------+-------------------------------------------+ -| :opcode:`!JUMP_IF_NOT_EXC_MATCH` | :opcode:`CHECK_EXC_MATCH` | -+-------------------------------------------+-------------------------------------------+ -| :opcode:`!JUMP_IF_NOT_EG_MATCH` | :opcode:`CHECK_EG_MATCH` | -+-------------------------------------------+-------------------------------------------+ -| :opcode:`!POP_JUMP_IF_FALSE` | | :opcode:`POP_JUMP_BACKWARD_IF_FALSE` | -| | | :opcode:`POP_JUMP_FORWARD_IF_FALSE` | -+-------------------------------------------+-------------------------------------------+ -| :opcode:`!POP_JUMP_IF_TRUE` | | :opcode:`POP_JUMP_BACKWARD_IF_TRUE` | -| | | :opcode:`POP_JUMP_FORWARD_IF_TRUE` | -+-------------------------------------------+-------------------------------------------+ -| | :opcode:`!COPY_DICT_WITHOUT_KEYS` | | -| | :opcode:`!GEN_START` | | -| | :opcode:`!POP_BLOCK` | | -| | :opcode:`!SETUP_FINALLY` | | -| | :opcode:`!YIELD_FROM` | | -+-------------------------------------------+-------------------------------------------+ - - -* The bytecode now contains inline cache entries, which take the form of - :opcode:`CACHE` instructions. Many opcodes expect to be followed by an exact - number of caches, and instruct the interpreter to skip over them at runtime. - Populated caches can look like arbitrary instructions, so great care should be - taken when reading or modifying raw, adaptive bytecode containing quickened - data. - -* Added :opcode:`COPY_FREE_VARS` to avoid needing special caller-side code - to handle calling closures. - -* Added :opcode:`JUMP_BACKWARD_NO_INTERRUPT`, - which is used in certain loops where it is undesirable to handle interrupts. - -* Added :opcode:`MAKE_CELL` to create a new :ref:`cell object `. - -* Added :opcode:`POP_JUMP_FORWARD_IF_NOT_NONE`, - :opcode:`POP_JUMP_BACKWARD_IF_NOT_NONE`, - :opcode:`POP_JUMP_FORWARD_IF_NONE` and :opcode:`POP_JUMP_BACKWARD_IF_NONE` - opcodes to speed up conditional jumps. - -* Added :opcode:`PUSH_EXC_INFO` for use in exception handlers - and :opcode:`PREP_RERAISE_STAR` for the new - :ref:`exception groups and except* `. - -* Added the :opcode:`RESUME` opcode. It is a no-op, - and performs internal tracing, debugging and optimization checks. - -* Added :opcode:`RETURN_GENERATOR`, :opcode:`SEND` and :opcode:`ASYNC_GEN_WRAP`, - used in generators and co-routines. - -* Replaced all numeric :opcode:`!BINARY_*` and :opcode:`!INPLACE_*` instructions - with a single :opcode:`BINARY_OP` implementation. - -* Replaced the three call instructions :opcode:`!CALL_FUNCTION`, - :opcode:`!CALL_FUNCTION_KW` and :opcode:`!CALL_METHOD` with - :opcode:`PUSH_NULL`, :opcode:`PRECALL`, :opcode:`CALL`, - and :opcode:`KW_NAMES`. - This decouples the argument shifting for methods from the handling of - keyword arguments and allows better specialization of calls. - -* Replaced several stack manipulation instructions - (:opcode:`!DUP_TOP`, :opcode:`!DUP_TOP_TWO`, :opcode:`!ROT_TWO`, - :opcode:`!ROT_THREE`, :opcode:`!ROT_FOUR`, and :opcode:`!ROT_N`) - with new :opcode:`COPY` and :opcode:`SWAP` instructions. - -* Replaced :opcode:`!JUMP_IF_NOT_EXC_MATCH` with :opcode:`CHECK_EXC_MATCH` - and :opcode:`!JUMP_IF_NOT_EG_MATCH` with :opcode:`CHECK_EG_MATCH`, - which perform the check but do not jump. - -* Replaced :opcode:`!JUMP_ABSOLUTE` by the relative :opcode:`JUMP_BACKWARD`. - -* Replaced :opcode:`!POP_JUMP_IF_TRUE` and :opcode:`!POP_JUMP_IF_FALSE` by - the relative :opcode:`POP_JUMP_FORWARD_IF_TRUE`, - :opcode:`POP_JUMP_BACKWARD_IF_TRUE`, - :opcode:`POP_JUMP_FORWARD_IF_FALSE` and :opcode:`POP_JUMP_BACKWARD_IF_FALSE`. - -* Replaced :opcode:`!SETUP_WITH` and :opcode:`!SETUP_ASYNC_WITH` - with :opcode:`BEFORE_WITH`. - -* Removed opcodes :opcode:`!COPY_DICT_WITHOUT_KEYS`, :opcode:`!GEN_START`, - :opcode:`!POP_BLOCK`, :opcode:`!SETUP_FINALLY` and :opcode:`!YIELD_FROM`. + + +.. _whatsnew311-added-opcodes: + +Added Opcodes +------------- + ++-------------------------------------------+-------------------------------------------------------------------------+ +| New Opcode(s) | Notes | ++===========================================+=========================================================================+ +| | :opcode:`ASYNC_GEN_WRAP` | Used in generators and co-routines | +| | :opcode:`RETURN_GENERATOR` | | +| | :opcode:`SEND` | | ++-------------------------------------------+-------------------------------------------------------------------------+ +| :opcode:`CACHE` | Inline cache entries [#opcode-cache]_ | ++-------------------------------------------+-------------------------------------------------------------------------+ +| :opcode:`COPY_FREE_VARS` | Avoids needing special caller-side code | +| | to handle calling closures | ++-------------------------------------------+-------------------------------------------------------------------------+ +| :opcode:`JUMP_BACKWARD_NO_INTERRUPT` | Used in certain loops where | +| | it is undesirable to handle interrupts | ++-------------------------------------------+-------------------------------------------------------------------------+ +| :opcode:`MAKE_CELL` | Creates new :ref:`cell-objects` | ++-------------------------------------------+-------------------------------------------------------------------------+ +| | :opcode:`POP_JUMP_BACKWARD_IF_NONE` | Speeds up conditional jumps | +| | :opcode:`POP_JUMP_BACKWARD_IF_NOT_NONE` | | +| | :opcode:`POP_JUMP_FORWARD_IF_NOT_NONE` | | +| | :opcode:`POP_JUMP_FORWARD_IF_NONE` | | ++-------------------------------------------+-------------------------------------------------------------------------+ +| :opcode:`PREP_RERAISE_STAR` | Handles the new | +| | :ref:`exception groups and except* | +| | ` | ++-------------------------------------------+-------------------------------------------------------------------------+ +| :opcode:`PUSH_EXC_INFO` | For use in exception handlers | ++-------------------------------------------+-------------------------------------------------------------------------+ +| :opcode:`RESUME` | No-op; performs internal tracing, | +| | debugging and optimization checks | ++-------------------------------------------+-------------------------------------------------------------------------+ + +.. [#opcode-cache] The bytecode now contains inline cache entries, + which take the form of :opcode:`CACHE` instructions. + Many opcodes expect to be followed by an exact number of caches, + and instruct the interpreter to skip over them at runtime. + Populated caches can look like arbitrary instructions, + so great care should be taken when reading or modifying + raw, adaptive bytecode containing quickened data. + + +.. _whatsnew311-replaced-opcodes: + +Replaced Opcodes +---------------- + ++------------------------------------+----------------------------------------+--------------------+ +| Removed Opcode(s) | New Opcode(s) | Notes | ++===============+====================+========================================+====================+ +| | :opcode:`!BINARY_*` | :opcode:`BINARY_OP` | [#opcode-binary]_ | +| | :opcode:`!INPLACE_*` | | | ++------------------------------------+----------------------------------------+--------------------+ +| | :opcode:`!CALL_FUNCTION` | | :opcode:`CALL` | [#opcode-call]_ | +| | :opcode:`!CALL_FUNCTION_KW` | | :opcode:`KW_NAMES` | | +| | :opcode:`!CALL_METHOD` | | :opcode:`PRECALL` | | +| | | :opcode:`PUSH_NULL` | | ++------------------------------------+----------------------------------------+--------------------+ +| | :opcode:`!DUP_TOP` | | :opcode:`COPY` | Stack manipulation | +| | :opcode:`!DUP_TOP_TWO` | | :opcode:`SWAP` | | +| | :opcode:`!ROT_TWO` | | | +| | :opcode:`!ROT_THREE` | | | +| | :opcode:`!ROT_FOUR` | | | +| | :opcode:`!ROT_N` | | | ++------------------------------------+----------------------------------------+--------------------+ +| :opcode:`!JUMP_ABSOLUTE` | :opcode:`JUMP_BACKWARD` | Now relative | ++------------------------------------+----------------------------------------+--------------------+ +| | :opcode:`!JUMP_IF_NOT_EXC_MATCH` | | :opcode:`CHECK_EXC_MATCH` | Now performs check | +| | :opcode:`!JUMP_IF_NOT_EG_MATCH` | | :opcode:`CHECK_EG_MATCH` | but doesn't jump | ++------------------------------------+----------------------------------------+--------------------+ +| | :opcode:`!POP_JUMP_IF_FALSE` | | :opcode:`POP_JUMP_BACKWARD_IF_FALSE` | Now relative | +| | | | :opcode:`POP_JUMP_FORWARD_IF_FALSE` | | +| | :opcode:`!POP_JUMP_IF_TRUE` | | :opcode:`POP_JUMP_BACKWARD_IF_TRUE` | | +| | | | :opcode:`POP_JUMP_FORWARD_IF_TRUE` | | ++------------------------------------+----------------------------------------+--------------------+ +| | :opcode:`!SETUP_WITH` | :opcode:`BEFORE_WITH` | :keyword:`with` | +| | :opcode:`!SETUP_ASYNC_WITH` | | block setup | ++------------------------------------+----------------------------------------+--------------------+ + +.. [#opcode-binary] Replaced all numeric :opcode:`!BINARY_*` + and :opcode:`!INPLACE_*` instructions + with a single :opcode:`BINARY_OP` implementation. + +.. [#opcode-call] Decouples the argument shifting for methods + from the handling of keyword arguments + and allows better specialization of calls. + + +.. _whatsnew311-removed-opcodes: + +Removed Opcodes +--------------- + +* :opcode:`!COPY_DICT_WITHOUT_KEYS` +* :opcode:`!GEN_START` +* :opcode:`!POP_BLOCK` +* :opcode:`!SETUP_FINALLY` +* :opcode:`!YIELD_FROM` + + +.. _whatsnew311-changed-opcodes: + +Changed Opcodes +--------------- * Changed :opcode:`JUMP_IF_TRUE_OR_POP` and :opcode:`JUMP_IF_FALSE_OR_POP` to now be relative rather than absolute. From 87e06bb5889efe6f36e30d903bfc8aebbae0b6e2 Mon Sep 17 00:00:00 2001 From: "C.A.M. Gerlach" Date: Sun, 23 Oct 2022 13:18:54 -0500 Subject: [PATCH 07/13] Add exception reprisentation change to Changed Opcodes --- Doc/whatsnew/3.11.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Doc/whatsnew/3.11.rst b/Doc/whatsnew/3.11.rst index 79b9e9a3576f00..e992beb754baf9 100644 --- a/Doc/whatsnew/3.11.rst +++ b/Doc/whatsnew/3.11.rst @@ -1527,6 +1527,10 @@ Changed Opcodes Instead, they indicate failure with ``None`` (where a tuple of extracted values would otherwise be). +* Changed opcodes that work with exceptions to reflect them + now being represented as one item on the stack instead of three + (see :gh:`89874`). + .. _whatsnew311-deprecated: .. _whatsnew311-python-api-deprecated: From 9c165b89e81946f67f4f50edb22cd28a57f237aa Mon Sep 17 00:00:00 2001 From: "C.A.M. Gerlach" Date: Sun, 23 Oct 2022 14:32:56 -0500 Subject: [PATCH 08/13] Unify & simplify added and replaced tables & entries --- Doc/whatsnew/3.11.rst | 139 +++++++++++++++++------------------------- 1 file changed, 57 insertions(+), 82 deletions(-) diff --git a/Doc/whatsnew/3.11.rst b/Doc/whatsnew/3.11.rst index e992beb754baf9..9e73e690279bf2 100644 --- a/Doc/whatsnew/3.11.rst +++ b/Doc/whatsnew/3.11.rst @@ -1407,44 +1407,65 @@ contributors are volunteers from the community. CPython bytecode changes ======================== - - .. _whatsnew311-added-opcodes: +.. _whatsnew311-replaced-opcodes: +.. _whatsnew311-added-replaced-opcodes: -Added Opcodes -------------- - -+-------------------------------------------+-------------------------------------------------------------------------+ -| New Opcode(s) | Notes | -+===========================================+=========================================================================+ -| | :opcode:`ASYNC_GEN_WRAP` | Used in generators and co-routines | -| | :opcode:`RETURN_GENERATOR` | | -| | :opcode:`SEND` | | -+-------------------------------------------+-------------------------------------------------------------------------+ -| :opcode:`CACHE` | Inline cache entries [#opcode-cache]_ | -+-------------------------------------------+-------------------------------------------------------------------------+ -| :opcode:`COPY_FREE_VARS` | Avoids needing special caller-side code | -| | to handle calling closures | -+-------------------------------------------+-------------------------------------------------------------------------+ -| :opcode:`JUMP_BACKWARD_NO_INTERRUPT` | Used in certain loops where | -| | it is undesirable to handle interrupts | -+-------------------------------------------+-------------------------------------------------------------------------+ -| :opcode:`MAKE_CELL` | Creates new :ref:`cell-objects` | -+-------------------------------------------+-------------------------------------------------------------------------+ -| | :opcode:`POP_JUMP_BACKWARD_IF_NONE` | Speeds up conditional jumps | -| | :opcode:`POP_JUMP_BACKWARD_IF_NOT_NONE` | | -| | :opcode:`POP_JUMP_FORWARD_IF_NOT_NONE` | | -| | :opcode:`POP_JUMP_FORWARD_IF_NONE` | | -+-------------------------------------------+-------------------------------------------------------------------------+ -| :opcode:`PREP_RERAISE_STAR` | Handles the new | -| | :ref:`exception groups and except* | -| | ` | -+-------------------------------------------+-------------------------------------------------------------------------+ -| :opcode:`PUSH_EXC_INFO` | For use in exception handlers | -+-------------------------------------------+-------------------------------------------------------------------------+ -| :opcode:`RESUME` | No-op; performs internal tracing, | -| | debugging and optimization checks | -+-------------------------------------------+-------------------------------------------------------------------------+ +Added/Replaced Opcodes +---------------------- + ++-------------------------------------------+------------------------------------+-----------------------------------------+ +| New Opcode(s) | Replaced Opcode(s) | Notes | ++===========================================+====================================+=========================================+ +| | :opcode:`ASYNC_GEN_WRAP` | | Used in generators and co-routines | +| | :opcode:`RETURN_GENERATOR` | | | +| | :opcode:`SEND` | | | ++-------------------------------------------+------------------------------------+-----------------------------------------+ +| :opcode:`BEFORE_WITH` | | :opcode:`!SETUP_WITH` | :keyword:`with` block setup | +| | | :opcode:`!SETUP_ASYNC_WITH` | | ++-------------------------------------------+------------------------------------+-----------------------------------------+ +| :opcode:`BINARY_OP` | | :opcode:`!BINARY_*` | Replaced all numeric binary/in-place | +| | | :opcode:`!INPLACE_*` | opcodes with a single opcode | ++-------------------------------------------+------------------------------------+-----------------------------------------+ +| :opcode:`CACHE` | | Inline cache entries [#opcode-cache]_ | ++-------------------------------------------+------------------------------------+-----------------------------------------+ +| | :opcode:`CALL` | | :opcode:`!CALL_FUNCTION` | Decouples argument shifting for methods | +| | :opcode:`KW_NAMES` | | :opcode:`!CALL_FUNCTION_KW` | from handling of keyword arguments; | +| | :opcode:`PRECALL` | | :opcode:`!CALL_METHOD` | allows better specialization of calls | +| | :opcode:`PUSH_NULL` | | | ++-------------------------------------------+------------------------------------+-----------------------------------------+ +| | :opcode:`CHECK_EXC_MATCH` | | :opcode:`!JUMP_IF_NOT_EXC_MATCH` | Now performs check | +| | :opcode:`CHECK_EG_MATCH` | | :opcode:`!JUMP_IF_NOT_EG_MATCH` | but doesn't jump | ++-------------------------------------------+------------------------------------+-----------------------------------------+ +| | :opcode:`COPY` | | :opcode:`!DUP_TOP` | Stack manipulation instructions | +| | :opcode:`SWAP` | | :opcode:`!DUP_TOP_TWO` | | +| | | :opcode:`!ROT_TWO` | | +| | | :opcode:`!ROT_THREE` | | +| | | :opcode:`!ROT_FOUR` | | +| | | :opcode:`!ROT_N` | | ++-------------------------------------------+------------------------------------+-----------------------------------------+ +| :opcode:`COPY_FREE_VARS` | | Avoids needing special caller-side code | +| | | for closures | ++-------------------------------------------+------------------------------------+-----------------------------------------+ +| :opcode:`JUMP_BACKWARD_NO_INTERRUPT` | | For certain loops where | +| | | handling interrupts is undesirable | ++-------------------------------------------+------------------------------------+-----------------------------------------+ +| | :opcode:`JUMP_BACKWARD` | | :opcode:`!JUMP_ABSOLUTE` | All jump opcodes now relative; | +| | :opcode:`POP_JUMP_BACKWARD_IF_* | | :opcode:`!POP_JUMP_IF_FALSE` | arg is offset from current instruction | +| ` | | :opcode:`!POP_JUMP_IF_TRUE` | rather than absolute location | +| | :opcode:`POP_JUMP_FORWARD_IF_* | | and most op names contain direction; | +| ` | | added ``NONE`` & ``NOT_NONE`` variants | ++-------------------------------------------+------------------------------------+-----------------------------------------+ +| :opcode:`MAKE_CELL` | | Creates new :ref:`cell-objects` | ++-------------------------------------------+------------------------------------+-----------------------------------------+ +| :opcode:`PREP_RERAISE_STAR` | | Handles the :ref:`new exception groups | +| | | ` | ++-------------------------------------------+------------------------------------+-----------------------------------------+ +| :opcode:`PUSH_EXC_INFO` | | For use in exception handlers | ++-------------------------------------------+------------------------------------+-----------------------------------------+ +| :opcode:`RESUME` | | No-op; performs internal tracing, | +| | | debugging and optimization checks | ++-------------------------------------------+------------------------------------+-----------------------------------------+ .. [#opcode-cache] The bytecode now contains inline cache entries, which take the form of :opcode:`CACHE` instructions. @@ -1455,52 +1476,6 @@ Added Opcodes raw, adaptive bytecode containing quickened data. -.. _whatsnew311-replaced-opcodes: - -Replaced Opcodes ----------------- - -+------------------------------------+----------------------------------------+--------------------+ -| Removed Opcode(s) | New Opcode(s) | Notes | -+===============+====================+========================================+====================+ -| | :opcode:`!BINARY_*` | :opcode:`BINARY_OP` | [#opcode-binary]_ | -| | :opcode:`!INPLACE_*` | | | -+------------------------------------+----------------------------------------+--------------------+ -| | :opcode:`!CALL_FUNCTION` | | :opcode:`CALL` | [#opcode-call]_ | -| | :opcode:`!CALL_FUNCTION_KW` | | :opcode:`KW_NAMES` | | -| | :opcode:`!CALL_METHOD` | | :opcode:`PRECALL` | | -| | | :opcode:`PUSH_NULL` | | -+------------------------------------+----------------------------------------+--------------------+ -| | :opcode:`!DUP_TOP` | | :opcode:`COPY` | Stack manipulation | -| | :opcode:`!DUP_TOP_TWO` | | :opcode:`SWAP` | | -| | :opcode:`!ROT_TWO` | | | -| | :opcode:`!ROT_THREE` | | | -| | :opcode:`!ROT_FOUR` | | | -| | :opcode:`!ROT_N` | | | -+------------------------------------+----------------------------------------+--------------------+ -| :opcode:`!JUMP_ABSOLUTE` | :opcode:`JUMP_BACKWARD` | Now relative | -+------------------------------------+----------------------------------------+--------------------+ -| | :opcode:`!JUMP_IF_NOT_EXC_MATCH` | | :opcode:`CHECK_EXC_MATCH` | Now performs check | -| | :opcode:`!JUMP_IF_NOT_EG_MATCH` | | :opcode:`CHECK_EG_MATCH` | but doesn't jump | -+------------------------------------+----------------------------------------+--------------------+ -| | :opcode:`!POP_JUMP_IF_FALSE` | | :opcode:`POP_JUMP_BACKWARD_IF_FALSE` | Now relative | -| | | | :opcode:`POP_JUMP_FORWARD_IF_FALSE` | | -| | :opcode:`!POP_JUMP_IF_TRUE` | | :opcode:`POP_JUMP_BACKWARD_IF_TRUE` | | -| | | | :opcode:`POP_JUMP_FORWARD_IF_TRUE` | | -+------------------------------------+----------------------------------------+--------------------+ -| | :opcode:`!SETUP_WITH` | :opcode:`BEFORE_WITH` | :keyword:`with` | -| | :opcode:`!SETUP_ASYNC_WITH` | | block setup | -+------------------------------------+----------------------------------------+--------------------+ - -.. [#opcode-binary] Replaced all numeric :opcode:`!BINARY_*` - and :opcode:`!INPLACE_*` instructions - with a single :opcode:`BINARY_OP` implementation. - -.. [#opcode-call] Decouples the argument shifting for methods - from the handling of keyword arguments - and allows better specialization of calls. - - .. _whatsnew311-removed-opcodes: Removed Opcodes From 1e0d7cb939c7233ccd5d8b512c1a4fee5859d56e Mon Sep 17 00:00:00 2001 From: "C.A.M. Gerlach" Date: Sun, 23 Oct 2022 14:49:05 -0500 Subject: [PATCH 09/13] Move added opcodes out of table into a bulleted list instead --- Doc/whatsnew/3.11.rst | 129 +++++++++++++++++++++--------------------- 1 file changed, 66 insertions(+), 63 deletions(-) diff --git a/Doc/whatsnew/3.11.rst b/Doc/whatsnew/3.11.rst index 9e73e690279bf2..e4d6d753027368 100644 --- a/Doc/whatsnew/3.11.rst +++ b/Doc/whatsnew/3.11.rst @@ -1407,73 +1407,76 @@ contributors are volunteers from the community. CPython bytecode changes ======================== +The bytecode now contains inline cache entries, +which take the form of the newly-added :opcode:`CACHE` instructions. +Many opcodes expect to be followed by an exact number of caches, +and instruct the interpreter to skip over them at runtime. +Populated caches can look like arbitrary instructions, +so great care should be taken when reading or modifying +raw, adaptive bytecode containing quickened data. + + .. _whatsnew311-added-opcodes: + +New opcodes +----------- + +* :opcode:`ASYNC_GEN_WRAP`, :opcode:`RETURN_GENERATOR` and :opcode:`SEND`, + used in generators and co-routines. + +* :opcode:`COPY_FREE_VARS`, + which avoids needing special caller-side code for closures. + +* :opcode:`JUMP_BACKWARD_NO_INTERRUPT`, + for use in certain loops where handling interrupts is undesirable. + +* :opcode:`MAKE_CELL`, to create :ref:`cell-objects`. + +* :opcode:`PREP_RERAISE_STAR`, + to handle the :ref:`new exception groups and except* ` + added in :pep:`654`. + +* :opcode:`PUSH_EXC_INFO`, for use in exception handlers. + +* :opcode:`RESUME`, a no-op, + for internal tracing, debugging and optimization checks. + + .. _whatsnew311-replaced-opcodes: -.. _whatsnew311-added-replaced-opcodes: -Added/Replaced Opcodes ----------------------- +Replaced opcodes +---------------- -+-------------------------------------------+------------------------------------+-----------------------------------------+ -| New Opcode(s) | Replaced Opcode(s) | Notes | -+===========================================+====================================+=========================================+ -| | :opcode:`ASYNC_GEN_WRAP` | | Used in generators and co-routines | -| | :opcode:`RETURN_GENERATOR` | | | -| | :opcode:`SEND` | | | -+-------------------------------------------+------------------------------------+-----------------------------------------+ -| :opcode:`BEFORE_WITH` | | :opcode:`!SETUP_WITH` | :keyword:`with` block setup | -| | | :opcode:`!SETUP_ASYNC_WITH` | | -+-------------------------------------------+------------------------------------+-----------------------------------------+ -| :opcode:`BINARY_OP` | | :opcode:`!BINARY_*` | Replaced all numeric binary/in-place | -| | | :opcode:`!INPLACE_*` | opcodes with a single opcode | -+-------------------------------------------+------------------------------------+-----------------------------------------+ -| :opcode:`CACHE` | | Inline cache entries [#opcode-cache]_ | -+-------------------------------------------+------------------------------------+-----------------------------------------+ -| | :opcode:`CALL` | | :opcode:`!CALL_FUNCTION` | Decouples argument shifting for methods | -| | :opcode:`KW_NAMES` | | :opcode:`!CALL_FUNCTION_KW` | from handling of keyword arguments; | -| | :opcode:`PRECALL` | | :opcode:`!CALL_METHOD` | allows better specialization of calls | -| | :opcode:`PUSH_NULL` | | | -+-------------------------------------------+------------------------------------+-----------------------------------------+ -| | :opcode:`CHECK_EXC_MATCH` | | :opcode:`!JUMP_IF_NOT_EXC_MATCH` | Now performs check | -| | :opcode:`CHECK_EG_MATCH` | | :opcode:`!JUMP_IF_NOT_EG_MATCH` | but doesn't jump | -+-------------------------------------------+------------------------------------+-----------------------------------------+ -| | :opcode:`COPY` | | :opcode:`!DUP_TOP` | Stack manipulation instructions | -| | :opcode:`SWAP` | | :opcode:`!DUP_TOP_TWO` | | -| | | :opcode:`!ROT_TWO` | | -| | | :opcode:`!ROT_THREE` | | -| | | :opcode:`!ROT_FOUR` | | -| | | :opcode:`!ROT_N` | | -+-------------------------------------------+------------------------------------+-----------------------------------------+ -| :opcode:`COPY_FREE_VARS` | | Avoids needing special caller-side code | -| | | for closures | -+-------------------------------------------+------------------------------------+-----------------------------------------+ -| :opcode:`JUMP_BACKWARD_NO_INTERRUPT` | | For certain loops where | -| | | handling interrupts is undesirable | -+-------------------------------------------+------------------------------------+-----------------------------------------+ -| | :opcode:`JUMP_BACKWARD` | | :opcode:`!JUMP_ABSOLUTE` | All jump opcodes now relative; | -| | :opcode:`POP_JUMP_BACKWARD_IF_* | | :opcode:`!POP_JUMP_IF_FALSE` | arg is offset from current instruction | -| ` | | :opcode:`!POP_JUMP_IF_TRUE` | rather than absolute location | -| | :opcode:`POP_JUMP_FORWARD_IF_* | | and most op names contain direction; | -| ` | | added ``NONE`` & ``NOT_NONE`` variants | -+-------------------------------------------+------------------------------------+-----------------------------------------+ -| :opcode:`MAKE_CELL` | | Creates new :ref:`cell-objects` | -+-------------------------------------------+------------------------------------+-----------------------------------------+ -| :opcode:`PREP_RERAISE_STAR` | | Handles the :ref:`new exception groups | -| | | ` | -+-------------------------------------------+------------------------------------+-----------------------------------------+ -| :opcode:`PUSH_EXC_INFO` | | For use in exception handlers | -+-------------------------------------------+------------------------------------+-----------------------------------------+ -| :opcode:`RESUME` | | No-op; performs internal tracing, | -| | | debugging and optimization checks | -+-------------------------------------------+------------------------------------+-----------------------------------------+ - -.. [#opcode-cache] The bytecode now contains inline cache entries, - which take the form of :opcode:`CACHE` instructions. - Many opcodes expect to be followed by an exact number of caches, - and instruct the interpreter to skip over them at runtime. - Populated caches can look like arbitrary instructions, - so great care should be taken when reading or modifying - raw, adaptive bytecode containing quickened data. ++-----------------------------------+------------------------------------+-----------------------------------------+ +| New Opcode(s) | Replaced Opcode(s) | Notes | ++===================================+====================================+=========================================+ +| :opcode:`BEFORE_WITH` | | :opcode:`!SETUP_WITH` | :keyword:`with` block setup | +| | | :opcode:`!SETUP_ASYNC_WITH` | | ++-----------------------------------+------------------------------------+-----------------------------------------+ +| :opcode:`BINARY_OP` | | :opcode:`!BINARY_*` | Replaced all numeric binary/in-place | +| | | :opcode:`!INPLACE_*` | opcodes with a single opcode | ++-----------------------------------+------------------------------------+-----------------------------------------+ +| | :opcode:`CALL` | | :opcode:`!CALL_FUNCTION` | Decouples argument shifting for methods | +| | :opcode:`KW_NAMES` | | :opcode:`!CALL_FUNCTION_KW` | from handling of keyword arguments; | +| | :opcode:`PRECALL` | | :opcode:`!CALL_METHOD` | allows better specialization of calls | +| | :opcode:`PUSH_NULL` | | | ++-----------------------------------+------------------------------------+-----------------------------------------+ +| | :opcode:`CHECK_EXC_MATCH` | | :opcode:`!JUMP_IF_NOT_EXC_MATCH` | Now performs check | +| | :opcode:`CHECK_EG_MATCH` | | :opcode:`!JUMP_IF_NOT_EG_MATCH` | but doesn't jump | ++-----------------------------------+------------------------------------+-----------------------------------------+ +| | :opcode:`COPY` | | :opcode:`!DUP_TOP` | Stack manipulation instructions | +| | :opcode:`SWAP` | | :opcode:`!DUP_TOP_TWO` | | +| | | :opcode:`!ROT_TWO` | | +| | | :opcode:`!ROT_THREE` | | +| | | :opcode:`!ROT_FOUR` | | +| | | :opcode:`!ROT_N` | | ++-----------------------------------+------------------------------------+-----------------------------------------+ +| | :opcode:`JUMP_BACKWARD` | | :opcode:`!JUMP_ABSOLUTE` | All jump opcodes now relative; | +| | :opcode:`POP_JUMP_BACKWARD_IF_* | | :opcode:`!POP_JUMP_IF_FALSE` | arg is offset from current instruction | +| ` | | :opcode:`!POP_JUMP_IF_TRUE` | rather than absolute location | +| | :opcode:`POP_JUMP_FORWARD_IF_* | | and most op names contain direction; | +| ` | | added ``NONE`` & ``NOT_NONE`` variants | ++-----------------------------------+------------------------------------+-----------------------------------------+ .. _whatsnew311-removed-opcodes: From a0b90d820a70c2e932dc76ea984e038a0d1532e8 Mon Sep 17 00:00:00 2001 From: "C.A.M. Gerlach" Date: Sun, 23 Oct 2022 15:04:34 -0500 Subject: [PATCH 10/13] Re-order Replaced Opcodes table by replaced opcode --- Doc/whatsnew/3.11.rst | 60 +++++++++++++++++++++---------------------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/Doc/whatsnew/3.11.rst b/Doc/whatsnew/3.11.rst index e4d6d753027368..e204f46a64f0b5 100644 --- a/Doc/whatsnew/3.11.rst +++ b/Doc/whatsnew/3.11.rst @@ -1447,36 +1447,36 @@ New opcodes Replaced opcodes ---------------- -+-----------------------------------+------------------------------------+-----------------------------------------+ -| New Opcode(s) | Replaced Opcode(s) | Notes | -+===================================+====================================+=========================================+ -| :opcode:`BEFORE_WITH` | | :opcode:`!SETUP_WITH` | :keyword:`with` block setup | -| | | :opcode:`!SETUP_ASYNC_WITH` | | -+-----------------------------------+------------------------------------+-----------------------------------------+ -| :opcode:`BINARY_OP` | | :opcode:`!BINARY_*` | Replaced all numeric binary/in-place | -| | | :opcode:`!INPLACE_*` | opcodes with a single opcode | -+-----------------------------------+------------------------------------+-----------------------------------------+ -| | :opcode:`CALL` | | :opcode:`!CALL_FUNCTION` | Decouples argument shifting for methods | -| | :opcode:`KW_NAMES` | | :opcode:`!CALL_FUNCTION_KW` | from handling of keyword arguments; | -| | :opcode:`PRECALL` | | :opcode:`!CALL_METHOD` | allows better specialization of calls | -| | :opcode:`PUSH_NULL` | | | -+-----------------------------------+------------------------------------+-----------------------------------------+ -| | :opcode:`CHECK_EXC_MATCH` | | :opcode:`!JUMP_IF_NOT_EXC_MATCH` | Now performs check | -| | :opcode:`CHECK_EG_MATCH` | | :opcode:`!JUMP_IF_NOT_EG_MATCH` | but doesn't jump | -+-----------------------------------+------------------------------------+-----------------------------------------+ -| | :opcode:`COPY` | | :opcode:`!DUP_TOP` | Stack manipulation instructions | -| | :opcode:`SWAP` | | :opcode:`!DUP_TOP_TWO` | | -| | | :opcode:`!ROT_TWO` | | -| | | :opcode:`!ROT_THREE` | | -| | | :opcode:`!ROT_FOUR` | | -| | | :opcode:`!ROT_N` | | -+-----------------------------------+------------------------------------+-----------------------------------------+ -| | :opcode:`JUMP_BACKWARD` | | :opcode:`!JUMP_ABSOLUTE` | All jump opcodes now relative; | -| | :opcode:`POP_JUMP_BACKWARD_IF_* | | :opcode:`!POP_JUMP_IF_FALSE` | arg is offset from current instruction | -| ` | | :opcode:`!POP_JUMP_IF_TRUE` | rather than absolute location | -| | :opcode:`POP_JUMP_FORWARD_IF_* | | and most op names contain direction; | -| ` | | added ``NONE`` & ``NOT_NONE`` variants | -+-----------------------------------+------------------------------------+-----------------------------------------+ ++------------------------------------+-----------------------------------+-----------------------------------------+ +| Replaced Opcode(s) | New Opcode(s) | Notes | ++====================================+===================================+=========================================+ +| | :opcode:`!BINARY_*` | :opcode:`BINARY_OP` | Replaced all numeric binary/in-place | +| | :opcode:`!INPLACE_*` | | opcodes with a single opcode | ++------------------------------------+-----------------------------------+-----------------------------------------+ +| | :opcode:`!CALL_FUNCTION` | | :opcode:`CALL` | Decouples argument shifting for methods | +| | :opcode:`!CALL_FUNCTION_KW` | | :opcode:`KW_NAMES` | from handling of keyword arguments; | +| | :opcode:`!CALL_METHOD` | | :opcode:`PRECALL` | allows better specialization of calls | +| | | :opcode:`PUSH_NULL` | | ++------------------------------------+-----------------------------------+-----------------------------------------+ +| | :opcode:`!DUP_TOP` | | :opcode:`COPY` | Stack manipulation instructions | +| | :opcode:`!DUP_TOP_TWO` | | :opcode:`SWAP` | | +| | :opcode:`!ROT_TWO` | | | +| | :opcode:`!ROT_THREE` | | | +| | :opcode:`!ROT_FOUR` | | | +| | :opcode:`!ROT_N` | | | ++------------------------------------+-----------------------------------+-----------------------------------------+ +| | :opcode:`!JUMP_IF_NOT_EXC_MATCH` | | :opcode:`CHECK_EXC_MATCH` | Now performs check but doesn't jump | +| | :opcode:`!JUMP_IF_NOT_EG_MATCH` | | :opcode:`CHECK_EG_MATCH` | | ++------------------------------------+-----------------------------------+-----------------------------------------+ +| | :opcode:`!JUMP_ABSOLUTE` | | :opcode:`JUMP_BACKWARD` | All jump opcodes now relative; | +| | :opcode:`!POP_JUMP_IF_FALSE` | | :opcode:`POP_JUMP_BACKWARD_IF_* | arg is offset from current instruction | +| | :opcode:`!POP_JUMP_IF_TRUE` | ` | rather than absolute location; | +| | | :opcode:`POP_JUMP_FORWARD_IF_* | added ``NONE`` & ``NOT_NONE`` variants | +| | ` | | ++------------------------------------+-----------------------------------+-----------------------------------------+ +| | :opcode:`!SETUP_WITH` | :opcode:`BEFORE_WITH` | :keyword:`with` block setup | +| | :opcode:`!SETUP_ASYNC_WITH` | | | ++------------------------------------+-----------------------------------+-----------------------------------------+ .. _whatsnew311-removed-opcodes: From 4ed6cfb7950f0f3bab4a48edb079e1c727de6b85 Mon Sep 17 00:00:00 2001 From: "C.A.M. Gerlach" Date: Sun, 23 Oct 2022 15:17:19 -0500 Subject: [PATCH 11/13] Consolidate changed and removed sections to be more concise --- Doc/whatsnew/3.11.rst | 30 +++++++++++------------------- 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/Doc/whatsnew/3.11.rst b/Doc/whatsnew/3.11.rst index e204f46a64f0b5..3c4c4446f0df77 100644 --- a/Doc/whatsnew/3.11.rst +++ b/Doc/whatsnew/3.11.rst @@ -1479,36 +1479,28 @@ Replaced opcodes +------------------------------------+-----------------------------------+-----------------------------------------+ -.. _whatsnew311-removed-opcodes: - -Removed Opcodes ---------------- - -* :opcode:`!COPY_DICT_WITHOUT_KEYS` -* :opcode:`!GEN_START` -* :opcode:`!POP_BLOCK` -* :opcode:`!SETUP_FINALLY` -* :opcode:`!YIELD_FROM` - - .. _whatsnew311-changed-opcodes: +.. _whatsnew311-removed-opcodes: +.. _whatsnew311-changed-removed-opcodes: -Changed Opcodes ---------------- +Changed/removed opcodes +----------------------- * Changed :opcode:`JUMP_IF_TRUE_OR_POP` and :opcode:`JUMP_IF_FALSE_OR_POP` - to now be relative rather than absolute. + to be relative rather than absolute. * Changed :opcode:`MATCH_CLASS` and :opcode:`MATCH_KEYS` - to no longer push an additional boolean value - indicating whether the match succeeded or failed. - Instead, they indicate failure with ``None`` - (where a tuple of extracted values would otherwise be). + to no longer push an additional boolean value to indicate success/failure. + Instead, ``None`` is pushed on failure + in place of the tuple of extracted values. * Changed opcodes that work with exceptions to reflect them now being represented as one item on the stack instead of three (see :gh:`89874`). +* Removed :opcode:`!COPY_DICT_WITHOUT_KEYS`, :opcode:`!GEN_START`, + :opcode:`!POP_BLOCK`, :opcode:`!SETUP_FINALLY` and :opcode:`!YIELD_FROM`. + .. _whatsnew311-deprecated: .. _whatsnew311-python-api-deprecated: From 7c94ab031c4210fe2df80e9db9e626ad7fbc0aca Mon Sep 17 00:00:00 2001 From: "C.A.M. Gerlach" Date: Sun, 23 Oct 2022 15:42:32 -0500 Subject: [PATCH 12/13] Consolidate jump opcode changes further --- Doc/whatsnew/3.11.rst | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/Doc/whatsnew/3.11.rst b/Doc/whatsnew/3.11.rst index 3c4c4446f0df77..91f7da71c9ff0a 100644 --- a/Doc/whatsnew/3.11.rst +++ b/Doc/whatsnew/3.11.rst @@ -1468,16 +1468,21 @@ Replaced opcodes | | :opcode:`!JUMP_IF_NOT_EXC_MATCH` | | :opcode:`CHECK_EXC_MATCH` | Now performs check but doesn't jump | | | :opcode:`!JUMP_IF_NOT_EG_MATCH` | | :opcode:`CHECK_EG_MATCH` | | +------------------------------------+-----------------------------------+-----------------------------------------+ -| | :opcode:`!JUMP_ABSOLUTE` | | :opcode:`JUMP_BACKWARD` | All jump opcodes now relative; | -| | :opcode:`!POP_JUMP_IF_FALSE` | | :opcode:`POP_JUMP_BACKWARD_IF_* | arg is offset from current instruction | -| | :opcode:`!POP_JUMP_IF_TRUE` | ` | rather than absolute location; | -| | | :opcode:`POP_JUMP_FORWARD_IF_* | added ``NONE`` & ``NOT_NONE`` variants | +| | :opcode:`!JUMP_ABSOLUTE` | | :opcode:`JUMP_BACKWARD` | See [#bytecode-jump]_; | +| | :opcode:`!POP_JUMP_IF_FALSE` | | :opcode:`POP_JUMP_BACKWARD_IF_* | ``TRUE``, ``FALSE``, | +| | :opcode:`!POP_JUMP_IF_TRUE` | ` | ``NONE`` and ``NOT_NONE`` variants | +| | | :opcode:`POP_JUMP_FORWARD_IF_* | for each direction | | | ` | | +------------------------------------+-----------------------------------+-----------------------------------------+ | | :opcode:`!SETUP_WITH` | :opcode:`BEFORE_WITH` | :keyword:`with` block setup | | | :opcode:`!SETUP_ASYNC_WITH` | | | +------------------------------------+-----------------------------------+-----------------------------------------+ +.. [#bytecode-jump] All jump opcodes are now relative, including the + existing :opcode:`JUMP_IF_TRUE_OR_POP` and :opcode:`JUMP_IF_FALSE_OR_POP`. + The argument is now an offset from the current instruction + rather than an absolute location. + .. _whatsnew311-changed-opcodes: .. _whatsnew311-removed-opcodes: @@ -1486,9 +1491,6 @@ Replaced opcodes Changed/removed opcodes ----------------------- -* Changed :opcode:`JUMP_IF_TRUE_OR_POP` and :opcode:`JUMP_IF_FALSE_OR_POP` - to be relative rather than absolute. - * Changed :opcode:`MATCH_CLASS` and :opcode:`MATCH_KEYS` to no longer push an additional boolean value to indicate success/failure. Instead, ``None`` is pushed on failure From c1a774314d4785809feae46bf0a6c4b209f3e9ba Mon Sep 17 00:00:00 2001 From: Irit Katriel <1055913+iritkatriel@users.noreply.github.com> Date: Mon, 24 Oct 2022 13:35:10 +0100 Subject: [PATCH 13/13] CHECK_EG_MATCH is new --- Doc/whatsnew/3.11.rst | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Doc/whatsnew/3.11.rst b/Doc/whatsnew/3.11.rst index 91f7da71c9ff0a..929aef08e923de 100644 --- a/Doc/whatsnew/3.11.rst +++ b/Doc/whatsnew/3.11.rst @@ -1432,7 +1432,7 @@ New opcodes * :opcode:`MAKE_CELL`, to create :ref:`cell-objects`. -* :opcode:`PREP_RERAISE_STAR`, +* :opcode:`CHECK_EG_MATCH` and :opcode:`PREP_RERAISE_STAR`, to handle the :ref:`new exception groups and except* ` added in :pep:`654`. @@ -1466,7 +1466,6 @@ Replaced opcodes | | :opcode:`!ROT_N` | | | +------------------------------------+-----------------------------------+-----------------------------------------+ | | :opcode:`!JUMP_IF_NOT_EXC_MATCH` | | :opcode:`CHECK_EXC_MATCH` | Now performs check but doesn't jump | -| | :opcode:`!JUMP_IF_NOT_EG_MATCH` | | :opcode:`CHECK_EG_MATCH` | | +------------------------------------+-----------------------------------+-----------------------------------------+ | | :opcode:`!JUMP_ABSOLUTE` | | :opcode:`JUMP_BACKWARD` | See [#bytecode-jump]_; | | | :opcode:`!POP_JUMP_IF_FALSE` | | :opcode:`POP_JUMP_BACKWARD_IF_* | ``TRUE``, ``FALSE``, |