Skip to content

Commit 07d97c9

Browse files
GH-90997: Document CACHEs (GH-95694) (GH-95696)
(cherry picked from commit 5f3c9fd) Co-authored-by: Brandt Bucher <[email protected]>
1 parent 4512a16 commit 07d97c9

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

Doc/library/dis.rst

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,24 @@ The Python compiler currently generates the following bytecode instructions.
410410
.. versionadded:: 3.11
411411

412412

413+
.. opcode:: CACHE
414+
415+
Rather than being an actual instruction, this opcode is used to mark extra
416+
space for the interpreter to cache useful data directly in the bytecode
417+
itself. It is automatically hidden by all ``dis`` utilities, but can be
418+
viewed with ``show_caches=True``.
419+
420+
Logically, this space is part of the preceding instruction. Many opcodes
421+
expect to be followed by an exact number of caches, and will instruct the
422+
interpreter to skip over them at runtime.
423+
424+
Populated caches can look like arbitrary instructions, so great care should
425+
be taken when reading or modifying raw, adaptive bytecode containing
426+
quickened data.
427+
428+
.. versionadded:: 3.11
429+
430+
413431
**Unary operations**
414432

415433
Unary operations take the top of the stack, apply the operation, and push the

Doc/whatsnew/3.11.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1165,6 +1165,13 @@ contributors are volunteers from the community.
11651165
CPython bytecode changes
11661166
========================
11671167

1168+
* The bytecode now contains inline cache entries, which take the form of
1169+
:opcode:`CACHE` instructions. Many opcodes expect to be followed by an exact
1170+
number of caches, and instruct the interpreter to skip over them at runtime.
1171+
Populated caches can look like arbitrary instructions, so great care should be
1172+
taken when reading or modifying raw, adaptive bytecode containing quickened
1173+
data.
1174+
11681175
* Replaced all numeric ``BINARY_*`` and ``INPLACE_*`` instructions with a single
11691176
:opcode:`BINARY_OP` implementation.
11701177

0 commit comments

Comments
 (0)