Skip to content

Commit a9caf9c

Browse files
authored
GH-105848: Simplify the arrangement of CALL's stack (GH-107788)
1 parent 0a7f48b commit a9caf9c

16 files changed

+627
-682
lines changed

Doc/library/dis.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ the following command can be used to display the disassembly of
5656
>>> dis.dis(myfunc)
5757
2 0 RESUME 0
5858
<BLANKLINE>
59-
3 2 LOAD_GLOBAL 1 (NULL + len)
59+
3 2 LOAD_GLOBAL 1 (len + NULL)
6060
12 LOAD_FAST 0 (alist)
6161
14 CALL 1
6262
22 RETURN_VALUE

Include/internal/pycore_opcode_metadata.h

+9-9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Lib/dis.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -552,15 +552,15 @@ def _get_instructions_bytes(code, varname_from_oparg=None,
552552
if deop == LOAD_GLOBAL:
553553
argval, argrepr = _get_name_info(arg//2, get_name)
554554
if (arg & 1) and argrepr:
555-
argrepr = "NULL + " + argrepr
555+
argrepr = f"{argrepr} + NULL"
556556
elif deop == LOAD_ATTR:
557557
argval, argrepr = _get_name_info(arg//2, get_name)
558558
if (arg & 1) and argrepr:
559-
argrepr = "NULL|self + " + argrepr
559+
argrepr = f"{argrepr} + NULL|self"
560560
elif deop == LOAD_SUPER_ATTR:
561561
argval, argrepr = _get_name_info(arg//4, get_name)
562562
if (arg & 1) and argrepr:
563-
argrepr = "NULL|self + " + argrepr
563+
argrepr = f"{argrepr} + NULL|self"
564564
else:
565565
argval, argrepr = _get_name_info(arg, get_name)
566566
elif deop in hasjabs:

Lib/importlib/_bootstrap_external.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,7 @@ def _write_atomic(path, data, mode=0o666):
453453
# Python 3.13a1 3555 (generate specialized opcodes metadata from bytecodes.c)
454454
# Python 3.13a1 3556 (Convert LOAD_CLOSURE to a pseudo-op)
455455
# Python 3.13a1 3557 (Make the conversion to boolean in jumps explicit)
456+
# Python 3.13a1 3558 (Reorder the stack items for CALL)
456457

457458
# Python 3.14 will start with 3600
458459

@@ -469,7 +470,7 @@ def _write_atomic(path, data, mode=0o666):
469470
# Whenever MAGIC_NUMBER is changed, the ranges in the magic_values array
470471
# in PC/launcher.c must also be updated.
471472

472-
MAGIC_NUMBER = (3557).to_bytes(2, 'little') + b'\r\n'
473+
MAGIC_NUMBER = (3558).to_bytes(2, 'little') + b'\r\n'
473474

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

Lib/test/test_compiler_assemble.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,12 @@ def inner():
9494

9595
instructions = [
9696
('RESUME', 0,),
97-
('PUSH_NULL', 0, 1),
9897
('LOAD_CLOSURE', 0, 1),
9998
('BUILD_TUPLE', 1, 1),
10099
('LOAD_CONST', 1, 1),
101100
('MAKE_FUNCTION', 0, 2),
102101
('SET_FUNCTION_ATTRIBUTE', 8, 2),
102+
('PUSH_NULL', 0, 1),
103103
('CALL', 0, 2), # (lambda: x)()
104104
('LOAD_CONST', 2, 2), # 2
105105
('BINARY_OP', 6, 2), # %

Lib/test/test_compiler_codegen.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ def test_for_loop(self):
4141
loop_lbl := self.Label(),
4242
('FOR_ITER', exit_lbl := self.Label(), 1),
4343
('STORE_NAME', 1, 1),
44-
('PUSH_NULL', None, 2),
4544
('LOAD_NAME', 2, 2),
45+
('PUSH_NULL', None, 2),
4646
('LOAD_NAME', 1, 2),
4747
('CALL', 1, 2),
4848
('POP_TOP', None),

0 commit comments

Comments
 (0)