Skip to content

Commit a1417b2

Browse files
authored
pythongh-100239: replace BINARY_SUBSCR & family by BINARY_OP with oparg NB_SUBSCR (python#129700)
1 parent 2248a9c commit a1417b2

30 files changed

+1218
-1384
lines changed

Doc/library/dis.rst

+2-9
Original file line numberDiff line numberDiff line change
@@ -703,15 +703,8 @@ not have to be) the original ``STACK[-2]``.
703703
STACK.append(lhs op rhs)
704704

705705
.. versionadded:: 3.11
706-
707-
708-
.. opcode:: BINARY_SUBSCR
709-
710-
Implements::
711-
712-
key = STACK.pop()
713-
container = STACK.pop()
714-
STACK.append(container[key])
706+
.. versionchanged:: 3.14
707+
With oparg :``NB_SUBSCR``, implements binary subscript (replaces opcode ``BINARY_SUBSCR``)
715708

716709

717710
.. opcode:: STORE_SUBSCR

Doc/whatsnew/3.14.rst

+6
Original file line numberDiff line numberDiff line change
@@ -1199,6 +1199,12 @@ Others
11991199
:meth:`~object.__index__`. (Contributed by Mark Dickinson in :gh:`119743`.)
12001200

12011201

1202+
CPython Bytecode Changes
1203+
========================
1204+
1205+
* Replaced the opcode ``BINARY_SUBSCR`` by :opcode:`BINARY_OP` with oparg ``NB_SUBSCR``.
1206+
(Contributed by Irit Katriel in :gh:`100239`.)
1207+
12021208
Porting to Python 3.14
12031209
======================
12041210

Include/internal/pycore_code.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -338,8 +338,6 @@ extern void _Py_Specialize_StoreAttr(_PyStackRef owner, _Py_CODEUNIT *instr,
338338
PyObject *name);
339339
extern void _Py_Specialize_LoadGlobal(PyObject *globals, PyObject *builtins,
340340
_Py_CODEUNIT *instr, PyObject *name);
341-
extern void _Py_Specialize_BinarySubscr(_PyStackRef sub, _PyStackRef container,
342-
_Py_CODEUNIT *instr);
343341
extern void _Py_Specialize_StoreSubscr(_PyStackRef container, _PyStackRef sub,
344342
_Py_CODEUNIT *instr);
345343
extern void _Py_Specialize_Call(_PyStackRef callable, _Py_CODEUNIT *instr,
@@ -586,6 +584,7 @@ typedef int (*binaryopguardfunc)(PyObject *lhs, PyObject *rhs);
586584
typedef PyObject *(*binaryopactionfunc)(PyObject *lhs, PyObject *rhs);
587585

588586
typedef struct {
587+
int oparg;
589588
binaryopguardfunc guard;
590589
binaryopactionfunc action;
591590
} _PyBinaryOpSpecializationDescr;

Include/internal/pycore_magic_number.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@ Known values:
268268
Python 3.14a4 3613 (Add LOAD_CONST_MORTAL instruction)
269269
Python 3.14a5 3614 (Add BINARY_OP_EXTEND)
270270
Python 3.14a5 3615 (CALL_FUNCTION_EX always take a kwargs argument)
271+
Python 3.14a5 3616 (Remove BINARY_SUBSCR and family. Make them BINARY_OPs)
271272
272273
Python 3.15 will start with 3650
273274
@@ -280,7 +281,7 @@ PC/launcher.c must also be updated.
280281
281282
*/
282283

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

Include/internal/pycore_opcode_metadata.h

+55-67
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)