Skip to content

gh-114212:Note 3.13 stack order change for LOAD_GLOBAL/LOAD_ATTR/LOAD_SUPER_ATTR #137909

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions Doc/library/dis.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1259,13 +1259,18 @@ iterations of the loop.
correct name, the bytecode pushes the unbound method and ``STACK[-1]``.
``STACK[-1]`` will be used as the first argument (``self``) by :opcode:`CALL`
or :opcode:`CALL_KW` when calling the unbound method.
Otherwise, ``NULL`` and the object returned by
the attribute lookup are pushed.
Otherwise, the object returned by the attribute lookup and ``NULL`` are
pushed (in that order).

.. versionchanged:: 3.12
If the low bit of ``namei`` is set, then a ``NULL`` or ``self`` is
If the low bit of ``namei`` is set, then a ``NULL`` or ``self`` was
pushed to the stack before the attribute or unbound method respectively.

.. versionchanged:: 3.13
The push order changed to keep the callable at a fixed stack position for
:opcode:`CALL`: the attribute or unbound method is now pushed before the
``NULL``/``self`` marker (previously the marker was pushed first).


.. opcode:: LOAD_SUPER_ATTR (namei)

Expand All @@ -1283,14 +1288,20 @@ iterations of the loop.
except that ``namei`` is shifted left by 2 bits instead of 1.

The low bit of ``namei`` signals to attempt a method load, as with
:opcode:`LOAD_ATTR`, which results in pushing ``NULL`` and the loaded method.
:opcode:`LOAD_ATTR`, which results in pushing the loaded method and ``NULL``
(in that order).
When it is unset a single value is pushed to the stack.

The second-low bit of ``namei``, if set, means that this was a two-argument
call to :func:`super` (unset means zero-argument).

.. versionadded:: 3.12

.. versionchanged:: 3.13
The push order for method loads changed to keep the callable at a fixed
stack position for :opcode:`CALL`: the loaded method is now pushed before
the ``NULL`` marker (previously the marker was pushed first).


.. opcode:: COMPARE_OP (opname)

Expand Down Expand Up @@ -1422,6 +1433,11 @@ iterations of the loop.
If the low bit of ``namei`` is set, then a ``NULL`` is pushed to the
stack before the global variable.

.. versionchanged:: 3.13
The push order changed to keep the callable at a fixed stack position for
:opcode:`CALL`: the global is now pushed before the ``NULL`` marker
(previously the marker was pushed first).

.. opcode:: LOAD_FAST (var_num)

Pushes a reference to the local ``co_varnames[var_num]`` onto the stack.
Expand Down
Loading