Skip to content

Commit 665a439

Browse files
authored
gh-105481: generate op IDs from bytecode.c instead of hard coding them in opcode.py (#107971)
1 parent e88eb37 commit 665a439

21 files changed

+1533
-1461
lines changed

Include/internal/pycore_opcode.h

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

Include/internal/pycore_opcode_metadata.h

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

Include/opcode_ids.h

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

Lib/_opcode_metadata.py

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

Lib/dis.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
_intrinsic_1_descs,
1515
_intrinsic_2_descs,
1616
_specializations,
17-
_specialized_instructions,
17+
_specialized_opmap,
1818
)
1919

2020
__all__ = ["code_info", "dis", "disassemble", "distb", "disco",
@@ -49,11 +49,11 @@
4949

5050
_all_opname = list(opname)
5151
_all_opmap = dict(opmap)
52-
_empty_slot = [slot for slot, name in enumerate(_all_opname) if name.startswith("<")]
53-
for spec_op, specialized in zip(_empty_slot, _specialized_instructions):
52+
for name, op in _specialized_opmap.items():
5453
# fill opname and opmap
55-
_all_opname[spec_op] = specialized
56-
_all_opmap[specialized] = spec_op
54+
assert op < len(_all_opname)
55+
_all_opname[op] = name
56+
_all_opmap[name] = op
5757

5858
deoptmap = {
5959
specialized: base for base, family in _specializations.items() for specialized in family

Lib/importlib/_bootstrap_external.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,7 @@ def _write_atomic(path, data, mode=0o666):
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)
456456
# Python 3.13a1 3558 (Reorder the stack items for CALL)
457+
# Python 3.13a1 3559 (Generate opcode IDs from bytecodes.c)
457458

458459
# Python 3.14 will start with 3600
459460

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

473-
MAGIC_NUMBER = (3558).to_bytes(2, 'little') + b'\r\n'
474+
MAGIC_NUMBER = (3559).to_bytes(2, 'little') + b'\r\n'
474475

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

0 commit comments

Comments
 (0)