[Python-checkins] GH-90997: Document CACHEs (GH-95694) (GH-95696)

ambv webhook-mailer at python.org
Fri Aug 5 03:42:54 EDT 2022


https://github.com/python/cpython/commit/07d97c9e5d674d5d309e789014dbe59cabf7a7dd
commit: 07d97c9e5d674d5d309e789014dbe59cabf7a7dd
branch: 3.11
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: ambv <lukasz at langa.pl>
date: 2022-08-05T09:42:49+02:00
summary:

GH-90997: Document CACHEs (GH-95694) (GH-95696)

(cherry picked from commit 5f3c9fda1825737fa7b671b995f84a8ab9a4adb8)

Co-authored-by: Brandt Bucher <brandtbucher at gmail.com>

files:
M Doc/library/dis.rst
M Doc/whatsnew/3.11.rst

diff --git a/Doc/library/dis.rst b/Doc/library/dis.rst
index c303ab9a1ff8..f7989ea43dac 100644
--- a/Doc/library/dis.rst
+++ b/Doc/library/dis.rst
@@ -410,6 +410,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 c57f8a0f3e9f..0ba88532442d 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 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.
+
 * Replaced all numeric ``BINARY_*`` and ``INPLACE_*`` instructions with a single
   :opcode:`BINARY_OP` implementation.
 



More information about the Python-checkins mailing list