Skip to content

Commit ae838af

Browse files
[3.12] gh-107457: update dis documentation with changes in 3.12 (GH-108900) (#110985)
gh-107457: update dis documentation with changes in 3.12 (GH-108900) (cherry picked from commit 198aa67) Co-authored-by: Matthieu Dartiailh <[email protected]>
1 parent f0c2390 commit ae838af

File tree

1 file changed

+43
-16
lines changed

1 file changed

+43
-16
lines changed

Doc/library/dis.rst

Lines changed: 43 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,14 @@ interpreter.
4242
bytecode to specialize it for different runtime conditions. The
4343
adaptive bytecode can be shown by passing ``adaptive=True``.
4444

45+
.. versionchanged:: 3.12
46+
The argument of a jump is the offset of the target instruction relative
47+
to the instruction that appears immediately after the jump instruction's
48+
:opcode:`CACHE` entries.
49+
50+
As a consequence, the presence of the :opcode:`CACHE` instructions is
51+
transparent for forward jumps but needs to be taken into account when
52+
reasoning about backward jumps.
4553

4654
Example: Given the function :func:`!myfunc`::
4755

@@ -450,6 +458,14 @@ operations on it as if it was a Python list. The top of the stack corresponds to
450458
.. versionadded:: 3.12
451459

452460

461+
.. opcode:: END_SEND
462+
463+
Implements ``del STACK[-2]``.
464+
Used to clean up when a generator exits.
465+
466+
.. versionadded:: 3.12
467+
468+
453469
.. opcode:: COPY (i)
454470

455471
Push the i-th item to the top of the stack without removing it from its original
@@ -1085,15 +1101,21 @@ iterations of the loop.
10851101

10861102
.. opcode:: LOAD_SUPER_ATTR (namei)
10871103

1088-
This opcode implements :func:`super` (e.g. ``super().method()`` and
1089-
``super().attr``). It works the same as :opcode:`LOAD_ATTR`, except that
1090-
``namei`` is shifted left by 2 bits instead of 1, and instead of expecting a
1091-
single receiver on the stack, it expects three objects (from top of stack
1092-
down): ``self`` (the first argument to the current method), ``cls`` (the
1093-
class within which the current method was defined), and the global ``super``.
1104+
This opcode implements :func:`super`, both in its zero-argument and
1105+
two-argument forms (e.g. ``super().method()``, ``super().attr`` and
1106+
``super(cls, self).method()``, ``super(cls, self).attr``).
1107+
1108+
It pops three values from the stack (from top of stack down):
1109+
- ``self``: the first argument to the current method
1110+
- ``cls``: the class within which the current method was defined
1111+
- the global ``super``
1112+
1113+
With respect to its argument, it works similarly to :opcode:`LOAD_ATTR`,
1114+
except that ``namei`` is shifted left by 2 bits instead of 1.
10941115

10951116
The low bit of ``namei`` signals to attempt a method load, as with
1096-
:opcode:`LOAD_ATTR`.
1117+
:opcode:`LOAD_ATTR`, which results in pushing ``None`` and the loaded method.
1118+
When it is unset a single value is pushed to the stack.
10971119

10981120
The second-low bit of ``namei``, if set, means that this was a two-argument
10991121
call to :func:`super` (unset means zero-argument).
@@ -1520,9 +1542,9 @@ iterations of the loop.
15201542
Equivalent to ``STACK[-1] = STACK[-2].send(STACK[-1])``. Used in ``yield from``
15211543
and ``await`` statements.
15221544

1523-
If the call raises :exc:`StopIteration`, pop both items, push the
1524-
exception's ``value`` attribute, and increment the bytecode counter by
1525-
*delta*.
1545+
If the call raises :exc:`StopIteration`, pop the top value from the stack,
1546+
push the exception's ``value`` attribute, and increment the bytecode counter
1547+
by *delta*.
15261548

15271549
.. versionadded:: 3.11
15281550

@@ -1550,7 +1572,7 @@ iterations of the loop.
15501572

15511573
Calls an intrinsic function with one argument. Passes ``STACK[-1]`` as the
15521574
argument and sets ``STACK[-1]`` to the result. Used to implement
1553-
functionality that is necessary but not performance critical.
1575+
functionality that is not performance critical.
15541576

15551577
The operand determines which intrinsic function is called:
15561578

@@ -1598,9 +1620,13 @@ iterations of the loop.
15981620

15991621
.. opcode:: CALL_INTRINSIC_2
16001622

1601-
Calls an intrinsic function with two arguments. Passes ``STACK[-2]``, ``STACK[-1]`` as the
1602-
arguments and sets ``STACK[-1]`` to the result. Used to implement functionality that is
1603-
necessary but not performance critical.
1623+
Calls an intrinsic function with two arguments. Used to implement functionality
1624+
that is not performance critical::
1625+
1626+
arg2 = STACK.pop()
1627+
arg1 = STACK.pop()
1628+
result = intrinsic2(arg1, arg2)
1629+
STACK.push(result)
16041630

16051631
The operand determines which intrinsic function is called:
16061632

@@ -1685,8 +1711,9 @@ These collections are provided for automatic introspection of bytecode
16851711
instructions:
16861712

16871713
.. versionchanged:: 3.12
1688-
The collections now contain pseudo instructions as well. These are
1689-
opcodes with values ``>= MIN_PSEUDO_OPCODE``.
1714+
The collections now contain pseudo instructions and instrumented
1715+
instructions as well. These are opcodes with values ``>= MIN_PSEUDO_OPCODE``
1716+
and ``>= MIN_INSTRUMENTED_OPCODE``.
16901717

16911718
.. data:: opname
16921719

0 commit comments

Comments
 (0)