Skip to content

Commit 3306286

Browse files
committed
Merge remote-tracking branch 'upstream/main' into 45711-exc_info_just_value
2 parents 8ee6d84 + f025ae6 commit 3306286

24 files changed

+491
-281
lines changed

Doc/library/dis.rst

Lines changed: 15 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ the following command can be used to display the disassembly of
3636
>>> dis.dis(myfunc)
3737
2 0 LOAD_GLOBAL 0 (len)
3838
2 LOAD_FAST 0 (alist)
39-
4 CALL_FUNCTION 1
39+
4 CALL_NO_KW 1
4040
6 RETURN_VALUE
4141

4242
(The "2" is a line number).
@@ -104,7 +104,7 @@ Example::
104104
...
105105
LOAD_GLOBAL
106106
LOAD_FAST
107-
CALL_FUNCTION
107+
CALL_NO_KW
108108
RETURN_VALUE
109109

110110

@@ -625,7 +625,7 @@ iterations of the loop.
625625
.. opcode:: LOAD_BUILD_CLASS
626626

627627
Pushes :func:`builtins.__build_class__` onto the stack. It is later called
628-
by :opcode:`CALL_FUNCTION` to construct a class.
628+
by :opcode:`CALL_NO_KW` to construct a class.
629629

630630

631631
.. opcode:: BEFORE_WITH (delta)
@@ -1047,21 +1047,20 @@ All of the following opcodes use their arguments.
10471047
with ``__cause__`` set to ``TOS``)
10481048

10491049

1050-
.. opcode:: CALL_FUNCTION (argc)
1050+
.. opcode:: CALL_NO_KW (argc)
10511051

10521052
Calls a callable object with positional arguments.
10531053
*argc* indicates the number of positional arguments.
10541054
The top of the stack contains positional arguments, with the right-most
10551055
argument on top. Below the arguments is a callable object to call.
1056-
``CALL_FUNCTION`` pops all arguments and the callable object off the stack,
1056+
``CALL_NO_KW`` pops all arguments and the callable object off the stack,
10571057
calls the callable object with those arguments, and pushes the return value
10581058
returned by the callable object.
10591059

1060-
.. versionchanged:: 3.6
1061-
This opcode is used only for calls with positional arguments.
1060+
.. versionadded:: 3.11
10621061

10631062

1064-
.. opcode:: CALL_FUNCTION_KW (argc)
1063+
.. opcode:: CALL_KW (argc)
10651064

10661065
Calls a callable object with positional (if any) and keyword arguments.
10671066
*argc* indicates the total number of positional and keyword arguments.
@@ -1071,13 +1070,11 @@ All of the following opcodes use their arguments.
10711070
in the order corresponding to the tuple.
10721071
Below that are positional arguments, with the right-most parameter on
10731072
top. Below the arguments is a callable object to call.
1074-
``CALL_FUNCTION_KW`` pops all arguments and the callable object off the stack,
1073+
``CALL_KW`` pops all arguments and the callable object off the stack,
10751074
calls the callable object with those arguments, and pushes the return value
10761075
returned by the callable object.
10771076

1078-
.. versionchanged:: 3.6
1079-
Keyword arguments are packed in a tuple instead of a dictionary,
1080-
*argc* indicates the total number of arguments.
1077+
.. versionadded:: 3.11
10811078

10821079

10831080
.. opcode:: CALL_FUNCTION_EX (flags)
@@ -1107,30 +1104,16 @@ All of the following opcodes use their arguments.
11071104
.. versionadded:: 3.7
11081105

11091106

1110-
.. opcode:: CALL_METHOD (argc)
1111-
1112-
Calls a method. *argc* is the number of positional arguments.
1113-
Keyword arguments are not supported. This opcode is designed to be used
1114-
with :opcode:`LOAD_METHOD`. Positional arguments are on top of the stack.
1115-
Below them, the two items described in :opcode:`LOAD_METHOD` are on the
1116-
stack (either ``self`` and an unbound method object or ``NULL`` and an
1117-
arbitrary callable). All of them are popped and the return value is pushed.
1118-
1119-
.. versionadded:: 3.7
1120-
1121-
1122-
.. opcode:: CALL_METHOD_KW (argc)
1107+
.. opcode:: PRECALL_METHOD (argc)
11231108

1124-
Calls a method in a similar fashion as :opcode:`CALL_METHOD`, but also supports keyword arguments.
1125-
*argc* is the number of positional and keyword arguments.
1126-
This opcode is designed to be used with :opcode:`LOAD_METHOD`. TOS is a
1127-
tuple of keyword argument names. Argument values are below that.
1128-
Below them, the two items described in :opcode:`LOAD_METHOD` are on the
1129-
stack (either ``self`` and an unbound method object or ``NULL`` and an
1130-
arbitrary callable). All of them are popped from the stack and the return value is pushed.
1109+
Prefixes either :opcode:`CALL_NO_KW` or :opcode:`CALL_KW`.
1110+
This opcode is designed to be used with :opcode:`LOAD_METHOD`.
1111+
Sets internal variables, so that :opcode:`CALL_NO_KW` or :opcode:`CALL_KW`
1112+
clean up after :opcode:`LOAD_METHOD` correctly.
11311113

