Skip to content

Commit b0a2da6

Browse files
markshannonsrinivasreddy
authored andcommitted
pythonGH-128914: Remove conditional stack effects from bytecodes.c and the code generators (pythonGH-128918)
1 parent ced58be commit b0a2da6

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

+1459
-1678
lines changed

Doc/library/dis.rst

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ 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 1 (len + NULL)
78+
3 LOAD_GLOBAL 0 (len)
79+
PUSH_NULL
7980
LOAD_FAST 0 (alist)
8081
CALL 1
8182
RETURN_VALUE
@@ -207,6 +208,7 @@ Example:
207208
...
208209
RESUME
209210
LOAD_GLOBAL
211+
PUSH_NULL
210212
LOAD_FAST
211213
CALL
212214
RETURN_VALUE
@@ -1215,21 +1217,28 @@ iterations of the loop.
12151217

12161218
.. opcode:: LOAD_ATTR (namei)
12171219

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

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.
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.
12231234
This bytecode distinguishes two cases: if ``STACK[-1]`` has a method with the
12241235
correct name, the bytecode pushes the unbound method and ``STACK[-1]``.
12251236
``STACK[-1]`` will be used as the first argument (``self``) by :opcode:`CALL`
12261237
or :opcode:`CALL_KW` when calling the unbound method.
12271238
Otherwise, ``NULL`` and the object returned by
12281239
the attribute lookup are pushed.
12291240

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.
1241+
.. versionadded:: 3.14
12331242

12341243

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

19281937

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-
19351938
.. _opcode_collections:
19361939

19371940
Opcode collections

Include/internal/pycore_code.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,8 @@ 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);
337339
extern void _Py_Specialize_StoreAttr(_PyStackRef owner, _Py_CODEUNIT *instr,
338340
PyObject *name);
339341
extern void _Py_Specialize_LoadGlobal(PyObject *globals, PyObject *builtins,

Include/internal/pycore_magic_number.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@ 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)
270271
271272
Python 3.15 will start with 3650
272273
@@ -279,7 +280,7 @@ PC/launcher.c must also be updated.
279280
280281
*/
281282

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

0 commit comments

Comments
 (0)