Skip to content

Commit a10f993

Browse files
authored
Revert "GH-128914: Remove conditional stack effects from bytecodes.c 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.
1 parent d7d066c commit a10f993

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1678
-1459
lines changed

Doc/library/dis.rst

+14-17
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,7 @@ the following command can be used to display the disassembly of
7575
>>> dis.dis(myfunc)
7676
2 RESUME 0
7777
<BLANKLINE>
78-
3 LOAD_GLOBAL 0 (len)
79-
PUSH_NULL
78+
3 LOAD_GLOBAL 1 (len + NULL)
8079
LOAD_FAST 0 (alist)
8180
CALL 1
8281
RETURN_VALUE
@@ -208,7 +207,6 @@ Example:
208207
...
209208
RESUME
210209
LOAD_GLOBAL
211-
PUSH_NULL
212210
LOAD_FAST
213211
CALL
214212
RETURN_VALUE
@@ -1217,28 +1215,21 @@ iterations of the loop.
12171215

12181216
.. opcode:: LOAD_ATTR (namei)
12191217

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

1222-
.. versionchanged:: 3.12
1223-
If the low bit of ``namei`` is set, then a ``NULL`` or ``self`` is
1224-
pushed to the stack before the attribute or unbound method respectively.
1225-
1226-
.. versionchanged:: 3.14
1227-
Reverted change from 3.12. The low bit of ``namei`` has no special meaning.
1228-
1229-
1230-
.. opcode:: LOAD_METHOD (namei)
1231-
1232-
Attempt to load a method named ``co_names[namei>>1]`` from the ``STACK[-1]`` object.
1233-
``STACK[-1]`` is popped.
1221+
If the low bit of ``namei`` is set, this will attempt to load a method named
1222+
``co_names[namei>>1]`` from the ``STACK[-1]`` object. ``STACK[-1]`` is popped.
12341223
This bytecode distinguishes two cases: if ``STACK[-1]`` has a method with the
12351224
correct name, the bytecode pushes the unbound method and ``STACK[-1]``.
12361225
``STACK[-1]`` will be used as the first argument (``self``) by :opcode:`CALL`
12371226
or :opcode:`CALL_KW` when calling the unbound method.
12381227
Otherwise, ``NULL`` and the object returned by
12391228
the attribute lookup are pushed.
12401229

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

12431234

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

19371928

1929+
.. opcode:: LOAD_METHOD
1930+
1931+
Optimized unbound method lookup. Emitted as a ``LOAD_ATTR`` opcode
1932+
with a flag set in the arg.
1933+
1934+
19381935
.. _opcode_collections:
19391936

19401937
Opcode collections

Include/internal/pycore_code.h

-2
Original file line numberDiff line numberDiff line change
@@ -334,8 +334,6 @@ extern void _Py_Specialize_LoadSuperAttr(_PyStackRef global_super, _PyStackRef c
334334
_Py_CODEUNIT *instr, int load_method);
335335
extern void _Py_Specialize_LoadAttr(_PyStackRef owner, _Py_CODEUNIT *instr,
336336
PyObject *name);
337-
extern void _Py_Specialize_LoadMethod(_PyStackRef owner, _Py_CODEUNIT *instr,
338-
PyObject *name);
339337
extern void _Py_Specialize_StoreAttr(_PyStackRef owner, _Py_CODEUNIT *instr,
340338
PyObject *name);
341339
extern void _Py_Specialize_LoadGlobal(PyObject *globals, PyObject *builtins,

Include/internal/pycore_magic_number.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,6 @@ Known values:
267267
Python 3.14a4 3612 (Add POP_ITER and INSTRUMENTED_POP_ITER)
268268
Python 3.14a4 3613 (Add LOAD_CONST_MORTAL instruction)
269269
Python 3.14a5 3614 (Add BINARY_OP_EXTEND)
270-
Python 3.14a5 3615 (Remove conditional stack effects)
271270
272271
Python 3.15 will start with 3650
273272
@@ -280,7 +279,7 @@ PC/launcher.c must also be updated.
280279
281280
*/
282281

283-
#define PYC_MAGIC_NUMBER 3615
282+
#define PYC_MAGIC_NUMBER 3614
284283
/* This is equivalent to converting PYC_MAGIC_NUMBER to 2 bytes
285284
(little-endian) and then appending b'\r\n'. */
286285
#define PYC_MAGIC_NUMBER_TOKEN \

0 commit comments

Comments
 (0)