Skip to content

GH-105848: Get rid of KW_NAMES #105849

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 13 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 12 additions & 15 deletions Doc/library/dis.rst
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ the following command can be used to display the disassembly of
<BLANKLINE>
3 2 LOAD_GLOBAL 1 (NULL + len)
12 LOAD_FAST 0 (alist)
14 CALL 1
14 CALL 2 (1)
22 RETURN_VALUE

(The "2" is a line number).
Expand Down Expand Up @@ -1361,22 +1361,23 @@ 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.
Calls a callable object with the number of arguments specified by ``argc >> 1``,
including the named arguments, if ``argc & 1``.
On the stack are (in ascending order), either:

* NULL
* The callable
* The positional arguments
* The named arguments
* The named arguments (if ``argc & 1``)
* A tuple of keyword names (if ``argc & 1``)

or:

* The callable
* ``self``
* The remaining positional arguments
* The named arguments
* The named arguments (if ``argc & 1``)
* A tuple of keyword names (if ``argc & 1``)

``argc`` is the total of the positional and named arguments, excluding
``self`` when a ``NULL`` is not present.
Expand All @@ -1387,6 +1388,11 @@ iterations of the loop.

.. versionadded:: 3.11

.. versionchanged:: 3.13
Keyword names are now found to the stack, and the presence of keyword
arguments is indicated by the low bit of the oparg (rather than a separate
``KW_NAMES`` instruction).


.. opcode:: CALL_FUNCTION_EX (flags)

Expand All @@ -1412,15 +1418,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
4 changes: 2 additions & 2 deletions Include/internal/pycore_opcode.h

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

2 changes: 0 additions & 2 deletions Include/opcode.h

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

7 changes: 7 additions & 0 deletions Lib/dis.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
LOAD_FAST_LOAD_FAST = opmap['LOAD_FAST_LOAD_FAST']
STORE_FAST_LOAD_FAST = opmap['STORE_FAST_LOAD_FAST']
STORE_FAST_STORE_FAST = opmap['STORE_FAST_STORE_FAST']
CALL = opmap['CALL']

CACHE = opmap["CACHE"]

Expand Down Expand Up @@ -586,6 +587,12 @@ def _get_instructions_bytes(code, varname_from_oparg=None,
argrepr = _intrinsic_1_descs[arg]
elif deop == CALL_INTRINSIC_2:
argrepr = _intrinsic_2_descs[arg]
elif deop == CALL:
argval = arg >> 1
if arg & 1:
argrepr = f"{argval} + keywords"
else:
argrepr = repr(argval)
yield Instruction(_all_opname[op], op,
arg, argval, argrepr,
offset, start_offset, starts_line, is_jump_target, positions)
Expand Down
3 changes: 2 additions & 1 deletion Lib/importlib/_bootstrap_external.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,7 @@ def _write_atomic(path, data, mode=0o666):
# Python 3.13a1 3552 (Remove LOAD_FAST__LOAD_CONST and LOAD_CONST__LOAD_FAST)
# Python 3.13a1 3553 (Add SET_FUNCTION_ATTRIBUTE)
# Python 3.13a1 3554 (more efficient bytecodes for f-strings)
# Python 3.13a1 3555 (Remove KW_NAMES)

# Python 3.14 will start with 3600

Expand All @@ -466,7 +467,7 @@ def _write_atomic(path, data, mode=0o666):
# Whenever MAGIC_NUMBER is changed, the ranges in the magic_values array
# in PC/launcher.c must also be updated.

MAGIC_NUMBER = (3554).to_bytes(2, 'little') + b'\r\n'
MAGIC_NUMBER = (3555).to_bytes(2, 'little') + b'\r\n'

_RAW_MAGIC_NUMBER = int.from_bytes(MAGIC_NUMBER, 'little') # For import.c

Expand Down
3 changes: 1 addition & 2 deletions Lib/opcode.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,7 @@ def pseudo_op(name, op, real_ops):
def_op('STORE_FAST_LOAD_FAST', 169)
def_op('STORE_FAST_STORE_FAST', 170)
def_op('CALL', 171)
def_op('KW_NAMES', 172)
hasconst.append(172)

def_op('CALL_INTRINSIC_1', 173)
def_op('CALL_INTRINSIC_2', 174)

Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_compiler_codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def test_for_loop(self):
('PUSH_NULL', None, 2),
('LOAD_NAME', 2, 2),
('LOAD_NAME', 1, 2),
('CALL', 1, 2),
('CALL', (1 << 1) | 0, 2),
('POP_TOP', None),
('JUMP', loop_lbl),
exit_lbl,
Expand Down
Loading