11321114
.. versionadded:: 3.11
11331115

1116+
11341117
.. opcode:: MAKE_FUNCTION (flags)
11351118

11361119
Pushes a new function object on the stack. From bottom to top, the consumed

Doc/library/functions.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1571,7 +1571,7 @@ are always available. They are listed here in alphabetical order.
15711571
:func:`itertools.islice` for an alternate version that returns an iterator.
15721572

15731573

1574-
.. function:: sorted(iterable, *, key=None, reverse=False)
1574+
.. function:: sorted(iterable, /, *, key=None, reverse=False)
15751575

15761576
Return a new sorted list from the items in *iterable*.
15771577

Doc/whatsnew/3.11.rst

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -373,9 +373,11 @@ CPython bytecode changes
373373
* Replaced all numeric ``BINARY_*`` and ``INPLACE_*`` instructions with a single
374374
:opcode:`BINARY_OP` implementation.
375375

376-
* Added a new :opcode:`CALL_METHOD_KW` opcode. Calls a method in a similar
377-
fashion as :opcode:`CALL_METHOD`, but also supports keyword arguments. Works
378-
in tandem with :opcode:`LOAD_METHOD`.
376+
* Replaced the three call instructions: :opcode:`CALL_FUNCTION`,
377+
:opcode:`CALL_FUNCTION_KW` and :opcode:`CALL_METHOD` with
378+
:opcode:`CALL_NO_KW`, :opcode:`CALL_KW` and :opcode:`PRECALL_METHOD`.
379+
This decouples the argument shifting for methods from the handling of
380+
keyword arguments and allows better specialization of calls.
379381

380382
* Removed ``COPY_DICT_WITHOUT_KEYS``.
381383

