Skip to content

Commit

Permalink
Revert "GH-128914: Remove conditional stack effects from `bytecodes.c…
Browse files Browse the repository at this point in the history
…` and the code generators (GH-128918)" (GH-129202)

The commit introduced a ~2.5-3% regression in the free threading build.

This reverts commit ab61d3f.
  • Loading branch information
colesbury authored Jan 23, 2025
1 parent d7d066c commit a10f993
Show file tree
Hide file tree
Showing 44 changed files with 1,678 additions and 1,459 deletions.
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

0 comments on commit a10f993

Please sign in to comment.