Skip to content

Revert "GH-128914: Remove conditional stack effects from bytecodes.c and the code generators (GH-128918)" #129202

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

Merged
merged 1 commit into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
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
31 changes: 14 additions & 17 deletions Doc/library/dis.rst
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ the following command can be used to display the disassembly of
>>> dis.dis(myfunc)
2 RESUME 0
<BLANKLINE>
3 LOAD_GLOBAL 0 (len)
PUSH_NULL
3 LOAD_GLOBAL 1 (len + NULL)
LOAD_FAST 0 (alist)
CALL 1
RETURN_VALUE
Expand Down Expand Up @@ -208,7 +207,6 @@ Example:
...
RESUME
LOAD_GLOBAL
PUSH_NULL
LOAD_FAST
CALL
RETURN_VALUE
Expand Down Expand Up @@ -1217,28 +1215,21 @@ iterations of the loop.

.. opcode:: LOAD_ATTR (namei)

Replaces ``STACK[-1]`` with ``getattr(STACK[-1], co_names[namei>>1])``.
If the low bit of ``namei`` is not set, this replaces ``STACK[-1]`` with
``getattr(STACK[-1], co_names[namei>>1])``.

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

.. versionchanged:: 3.14
Reverted change from 3.12. The low bit of ``namei`` has no special meaning.


.. opcode:: LOAD_METHOD (namei)

Attempt to load a method named ``co_names[namei>>1]`` from the ``STACK[-1]`` object.
``STACK[-1]`` is popped.
If the low bit of ``namei`` is set, this will attempt to load a method named
``co_names[namei>>1]`` from the ``STACK[-1]`` object. ``STACK[-1]`` is popped.
This bytecode distinguishes two cases: if ``STACK[-1]`` has a method with the
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.

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


.. opcode:: LOAD_SUPER_ATTR (namei)
Expand Down Expand Up @@ -1935,6 +1926,12 @@ but are replaced by real opcodes or removed before bytecode is generated.
This opcode is now a pseudo-instruction.


.. opcode:: LOAD_METHOD

Optimized unbound method lookup. Emitted as a ``LOAD_ATTR`` opcode
with a flag set in the arg.


.. _opcode_collections:

Opcode collections
Expand Down
2 changes: 0 additions & 2 deletions Include/internal/pycore_code.h
Original file line number Diff line number Diff line change
Expand Up @@ -334,8 +334,6 @@ extern void _Py_Specialize_LoadSuperAttr(_PyStackRef global_super, _PyStackRef c
_Py_CODEUNIT *instr, int load_method);
extern void _Py_Specialize_LoadAttr(_PyStackRef owner, _Py_CODEUNIT *instr,
PyObject *name);
extern void _Py_Specialize_LoadMethod(_PyStackRef owner, _Py_CODEUNIT *instr,
PyObject *name);
extern void _Py_Specialize_StoreAttr(_PyStackRef owner, _Py_CODEUNIT *instr,
PyObject *name);
extern void _Py_Specialize_LoadGlobal(PyObject *globals, PyObject *builtins,
Expand Down
3 changes: 1 addition & 2 deletions Include/internal/pycore_magic_number.h
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,6 @@ Known values:
Python 3.14a4 3612 (Add POP_ITER and INSTRUMENTED_POP_ITER)
Python 3.14a4 3613 (Add LOAD_CONST_MORTAL instruction)
Python 3.14a5 3614 (Add BINARY_OP_EXTEND)
Python 3.14a5 3615 (Remove conditional stack effects)

Python 3.15 will start with 3650

Expand All @@ -280,7 +279,7 @@ PC/launcher.c must also be updated.

*/

#define PYC_MAGIC_NUMBER 3615
#define PYC_MAGIC_NUMBER 3614
/* This is equivalent to converting PYC_MAGIC_NUMBER to 2 bytes
(little-endian) and then appending b'\r\n'. */
#define PYC_MAGIC_NUMBER_TOKEN \
Expand Down
Loading
Loading