From e8c6528cc4915b9ed6d5047566b94c2ba8960a4e Mon Sep 17 00:00:00 2001 From: Brandt Bucher Date: Thu, 4 Aug 2022 19:28:38 -0700 Subject: [PATCH 1/2] Add docs for CACHE --- Doc/library/dis.rst | 18 ++++++++++++++++++ Doc/whatsnew/3.11.rst | 7 +++++++ 2 files changed, 25 insertions(+) diff --git a/Doc/library/dis.rst b/Doc/library/dis.rst index 68c3d1c0a4b24b..63b064e7b444ec 100644 --- a/Doc/library/dis.rst +++ b/Doc/library/dis.rst @@ -408,6 +408,24 @@ The Python compiler currently generates the following bytecode instructions. .. versionadded:: 3.11 +.. opcode:: CACHE + + Rather than being an actual instruction, this opcode is used to mark extra + space for the interpreter to cache useful data directly in the bytecode + itself. It is automatically hidden by all ``dis`` utilities, but can be + viewed with ``show_caches=True``. + + Logically, this space is part of the preceding instruction. Many opcodes + expect to be followed by an exact number of caches, and will 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. + + .. versionadded:: 3.11 + + **Unary operations** Unary operations take the top of the stack, apply the operation, and push the diff --git a/Doc/whatsnew/3.11.rst b/Doc/whatsnew/3.11.rst index c976eddb08ba08..143cf7f409946c 100644 --- a/Doc/whatsnew/3.11.rst +++ b/Doc/whatsnew/3.11.rst @@ -1165,6 +1165,13 @@ contributors are volunteers from the community. CPython bytecode changes ======================== +* The bytecode now contains inline cache entries, which take the form of + :opcode:`CACHE` instructions. Many opcodes expect to be followed by 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. + * Replaced all numeric ``BINARY_*`` and ``INPLACE_*`` instructions with a single :opcode:`BINARY_OP` implementation. From 9544955e485dc3e650b800a12eb70d9a50102adc Mon Sep 17 00:00:00 2001 From: Brandt Bucher Date: Thu, 4 Aug 2022 22:35:10 -0700 Subject: [PATCH 2/2] fixup --- Doc/whatsnew/3.11.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/whatsnew/3.11.rst b/Doc/whatsnew/3.11.rst index 143cf7f409946c..f5d5d5f2be06a0 100644 --- a/Doc/whatsnew/3.11.rst +++ b/Doc/whatsnew/3.11.rst @@ -1166,7 +1166,7 @@ CPython bytecode changes ======================== * The bytecode now contains inline cache entries, which take the form of - :opcode:`CACHE` instructions. Many opcodes expect to be followed by exact + :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