Skip to content

Commit

Permalink
GH-105848: Replace KW_NAMES + CALL with LOAD_CONST + CALL_KW (GH-109300)
Browse files Browse the repository at this point in the history
  • Loading branch information
brandtbucher committed Sep 13, 2023
1 parent 987b4bc commit 22e65ee
Show file tree
Hide file tree
Showing 22 changed files with 719 additions and 508 deletions.
58 changes: 33 additions & 25 deletions Doc/library/dis.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1122,7 +1122,8 @@ iterations of the loop.
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`
when calling the unbound method. Otherwise, ``NULL`` and the object returned by
or :opcode:`CALL_KW` when calling the unbound method.
Otherwise, ``NULL`` and the object returned by
the attribute lookup are pushed.

.. versionchanged:: 3.12
Expand Down Expand Up @@ -1390,32 +1391,48 @@ iterations of the loop.

.. opcode:: CALL (argc)

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

* NULL
* The callable
* The positional arguments
* The named arguments

or:

* The callable
* ``self``
* ``self`` or ``NULL``
* The remaining positional arguments
* The named arguments

``argc`` is the total of the positional and named arguments, excluding
``self`` when a ``NULL`` is not present.
``argc`` is the total of the positional arguments, excluding ``self``.

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

.. versionadded:: 3.11

.. versionchanged:: 3.13
The callable now always appears at the same position on the stack.

.. versionchanged:: 3.13
Calls with keyword arguments are now handled by :opcode:`CALL_KW`.


.. opcode:: CALL_KW (argc)

Calls a callable object with the number of arguments specified by ``argc``,
including one or more named arguments. On the stack are (in ascending order):

* The callable
* ``self`` or ``NULL``
* The remaining positional arguments
* The named arguments
* A :class:`tuple` of keyword argument names

``argc`` is the total of the positional and named arguments, excluding ``self``.
The length of the tuple of keyword argument names is the number of named arguments.

``CALL_KW`` pops all arguments, the keyword names, and the callable object
off the stack, calls the callable object with those arguments, and pushes the
return value returned by the callable object.

.. versionadded:: 3.13


.. opcode:: CALL_FUNCTION_EX (flags)

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


.. opcode:: KW_NAMES (consti)

Prefixes :opcode:`CALL`.
Stores a reference to ``co_consts[consti]`` into an internal variable
for use by :opcode:`CALL`. ``co_consts[consti]`` must be a tuple of strings.

.. versionadded:: 3.11


.. opcode:: MAKE_FUNCTION

Pushes a new function object on the stack built from the code object at ``STACK[1]``.
Expand Down
2 changes: 1 addition & 1 deletion Include/internal/pycore_code.h
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ extern void _Py_Specialize_BinarySubscr(PyObject *sub, PyObject *container,
extern void _Py_Specialize_StoreSubscr(PyObject *container, PyObject *sub,
_Py_CODEUNIT *instr);
extern void _Py_Specialize_Call(PyObject *callable, _Py_CODEUNIT *instr,
int nargs, PyObject *kwnames);
int nargs);
extern void _Py_Specialize_BinaryOp(PyObject *lhs, PyObject *rhs, _Py_CODEUNIT *instr,
int oparg, PyObject **locals);
extern void _Py_Specialize_CompareOp(PyObject *lhs, PyObject *rhs,
Expand Down
165 changes: 87 additions & 78 deletions Include/internal/pycore_opcode_metadata.h

Large diffs are not rendered by default.

103 changes: 52 additions & 51 deletions Include/opcode_ids.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

127 changes: 64 additions & 63 deletions Lib/_opcode_metadata.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 22e65ee

Please sign in to comment.