Skip to content

Commit 22e65ee

Browse files
authored
GH-105848: Replace KW_NAMES + CALL with LOAD_CONST + CALL_KW (GH-109300)
1 parent 987b4bc commit 22e65ee

22 files changed

+719
-508
lines changed

Doc/library/dis.rst

+33-25
Original file line numberDiff line numberDiff line change
@@ -1122,7 +1122,8 @@ iterations of the loop.
11221122
This bytecode distinguishes two cases: if ``STACK[-1]`` has a method with the
11231123
correct name, the bytecode pushes the unbound method and ``STACK[-1]``.
11241124
``STACK[-1]`` will be used as the first argument (``self``) by :opcode:`CALL`
1125-
when calling the unbound method. Otherwise, ``NULL`` and the object returned by
1125+
or :opcode:`CALL_KW` when calling the unbound method.
1126+
Otherwise, ``NULL`` and the object returned by
11261127
the attribute lookup are pushed.
11271128

11281129
.. versionchanged:: 3.12
@@ -1390,32 +1391,48 @@ iterations of the loop.
13901391

13911392
.. opcode:: CALL (argc)
13921393

1393-
Calls a callable object with the number of arguments specified by ``argc``,
1394-
including the named arguments specified by the preceding
1395-
:opcode:`KW_NAMES`, if any.
1396-
On the stack are (in ascending order), either:
1394+
Calls a callable object with the number of arguments specified by ``argc``.
1395+
On the stack are (in ascending order):
13971396

1398-
* NULL
13991397
* The callable
1400-
* The positional arguments
1401-
* The named arguments
1402-
1403-
or:
1404-
1405-
* The callable
1406-
* ``self``
1398+
* ``self`` or ``NULL``
14071399
* The remaining positional arguments
1408-
* The named arguments
14091400

1410-
``argc`` is the total of the positional and named arguments, excluding
1411-
``self`` when a ``NULL`` is not present.
1401+
``argc`` is the total of the positional arguments, excluding ``self``.
14121402

14131403
``CALL`` pops all arguments and the callable object off the stack,
14141404
calls the callable object with those arguments, and pushes the return value
14151405
returned by the callable object.
14161406

14171407
.. versionadded:: 3.11
14181408

1409+
.. versionchanged:: 3.13
1410+
The callable now always appears at the same position on the stack.
1411+
1412+
.. versionchanged:: 3.13
1413+
Calls with keyword arguments are now handled by :opcode:`CALL_KW`.
1414+
1415+
1416+
.. opcode:: CALL_KW (argc)
1417+
1418+
Calls a callable object with the number of arguments specified by ``argc``,
1419+
including one or more named arguments. On the stack are (in ascending order):
1420+
1421+
* The callable
1422+
* ``self`` or ``NULL``
1423+
* The remaining positional arguments
1424+
* The named arguments
1425+
* A :class:`tuple` of keyword argument names
1426+
1427+
``argc`` is the total of the positional and named arguments, excluding ``self``.
1428+
The length of the tuple of keyword argument names is the number of named arguments.
1429+
1430+
``CALL_KW`` pops all arguments, the keyword names, and the callable object
1431+
off the stack, calls the callable object with those arguments, and pushes the
1432+
return value returned by the callable object.
1433+
1434+
.. versionadded:: 3.13
1435+
14191436

14201437
.. opcode:: CALL_FUNCTION_EX (flags)
14211438

@@ -1441,15 +1458,6 @@ iterations of the loop.
14411458
.. versionadded:: 3.11
14421459

14431460

1444-
.. opcode:: KW_NAMES (consti)
1445-
1446-
Prefixes :opcode:`CALL`.
1447-
Stores a reference to ``co_consts[consti]`` into an internal variable
1448-
for use by :opcode:`CALL`. ``co_consts[consti]`` must be a tuple of strings.
1449-
1450-
.. versionadded:: 3.11
1451-
1452-
14531461
.. opcode:: MAKE_FUNCTION
14541462

14551463
Pushes a new function object on the stack built from the code object at ``STACK[1]``.

Include/internal/pycore_code.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ extern void _Py_Specialize_BinarySubscr(PyObject *sub, PyObject *container,
253253
extern void _Py_Specialize_StoreSubscr(PyObject *container, PyObject *sub,
254254
_Py_CODEUNIT *instr);
255255
extern void _Py_Specialize_Call(PyObject *callable, _Py_CODEUNIT *instr,
256-
int nargs, PyObject *kwnames);
256+
int nargs);
257257
extern void _Py_Specialize_BinaryOp(PyObject *lhs, PyObject *rhs, _Py_CODEUNIT *instr,
258258
int oparg, PyObject **locals);
259259
extern void _Py_Specialize_CompareOp(PyObject *lhs, PyObject *rhs,

Include/internal/pycore_opcode_metadata.h

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

Include/opcode_ids.h

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

Lib/_opcode_metadata.py

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

0 commit comments

Comments
 (0)