Skip to content
Prev Previous commit
Next Next commit
Don't specialize CALL_KW
  • Loading branch information
brandtbucher committed Sep 6, 2023
commit 367e7dbdd838cad0eaa59768c36e14ec3da8095f
28 changes: 8 additions & 20 deletions Doc/library/dis.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1122,7 +1122,7 @@ 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
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Break long line

Suggested change
or :opcode:`CALL_KW` 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 @@ -1393,13 +1393,6 @@ iterations of the loop.
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`` (or ``NULL``)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* ``self`` (or ``NULL``)
* ``self`` or ``NULL``

* The remaining positional arguments
Expand All @@ -1413,22 +1406,17 @@ iterations of the loop.

.. 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):

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

or:
including one or more named arguments. On the stack are (in ascending order):

* The callable
* ``self`` (or ``NULL``)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* ``self`` (or ``NULL``)
* ``self`` or ``NULL``

Expand All @@ -1439,9 +1427,9 @@ iterations of the loop.
``argc`` is the total of the positional and named arguments, excluding
``self`` when a ``NULL`` is not present.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Same thing about whether "not" should be removed.)

Make explicit that if there are N positional and M keyword arguments, oparg is N+M, and len(tuple) must be == M.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
``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 and named arguments, excluding ``self``.


``CALL`` 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.
``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

Expand Down
2 changes: 0 additions & 2 deletions Include/internal/pycore_code.h
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,6 @@ extern void _Py_Specialize_StoreSubscr(PyObject *container, PyObject *sub,
_Py_CODEUNIT *instr);
extern void _Py_Specialize_Call(PyObject *callable, _Py_CODEUNIT *instr,
int nargs);
extern void _Py_Specialize_CallKw(PyObject *callable, _Py_CODEUNIT *instr,
int nargs, PyObject *kwnames);
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
30 changes: 7 additions & 23 deletions Include/internal/pycore_opcode_metadata.h

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

Loading