Skip to content

Commit cf345e9

Browse files
authored
bpo-46329: Change calling sequence (again) (GH-31373)
* Change calling sequence: Add PUSH_NULL. Merge PRECALL_FUNCTION and PRECALL_METHOD into PRECALL.
1 parent e2c2861 commit cf345e9

File tree

13 files changed

+365
-344
lines changed

13 files changed

+365
-344
lines changed

Doc/whatsnew/3.11.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ CPython bytecode changes
410410

411411
* Replaced the three call instructions: :opcode:`CALL_FUNCTION`,
412412
:opcode:`CALL_FUNCTION_KW` and :opcode:`CALL_METHOD` with
413-
:opcode:`PRECALL_FUNCTION`, :opcode:`PRECALL_METHOD`, :opcode:`CALL`,
413+
:opcode:`PUSH_NULL`, :opcode:`PRECALL`, :opcode:`CALL`,
414414
and :opcode:`KW_NAMES`.
415415
This decouples the argument shifting for methods from the handling of
416416
keyword arguments and allows better specialization of calls.

Include/opcode.h

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

Lib/importlib/_bootstrap_external.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,7 @@ def _write_atomic(path, data, mode=0o666):
385385
# Python 3.11a5 3477 (Replace DUP_TOP/DUP_TOP_TWO with COPY and
386386
# ROT_TWO/ROT_THREE/ROT_FOUR/ROT_N with SWAP)
387387
# Python 3.11a5 3478 (New CALL opcodes)
388+
# Python 3.11a5 3479 (Add PUSH_NULL opcode)
388389

389390
# Python 3.12 will start with magic number 3500
390391

@@ -402,7 +403,7 @@ def _write_atomic(path, data, mode=0o666):
402403
# Whenever MAGIC_NUMBER is changed, the ranges in the magic_values array
403404
# in PC/launcher.c must also be updated.
404405

405-
MAGIC_NUMBER = (3478).to_bytes(2, 'little') + b'\r\n'
406+
MAGIC_NUMBER = (3479).to_bytes(2, 'little') + b'\r\n'
406407
_RAW_MAGIC_NUMBER = int.from_bytes(MAGIC_NUMBER, 'little') # For import.c
407408

408409
_PYCACHE = '__pycache__'

Lib/opcode.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ def jabs_op(name, op):
5555
# Blank lines correspond to available opcodes
5656

5757
def_op('POP_TOP', 1)
58+
def_op('PUSH_NULL', 2)
5859

5960
def_op('NOP', 9)
6061
def_op('UNARY_POSITIVE', 10)
@@ -187,9 +188,7 @@ def jabs_op(name, op):
187188
def_op('SET_UPDATE', 163)
188189
def_op('DICT_MERGE', 164)
189190
def_op('DICT_UPDATE', 165)
190-
191-
def_op('PRECALL_FUNCTION', 167)
192-
def_op('PRECALL_METHOD', 168)
191+
def_op('PRECALL', 166)
193192

194193
def_op('CALL', 171)
195194
def_op('KW_NAMES', 172)

Lib/test/test_compile.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -838,7 +838,7 @@ def foo(x):
838838
instructions = [opcode.opname for opcode in opcodes]
839839
self.assertNotIn('LOAD_METHOD', instructions)
840840
self.assertIn('LOAD_ATTR', instructions)
841-
self.assertIn('PRECALL_FUNCTION', instructions)
841+
self.assertIn('PRECALL', instructions)
842842

843843
def test_lineno_procedure_call(self):
844844
def call():

0 commit comments

Comments
 (0)