Include/internal/pycore_code.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ int _Py_Specialize_LoadGlobal(PyObject *globals, PyObject *builtins, _Py_CODEUNI
271271
int _Py_Specialize_LoadMethod(PyObject *owner, _Py_CODEUNIT *instr, PyObject *name, SpecializedCacheEntry *cache);
272272
int _Py_Specialize_BinarySubscr(PyObject *sub, PyObject *container, _Py_CODEUNIT *instr, SpecializedCacheEntry *cache);
273273
int _Py_Specialize_StoreSubscr(PyObject *container, PyObject *sub, _Py_CODEUNIT *instr);
274-
int _Py_Specialize_CallFunction(PyObject *callable, _Py_CODEUNIT *instr, int nargs, SpecializedCacheEntry *cache, PyObject *builtins);
274+
int _Py_Specialize_CallNoKw(PyObject *callable, _Py_CODEUNIT *instr, int nargs, SpecializedCacheEntry *cache, PyObject *builtins);
275275
void _Py_Specialize_BinaryOp(PyObject *lhs, PyObject *rhs, _Py_CODEUNIT *instr,
276276
SpecializedCacheEntry *cache);
277277
void _Py_Specialize_CompareOp(PyObject *lhs, PyObject *rhs, _Py_CODEUNIT *instr, SpecializedCacheEntry *cache);
@@ -288,7 +288,7 @@ void _Py_Specialize_CompareOp(PyObject *lhs, PyObject *rhs, _Py_CODEUNIT *instr,
288288
#define COLLECT_SPECIALIZATION_STATS_DETAILED PRINT_SPECIALIZATION_STATS_DETAILED
289289
#endif
290290

291-
#define SPECIALIZATION_FAILURE_KINDS 20
291+
#define SPECIALIZATION_FAILURE_KINDS 30
292292

293293
#if COLLECT_SPECIALIZATION_STATS
294294

Include/internal/pycore_frame.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ static inline PyObject **_PyFrame_Stackbase(InterpreterFrame *f) {
6666

6767
static inline PyObject *_PyFrame_StackPeek(InterpreterFrame *f) {
6868
assert(f->stacktop > f->f_code->co_nlocalsplus);
69+
assert(f->localsplus[f->stacktop-1] != NULL);
6970
return f->localsplus[f->stacktop-1];
7071
}
7172

Include/opcode.h

Lines changed: 38 additions & 36 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Lib/argparse.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,9 @@ def _format_actions_usage(self, actions, groups):
392392
group_actions = set()
393393
inserts = {}
394394
for group in groups:
395+
if not group._group_actions:
396+
raise ValueError(f'empty group {group}')
397+
395398
try:
396399
start = actions.index(group._group_actions[0])
397400
except ValueError:

Lib/importlib/_bootstrap_external.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -371,8 +371,10 @@ def _write_atomic(path, data, mode=0o666):
371371
# Python 3.11a3 3464 (bpo-45636: Merge numeric BINARY_*/INPLACE_* into
372372
# BINARY_OP)
373373
# Python 3.11a3 3465 (Add COPY_FREE_VARS opcode)
374-
# Python 3.11a3 3466 (bpo-45292: PEP-654 except*)
375-
# Python 3.11a3 3467 (bpo-45711: remove type, traceback from exc_info)
374+
# Python 3.11a4 3466 (bpo-45292: PEP-654 except*)
375+
# Python 3.11a4 3467 (Change CALL_xxx opcodes)
376+
# Python 3.11a4 3468 (Add SEND opcode)
377+
# Python 3.11a4 3469 (bpo-45711: remove type, traceback from exc_info)
376378

377379
#
378380
# MAGIC must change whenever the bytecode emitted by the compiler may no
@@ -382,7 +384,7 @@ def _write_atomic(path, data, mode=0o666):
382384
# Whenever MAGIC_NUMBER is changed, the ranges in the magic_values array
383385
# in PC/launcher.c must also be updated.
384386

385-
MAGIC_NUMBER = (3467).to_bytes(2, 'little') + b'\r\n'
387+
MAGIC_NUMBER = (3469).to_bytes(2, 'little') + b'\r\n'
386388
_RAW_MAGIC_NUMBER = int.from_bytes(MAGIC_NUMBER, 'little') # For import.c
387389

388390
_PYCACHE = '__pycache__'

Lib/opcode.py

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def jabs_op(name, op):
9393
def_op('GET_YIELD_FROM_ITER', 69)
9494
def_op('PRINT_EXPR', 70)
9595
def_op('LOAD_BUILD_CLASS', 71)
96-
def_op('YIELD_FROM', 72)
96+
9797
def_op('GET_AWAITABLE', 73)
9898
def_op('LOAD_ASSERTION_ERROR', 74)
9999

@@ -143,7 +143,7 @@ def jabs_op(name, op):
143143
def_op('COPY', 120)
144144
jabs_op('JUMP_IF_NOT_EXC_MATCH', 121)
145145
def_op('BINARY_OP', 122)
146-
146+
jrel_op('SEND', 123) # Number of bytes to skip
147147
def_op('LOAD_FAST', 124) # Local variable number
148148
haslocal.append(124)
149149
def_op('STORE_FAST', 125) # Local variable number
@@ -155,7 +155,7 @@ def jabs_op(name, op):
155155

156156
def_op('GEN_START', 129) # Kind of generator/coroutine
157157
def_op('RAISE_VARARGS', 130) # Number of raise arguments (1, 2, or 3)
158-
def_op('CALL_FUNCTION', 131) # #args
158+
159159
def_op('MAKE_FUNCTION', 132) # Flags
160160
def_op('BUILD_SLICE', 133) # Number of items
161161

@@ -170,7 +170,6 @@ def jabs_op(name, op):
170170
def_op('DELETE_DEREF', 139)
171171
hasfree.append(139)
172172

173-
def_op('CALL_FUNCTION_KW', 141) # #args + #kwargs
174173
def_op('CALL_FUNCTION_EX', 142) # Flags
175174

176175
def_op('EXTENDED_ARG', 144)
@@ -189,12 +188,15 @@ def jabs_op(name, op):
189188
def_op('BUILD_STRING', 157)
190189

191190
name_op('LOAD_METHOD', 160)
192-
def_op('CALL_METHOD', 161)
191+
193192
def_op('LIST_EXTEND', 162)
194193
def_op('SET_UPDATE', 163)
195194
def_op('DICT_MERGE', 164)
196195
def_op('DICT_UPDATE', 165)
197-
def_op('CALL_METHOD_KW', 166)
196+
197+
def_op('PRECALL_METHOD', 168)
198+
def_op('CALL_NO_KW', 169)
199+
def_op('CALL_KW', 170)
198200

199201
del def_op, name_op, jrel_op, jabs_op
200202

@@ -249,12 +251,15 @@ def jabs_op(name, op):
249251
"STORE_SUBSCR_ADAPTIVE",
250252
"STORE_SUBSCR_LIST_INT",
251253
"STORE_SUBSCR_DICT",
252-
"CALL_FUNCTION_ADAPTIVE",
253-
"CALL_FUNCTION_BUILTIN_O",
254-
"CALL_FUNCTION_BUILTIN_FAST",
255-
"CALL_FUNCTION_LEN",
256-
"CALL_FUNCTION_ISINSTANCE",
257-
"CALL_FUNCTION_PY_SIMPLE",
254+
"CALL_NO_KW_ADAPTIVE",
255+
"CALL_NO_KW_BUILTIN_O",
256+
"CALL_NO_KW_BUILTIN_FAST",
257+
"CALL_NO_KW_LEN",
258+
"CALL_NO_KW_ISINSTANCE",
259+
"CALL_NO_KW_PY_SIMPLE",
260+
"CALL_NO_KW_LIST_APPEND",
261+
"CALL_NO_KW_METHOD_DESCRIPTOR_O",
262+
"CALL_NO_KW_METHOD_DESCRIPTOR_FAST",
258263
"JUMP_ABSOLUTE_QUICK",
259264
"LOAD_ATTR_ADAPTIVE",
260265
"LOAD_ATTR_INSTANCE_VALUE",

0 commit comments

Comments
 (0)