Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 828b276

Browse files
authored
GH-126599: Remove the PyOptimizer API (GH-129194)
1 parent 5c930a2 commit 828b276

23 files changed

+340
-430
lines changed

Include/internal/pycore_interp.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ extern "C" {
3131
#include "pycore_list.h" // struct _Py_list_state
3232
#include "pycore_mimalloc.h" // struct _mimalloc_interp_state
3333
#include "pycore_object_state.h" // struct _py_object_state
34-
#include "pycore_optimizer.h" // _PyOptimizerObject
34+
#include "pycore_optimizer.h" // _PyExecutorObject
3535
#include "pycore_obmalloc.h" // struct _obmalloc_state
3636
#include "pycore_qsbr.h" // struct _qsbr_state
3737
#include "pycore_stackref.h" // Py_STACKREF_DEBUG
@@ -262,7 +262,7 @@ struct _is {
262262
struct ast_state ast;
263263
struct types_state types;
264264
struct callable_cache callable_cache;
265-
_PyOptimizerObject *optimizer;
265+
bool jit;
266266
_PyExecutorObject *executor_list_head;
267267
size_t trace_run_counter;
268268
_rare_events rare_events;

Include/internal/pycore_opcode_metadata.h

Lines changed: 22 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/internal/pycore_optimizer.h

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -83,23 +83,6 @@ typedef struct _PyExecutorObject {
8383
_PyExitData exits[1];
8484
} _PyExecutorObject;
8585

86-
typedef struct _PyOptimizerObject _PyOptimizerObject;
87-
88-
/* Should return > 0 if a new executor is created. O if no executor is produced and < 0 if an error occurred. */
89-
typedef int (*_Py_optimize_func)(
90-
_PyOptimizerObject* self, struct _PyInterpreterFrame *frame,
91-
_Py_CODEUNIT *instr, _PyExecutorObject **exec_ptr,
92-
int curr_stackentries, bool progress_needed);
93-
94-
struct _PyOptimizerObject {
95-
PyObject_HEAD
96-
_Py_optimize_func optimize;
97-
/* Data needed by the optimizer goes here, but is opaque to the VM */
98-
};
99-
100-
/** Test support **/
101-
_PyOptimizerObject *_Py_SetOptimizer(PyInterpreterState *interp, _PyOptimizerObject* optimizer);
102-
10386

10487
// Export for '_opcode' shared extension (JIT compiler).
10588
PyAPI_FUNC(_PyExecutorObject*) _Py_GetExecutor(PyCodeObject *code, int offset);
@@ -110,12 +93,6 @@ void _Py_BloomFilter_Init(_PyBloomFilter *);
11093
void _Py_BloomFilter_Add(_PyBloomFilter *bloom, void *obj);
11194
PyAPI_FUNC(void) _Py_Executor_DependsOn(_PyExecutorObject *executor, void *obj);
11295

113-
// For testing
114-
// Export for '_testinternalcapi' shared extension.
115-
PyAPI_FUNC(_PyOptimizerObject *) _Py_GetOptimizer(void);
116-
PyAPI_FUNC(int) _Py_SetTier2Optimizer(_PyOptimizerObject* optimizer);
117-
PyAPI_FUNC(PyObject *) _PyOptimizer_NewUOpOptimizer(void);
118-
11996
#define _Py_MAX_ALLOWED_BUILTINS_MODIFICATIONS 3
12097
#define _Py_MAX_ALLOWED_GLOBALS_MODIFICATIONS 6
12198

@@ -144,9 +121,7 @@ int _Py_uop_analyze_and_optimize(struct _PyInterpreterFrame *frame,
144121
_PyUOpInstruction *trace, int trace_len, int curr_stackentries,
145122
_PyBloomFilter *dependencies);
146123

147-
extern PyTypeObject _PyDefaultOptimizer_Type;
148124
extern PyTypeObject _PyUOpExecutor_Type;
149-
extern PyTypeObject _PyUOpOptimizer_Type;
150125

151126

152127
#define UOP_FORMAT_TARGET 0

Include/opcode_ids.h

Lines changed: 37 additions & 35 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

InternalDocs/jit.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,8 @@ executor in `co_executors`.
3838

3939
## The micro-op optimizer
4040

41-
The optimizer that `_PyOptimizer_Optimize()` runs is configurable via the
42-
`_Py_SetTier2Optimizer()` function (this is used in test via
43-
`_testinternalcapi.set_optimizer()`.)
44-
4541
The micro-op (abbreviated `uop` to approximate `μop`) optimizer is defined in
46-
[`Python/optimizer.c`](../Python/optimizer.c) as the type `_PyUOpOptimizer_Type`.
42+
[`Python/optimizer.c`](../Python/optimizer.c) as `_PyOptimizer_Optimize`.
4743
It translates an instruction trace into a sequence of micro-ops by replacing
4844
each bytecode by an equivalent sequence of micro-ops (see
4945
`_PyOpcode_macro_expansion` in

Lib/_opcode_metadata.py

Lines changed: 41 additions & 35 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Lib/test/support/__init__.py

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@
5858
"LOOPBACK_TIMEOUT", "INTERNET_TIMEOUT", "SHORT_TIMEOUT", "LONG_TIMEOUT",
5959
"Py_DEBUG", "exceeds_recursion_limit", "get_c_recursion_limit",
6060
"skip_on_s390x",
61-
"without_optimizer",
61+
"requires_jit_enabled",
62+
"requires_jit_disabled",
6263
"force_not_colorized",
6364
"force_not_colorized_test_class",
6465
"make_clean_env",
@@ -2620,21 +2621,13 @@ def exceeds_recursion_limit():
26202621

26212622
Py_TRACE_REFS = hasattr(sys, 'getobjects')
26222623

2623-
# Decorator to disable optimizer while a function run
2624-
def without_optimizer(func):
2625-
try:
2626-
from _testinternalcapi import get_optimizer, set_optimizer
2627-
except ImportError:
2628-
return func
2629-
@functools.wraps(func)
2630-
def wrapper(*args, **kwargs):
2631-
save_opt = get_optimizer()
2632-
try:
2633-
set_optimizer(None)
2634-
return func(*args, **kwargs)
2635-
finally:
2636-
set_optimizer(save_opt)
2637-
return wrapper
2624+
try:
2625+
from _testinternalcapi import jit_enabled
2626+
except ImportError:
2627+
requires_jit_enabled = requires_jit_disabled = unittest.skip("requires _testinternalcapi")
2628+
else:
2629+
requires_jit_enabled = unittest.skipUnless(jit_enabled(), "requires JIT enabled")
2630+
requires_jit_disabled = unittest.skipIf(jit_enabled(), "requires JIT disabled")
26382631

26392632

26402633
_BASE_COPY_SRC_DIR_IGNORED_NAMES = frozenset({

Lib/test/test_capi/test_misc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ def test_getitem_with_error(self):
306306
CURRENT_THREAD_REGEX +
307307
r' File .*, line 6 in <module>\n'
308308
r'\n'
309-
r'Extension modules: _testcapi \(total: 1\)\n')
309+
r'Extension modules: _testcapi, _testinternalcapi \(total: 2\)\n')
310310
else:
311311
# Python built with NDEBUG macro defined:
312312
# test _Py_CheckFunctionResult() instead.

0 commit comments

Comments
 (0)