Skip to content

Commit 72119d1

Browse files
authored
gh-105481: remove regen-opcode. Generated _PyOpcode_Caches in regen-cases. (#108367)
1 parent 422f81b commit 72119d1

19 files changed

+78
-176
lines changed

Include/internal/pycore_opcode.h

-40
This file was deleted.

Include/internal/pycore_opcode_metadata.h

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

Include/internal/pycore_opcode_utils.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ extern "C" {
88
# error "this header requires Py_BUILD_CORE define"
99
#endif
1010

11-
#include "pycore_opcode.h" // JUMP_FORWARD
12-
11+
#include "opcode_ids.h"
1312

1413
#define MAX_REAL_OPCODE 254
1514

Lib/opcode.py

+23-31
Original file line numberDiff line numberDiff line change
@@ -5,48 +5,40 @@
55
"""
66

77

8-
# Note that __all__ is further extended below
9-
__all__ = ["cmp_op", "stack_effect", "hascompare"]
8+
__all__ = ["cmp_op", "stack_effect", "hascompare", "opname", "opmap",
9+
"HAVE_ARGUMENT", "EXTENDED_ARG", "hasarg", "hasconst", "hasname",
10+
"hasjump", "hasjrel", "hasjabs", "hasfree", "haslocal", "hasexc"]
1011

1112
import _opcode
1213
from _opcode import stack_effect
1314

14-
import sys
15-
# The build uses older versions of Python which do not have _opcode_metadata
16-
if sys.version_info[:2] >= (3, 13):
17-
from _opcode_metadata import _specializations, _specialized_opmap
18-
from _opcode_metadata import opmap, HAVE_ARGUMENT, MIN_INSTRUMENTED_OPCODE
19-
EXTENDED_ARG = opmap['EXTENDED_ARG']
15+
from _opcode_metadata import (_specializations, _specialized_opmap, opmap,
16+
HAVE_ARGUMENT, MIN_INSTRUMENTED_OPCODE)
17+
EXTENDED_ARG = opmap['EXTENDED_ARG']
2018

21-
opname = ['<%r>' % (op,) for op in range(max(opmap.values()) + 1)]
22-
for op, i in opmap.items():
23-
opname[i] = op
24-
25-
__all__.extend(["opname", "opmap", "HAVE_ARGUMENT", "EXTENDED_ARG"])
19+
opname = ['<%r>' % (op,) for op in range(max(opmap.values()) + 1)]
20+
for op, i in opmap.items():
21+
opname[i] = op
2622

2723
cmp_op = ('<', '<=', '==', '!=', '>', '>=')
2824

29-
# The build uses older versions of Python which do not have _opcode.has_* functions
30-
if sys.version_info[:2] >= (3, 13):
31-
# These lists are documented as part of the dis module's API
32-
hasarg = [op for op in opmap.values() if _opcode.has_arg(op)]
33-
hasconst = [op for op in opmap.values() if _opcode.has_const(op)]
34-
hasname = [op for op in opmap.values() if _opcode.has_name(op)]
35-
hasjump = [op for op in opmap.values() if _opcode.has_jump(op)]
36-
hasjrel = hasjump # for backward compatibility
37-
hasjabs = []
38-
hasfree = [op for op in opmap.values() if _opcode.has_free(op)]
39-
haslocal = [op for op in opmap.values() if _opcode.has_local(op)]
40-
hasexc = [op for op in opmap.values() if _opcode.has_exc(op)]
25+
# These lists are documented as part of the dis module's API
26+
hasarg = [op for op in opmap.values() if _opcode.has_arg(op)]
27+
hasconst = [op for op in opmap.values() if _opcode.has_const(op)]
28+
hasname = [op for op in opmap.values() if _opcode.has_name(op)]
29+
hasjump = [op for op in opmap.values() if _opcode.has_jump(op)]
30+
hasjrel = hasjump # for backward compatibility
31+
hasjabs = []
32+
hasfree = [op for op in opmap.values() if _opcode.has_free(op)]
33+
haslocal = [op for op in opmap.values() if _opcode.has_local(op)]
34+
hasexc = [op for op in opmap.values() if _opcode.has_exc(op)]
4135

42-
__all__.extend(["hasarg", "hasconst", "hasname", "hasjump", "hasjrel",
43-
"hasjabs", "hasfree", "haslocal", "hasexc"])
4436

45-
_intrinsic_1_descs = _opcode.get_intrinsic1_descs()
46-
_intrinsic_2_descs = _opcode.get_intrinsic2_descs()
47-
_nb_ops = _opcode.get_nb_ops()
37+
_intrinsic_1_descs = _opcode.get_intrinsic1_descs()
38+
_intrinsic_2_descs = _opcode.get_intrinsic2_descs()
39+
_nb_ops = _opcode.get_nb_ops()
4840

49-
hascompare = [opmap["COMPARE_OP"]]
41+
hascompare = [opmap["COMPARE_OP"]]
5042

5143
_cache_format = {
5244
"LOAD_GLOBAL": {

Makefile.pre.in

+3-11
Original file line numberDiff line numberDiff line change
@@ -1321,7 +1321,7 @@ regen-limited-abi: all
13211321
# Regenerate all generated files
13221322

13231323
.PHONY: regen-all
1324-
regen-all: regen-cases regen-opcode regen-typeslots \
1324+
regen-all: regen-cases regen-typeslots \
13251325
regen-token regen-ast regen-keyword regen-sre regen-frozen clinic \
13261326
regen-pegen-metaparser regen-pegen regen-test-frozenmain \
13271327
regen-test-levenshtein regen-global-objects
@@ -1425,15 +1425,6 @@ regen-ast:
14251425
$(UPDATE_FILE) $(srcdir)/Include/internal/pycore_ast_state.h $(srcdir)/Include/internal/pycore_ast_state.h.new
14261426
$(UPDATE_FILE) $(srcdir)/Python/Python-ast.c $(srcdir)/Python/Python-ast.c.new
14271427

1428-
.PHONY: regen-opcode
1429-
regen-opcode:
1430-
# Regenerate Include/internal/pycore_opcode.h from Lib/opcode.py
1431-
# using Tools/build/generate_opcode_h.py
1432-
$(PYTHON_FOR_REGEN) $(srcdir)/Tools/build/generate_opcode_h.py \
1433-
$(srcdir)/Lib/opcode.py \
1434-
$(srcdir)/Include/internal/pycore_opcode.h.new
1435-
$(UPDATE_FILE) $(srcdir)/Include/internal/pycore_opcode.h $(srcdir)/Include/internal/pycore_opcode.h.new
1436-
14371428
.PHONY: regen-token
14381429
regen-token:
14391430
# Regenerate Doc/library/token-list.inc from Grammar/Tokens
@@ -1651,6 +1642,7 @@ PYTHON_HEADERS= \
16511642
$(srcdir)/Include/object.h \
16521643
$(srcdir)/Include/objimpl.h \
16531644
$(srcdir)/Include/opcode.h \
1645+
$(srcdir)/Include/opcode_ids.h \
16541646
$(srcdir)/Include/osdefs.h \
16551647
$(srcdir)/Include/osmodule.h \
16561648
$(srcdir)/Include/patchlevel.h \
@@ -1790,7 +1782,7 @@ PYTHON_HEADERS= \
17901782
$(srcdir)/Include/internal/pycore_object_state.h \
17911783
$(srcdir)/Include/internal/pycore_obmalloc.h \
17921784
$(srcdir)/Include/internal/pycore_obmalloc_init.h \
1793-
$(srcdir)/Include/internal/pycore_opcode.h \
1785+
$(srcdir)/Include/internal/pycore_opcode_metadata.h \
17941786
$(srcdir)/Include/internal/pycore_opcode_utils.h \
17951787
$(srcdir)/Include/internal/pycore_optimizer.h \
17961788
$(srcdir)/Include/internal/pycore_pathconfig.h \
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
The regen-opcode build stage was removed and its work is now done in
2+
regen-cases.

Objects/codeobject.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
#include "pycore_code.h" // _PyCodeConstructor
77
#include "pycore_frame.h" // FRAME_SPECIALS_SIZE
88
#include "pycore_interp.h" // PyInterpreterState.co_extra_freefuncs
9-
#include "pycore_opcode.h" // _PyOpcode_Caches
10-
#include "pycore_opcode_metadata.h" // _PyOpcode_Deopt
9+
#include "pycore_opcode_metadata.h" // _PyOpcode_Deopt, _PyOpcode_Caches
1110
#include "pycore_pystate.h" // _PyInterpreterState_GET()
1211
#include "pycore_setobject.h" // _PySet_NextEntry()
1312
#include "pycore_tuple.h" // _PyTuple_ITEMS()

Objects/frameobject.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
#include "pycore_function.h" // _PyFunction_FromConstructor()
77
#include "pycore_moduleobject.h" // _PyModule_GetDict()
88
#include "pycore_object.h" // _PyObject_GC_UNTRACK()
9-
#include "pycore_opcode.h" // _PyOpcode_Caches
10-
#include "pycore_opcode_metadata.h" // _PyOpcode_Deopt
9+
#include "pycore_opcode_metadata.h" // _PyOpcode_Deopt, _PyOpcode_Caches
1110

1211

1312
#include "frameobject.h" // PyFrameObject

PCbuild/regen.targets

+2-12
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
<_ASTOutputs Include="$(PySourcePath)Python\Python-ast.c">
1414
<Argument>-C</Argument>
1515
</_ASTOutputs>
16-
<_OpcodeSources Include="$(PySourcePath)Tools\build\generate_opcode_h.py;$(PySourcePath)Lib\opcode.py" />
17-
<_OpcodeOutputs Include="$(PySourcePath)Include\internal\pycore_opcode.h" />
1816
<_TokenSources Include="$(PySourcePath)Grammar\Tokens" />
1917
<_TokenOutputs Include="$(PySourcePath)Doc\library\token-list.inc">
2018
<Format>rst</Format>
@@ -34,7 +32,7 @@
3432

3533
<Target Name="_TouchRegenSources" Condition="$(ForceRegen) == 'true'">
3634
<Message Text="Touching source files to force regeneration" Importance="high" />
37-
<Touch Files="@(_PegenSources);@(_ASTSources);@(_OpcodeSources);@(_TokenSources);@(_KeywordOutputs)"
35+
<Touch Files="@(_PegenSources);@(_ASTSources);@(_TokenSources);@(_KeywordOutputs)"
3836
AlwaysCreate="False" />
3937
</Target>
4038

@@ -55,14 +53,6 @@
5553
WorkingDirectory="$(PySourcePath)" />
5654
</Target>
5755

58-
<Target Name="_RegenOpcodes"
59-
Inputs="@(_OpcodeSources)" Outputs="@(_OpcodeOutputs)"
60-
DependsOnTargets="FindPythonForBuild">
61-
<Message Text="Regenerate @(_OpcodeOutputs->'%(Filename)%(Extension)',' ')" Importance="high" />
62-
<Exec Command="$(PythonForBuild) Tools\build\generate_opcode_h.py Lib\opcode.py Include\internal\pycore_opcode.h Include\internal\pycore_intrinsics.h"
63-
WorkingDirectory="$(PySourcePath)" />
64-
</Target>
65-
6656
<Target Name="_RegenTokens"
6757
Inputs="@(_TokenSources)" Outputs="@(_TokenOutputs)"
6858
DependsOnTargets="FindPythonForBuild">
@@ -89,7 +79,7 @@
8979

9080
<Target Name="Regen"
9181
Condition="$(Configuration) != 'PGUpdate'"
92-
DependsOnTargets="_TouchRegenSources;_RegenPegen;_RegenAST_H;_RegenOpcodes;_RegenTokens;_RegenKeywords;_RegenGlobalObjects">
82+
DependsOnTargets="_TouchRegenSources;_RegenPegen;_RegenAST_H;_RegenTokens;_RegenKeywords;_RegenGlobalObjects">
9383
<Message Text="Generated sources are up to date" Importance="high" />
9484
</Target>
9585

Python/assemble.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33
#include "Python.h"
44
#include "pycore_code.h" // write_location_entry_start()
55
#include "pycore_compile.h"
6-
#include "pycore_opcode.h" // _PyOpcode_Caches[] and opcode category macros
76
#include "pycore_opcode_utils.h" // IS_BACKWARDS_JUMP_OPCODE
8-
#include "pycore_opcode_metadata.h" // IS_PSEUDO_INSTR
7+
#include "pycore_opcode_metadata.h" // IS_PSEUDO_INSTR, _PyOpcode_Caches
98

109

1110
#define DEFAULT_CODE_SIZE 128

Python/ceval.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414
#include "pycore_long.h" // _PyLong_GetZero()
1515
#include "pycore_moduleobject.h" // PyModuleObject
1616
#include "pycore_object.h" // _PyObject_GC_TRACK()
17-
#include "pycore_opcode.h" // EXTRA_CASES
18-
#include "pycore_opcode_metadata.h"
17+
#include "pycore_opcode_metadata.h" // EXTRA_CASES
1918
#include "pycore_opcode_utils.h" // MAKE_FUNCTION_*
2019
#include "pycore_pyerrors.h" // _PyErr_GetRaisedException()
2120
#include "pycore_pystate.h" // _PyInterpreterState_GET()

Python/compile.c

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <stdbool.h>
2525

2626
#include "Python.h"
27+
#include "opcode.h"
2728
#include "pycore_ast.h" // _PyAST_GetDocString()
2829
#define NEED_OPCODE_TABLES
2930
#include "pycore_opcode_utils.h"

Python/executor.c

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#include "Python.h"
22

3+
#include "opcode.h"
4+
35
#include "pycore_call.h"
46
#include "pycore_ceval.h"
57
#include "pycore_dict.h"

Python/instrumentation.c

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
#include "Python.h"
2+
3+
#include "opcode_ids.h"
4+
25
#include "pycore_call.h"
36
#include "pycore_frame.h"
47
#include "pycore_interp.h"
58
#include "pycore_long.h"
69
#include "pycore_modsupport.h" // _PyModule_CreateInitialized()
710
#include "pycore_namespace.h"
811
#include "pycore_object.h"
9-
#include "pycore_opcode.h"
10-
#include "pycore_opcode_metadata.h" // IS_VALID_OPCODE
12+
#include "pycore_opcode_metadata.h" // IS_VALID_OPCODE, _PyOpcode_Caches
1113
#include "pycore_pyerrors.h"
1214
#include "pycore_pystate.h" // _PyInterpreterState_GET()
1315

Python/optimizer.c

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#include "Python.h"
22
#include "opcode.h"
33
#include "pycore_interp.h"
4-
#include "pycore_opcode.h"
54
#include "pycore_opcode_metadata.h"
65
#include "pycore_opcode_utils.h"
76
#include "pycore_optimizer.h"

Python/optimizer_analysis.c

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#include "Python.h"
22
#include "opcode.h"
33
#include "pycore_interp.h"
4-
#include "pycore_opcode.h"
54
#include "pycore_opcode_metadata.h"
65
#include "pycore_opcode_utils.h"
76
#include "pycore_pystate.h" // _PyInterpreterState_GET()

Python/specialize.c

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
#include "Python.h"
2+
3+
#include "opcode.h"
4+
25
#include "pycore_code.h"
36
#include "pycore_descrobject.h" // _PyMethodWrapper_Type
47
#include "pycore_dict.h"
@@ -7,7 +10,7 @@
710
#include "pycore_long.h"
811
#include "pycore_moduleobject.h"
912
#include "pycore_object.h"
10-
#include "pycore_opcode.h" // _PyOpcode_Caches
13+
#include "pycore_opcode_metadata.h" // _PyOpcode_Caches
1114
#include "pycore_pylifecycle.h" // _PyOS_URandomNonblock()
1215

1316

0 commit comments

Comments
 (0)