summaryrefslogtreecommitdiffstats
path: root/Doc
diff options
context:
space:
mode:
authorMark Shannon <mark@hotpy.org>2022-01-28 12:42:30 (GMT)
committerGitHub <noreply@github.com>2022-01-28 12:42:30 (GMT)
commit89fd7c34520aac493a8784a221366ed04452612b (patch)
treeda2dd6dfe862b1351063e2c0ee2a3564c4773416 /Doc
parent5a9e423473bf2c4eb32a0982e8d73420875db1da (diff)
downloadcpython-89fd7c34520aac493a8784a221366ed04452612b.zip
cpython-89fd7c34520aac493a8784a221366ed04452612b.tar.gz
cpython-89fd7c34520aac493a8784a221366ed04452612b.tar.bz2
bpo-46329: Split calls into precall and call instructions. (GH-30855)
* Add PRECALL_FUNCTION opcode. * Move 'call shape' varaibles into struct. * Replace CALL_NO_KW and CALL_KW with KW_NAMES and CALL instructions. * Specialize for builtin methods taking using the METH_FASTCALL | METH_KEYWORDS protocol. * Allow kwnames for specialized calls to builtin types. * Specialize calls to tuple(arg) and str(arg).
Diffstat (limited to 'Doc')
-rw-r--r--Doc/library/dis.rst70
-rw-r--r--Doc/whatsnew/3.11.rst3
2 files changed, 42 insertions, 31 deletions
diff --git a/Doc/library/dis.rst b/Doc/library/dis.rst
index d596809..ef64f75 100644
--- a/Doc/library/dis.rst
+++ b/Doc/library/dis.rst
@@ -34,10 +34,13 @@ the following command can be used to display the disassembly of
:func:`myfunc`::
>>> dis.dis(myfunc)
- 2 0 LOAD_GLOBAL 0 (len)
- 2 LOAD_FAST 0 (alist)
- 4 CALL_NO_KW 1
- 6 RETURN_VALUE
+ 1 0 RESUME 0
+
+ 2 2 LOAD_GLOBAL 0 (len)
+ 4 LOAD_FAST 0 (alist)
+ 6 PRECALL_FUNCTION 1
+ 8 CALL 0
+ 10 RETURN_VALUE
(The "2" is a line number).
@@ -102,9 +105,11 @@ Example::
>>> for instr in bytecode:
... print(instr.opname)
...
+ RESUME
LOAD_GLOBAL
LOAD_FAST
- CALL_NO_KW
+ PRECALL_FUNCTION
+ CALL
RETURN_VALUE
@@ -617,7 +622,7 @@ iterations of the loop.
.. opcode:: LOAD_BUILD_CLASS
Pushes :func:`builtins.__build_class__` onto the stack. It is later called
- by :opcode:`CALL_NO_KW` to construct a class.
+ to construct a class.
.. opcode:: BEFORE_WITH (delta)
@@ -1058,30 +1063,19 @@ iterations of the loop.
with ``__cause__`` set to ``TOS``)
-.. opcode:: CALL_NO_KW (argc)
-
- Calls a callable object with positional arguments.
- *argc* indicates the number of positional arguments.
- The top of the stack contains positional arguments, with the right-most
- argument on top. Below the arguments is a callable object to call.
- ``CALL_NO_KW`` 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
+.. opcode:: CALL (named)
+ Calls a callable object with the number of positional arguments specified by
+ the preceding :opcode:`PRECALL_FUNCTION` or :opcode:`PRECALL_METHOD` and
+ the named arguments specified by the preceding :opcode:`KW_NAMES`, if any.
+ *named* indicates the number of named arguments.
+ On the stack are (in ascending order):
-.. opcode:: CALL_KW (argc)
+ * The callable
+ * The positional arguments
+ * The named arguments
- Calls a callable object with positional (if any) and keyword arguments.
- *argc* indicates the total number of positional and keyword arguments.
- The top element on the stack contains a tuple with the names of the
- keyword arguments, which must be strings.
- Below that are the values for the keyword arguments,
- in the order corresponding to the tuple.
- Below that are positional arguments, with the right-most parameter on
- top. Below the arguments is a callable object to call.
- ``CALL_KW`` pops all arguments and the callable object off the stack,
+ ``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.
@@ -1108,7 +1102,7 @@ iterations of the loop.
Loads a method named ``co_names[namei]`` from the TOS object. TOS is popped.
This bytecode distinguishes two cases: if TOS has a method with the correct
name, the bytecode pushes the unbound method and TOS. TOS will be used as
- the first argument (``self``) by :opcode:`CALL_METHOD` when calling the
+ the first argument (``self``) by :opcode:`PRECALL_METHOD` when calling the
unbound method. Otherwise, ``NULL`` and the object return by the attribute
lookup are pushed.
@@ -1117,14 +1111,30 @@ iterations of the loop.
.. opcode:: PRECALL_METHOD (argc)
- Prefixes either :opcode:`CALL_NO_KW` or :opcode:`CALL_KW`.
+ Prefixes :opcode:`CALL` (possibly with an intervening ``KW_NAMES``).
This opcode is designed to be used with :opcode:`LOAD_METHOD`.
- Sets internal variables, so that :opcode:`CALL_NO_KW` or :opcode:`CALL_KW`
+ Sets internal variables, so that :opcode:`CALL`
clean up after :opcode:`LOAD_METHOD` correctly.
.. versionadded:: 3.11
+.. opcode:: PRECALL_FUNCTION (args)
+
+ Prefixes :opcode:`CALL` (possibly with an intervening ``KW_NAMES``).
+ Sets internal variables, so that :opcode:`CALL` can execute correctly.
+
+ .. versionadded:: 3.11
+
+
+.. opcode:: KW_NAMES (i)
+
+ 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 (flags)
Pushes a new function object on the stack. From bottom to top, the consumed
diff --git a/Doc/whatsnew/3.11.rst b/Doc/whatsnew/3.11.rst
index daa0a2a..e054008 100644
--- a/Doc/whatsnew/3.11.rst
+++ b/Doc/whatsnew/3.11.rst
@@ -400,7 +400,8 @@ CPython bytecode changes
* Replaced the three call instructions: :opcode:`CALL_FUNCTION`,
:opcode:`CALL_FUNCTION_KW` and :opcode:`CALL_METHOD` with
- :opcode:`CALL_NO_KW`, :opcode:`CALL_KW` and :opcode:`PRECALL_METHOD`.
+ :opcode:`PRECALL_FUNCTION`, :opcode:`PRECALL_METHOD`, :opcode:`CALL`,
+ and :opcode:`KW_NAMES`.
This decouples the argument shifting for methods from the handling of
keyword arguments and allows better specialization of calls.