Skip to content

Commit b51de05

Browse files
committed
remove _PyCounterOptimizer_Type and _PyOptimizer_NewCounter
1 parent e4f6f46 commit b51de05

File tree

7 files changed

+7
-36
lines changed

7 files changed

+7
-36
lines changed

Include/internal/pycore_optimizer.h

-2
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ PyAPI_FUNC(void) _Py_Executor_DependsOn(_PyExecutorObject *executor, void *obj);
118118
// Export for '_testinternalcapi' shared extension.
119119
PyAPI_FUNC(_PyOptimizerObject *) _Py_GetOptimizer(void);
120120
PyAPI_FUNC(int) _Py_SetTier2Optimizer(_PyOptimizerObject* optimizer);
121-
PyAPI_FUNC(PyObject *) _PyOptimizer_NewCounter(void);
122121
PyAPI_FUNC(PyObject *) _PyOptimizer_NewUOpOptimizer(void);
123122

124123
#define _Py_MAX_ALLOWED_BUILTINS_MODIFICATIONS 3
@@ -150,7 +149,6 @@ int _Py_uop_analyze_and_optimize(struct _PyInterpreterFrame *frame,
150149
_PyBloomFilter *dependencies);
151150

152151
extern PyTypeObject _PyCounterExecutor_Type;
153-
extern PyTypeObject _PyCounterOptimizer_Type;
154152
extern PyTypeObject _PyDefaultOptimizer_Type;
155153
extern PyTypeObject _PyUOpExecutor_Type;
156154
extern PyTypeObject _PyUOpOptimizer_Type;

Lib/test/test_capi/test_opt.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ def clear_executors(func):
3636

3737
@requires_specialization
3838
@unittest.skipIf(Py_GIL_DISABLED, "optimizer not yet supported in free-threaded builds")
39-
@unittest.skipUnless(hasattr(_testinternalcapi, "get_optimizer"),
39+
@unittest.skipUnless(hasattr(_testinternalcapi, "get_optimizer") and
40+
hasattr(_testinternalcapi, "new_counter_optimizer"),
4041
"Requires optimizer infrastructure")
4142
class TestOptimizerAPI(unittest.TestCase):
4243

@@ -222,7 +223,8 @@ def f():
222223

223224
@requires_specialization
224225
@unittest.skipIf(Py_GIL_DISABLED, "optimizer not yet supported in free-threaded builds")
225-
@unittest.skipUnless(hasattr(_testinternalcapi, "get_optimizer"),
226+
@unittest.skipUnless(hasattr(_testinternalcapi, "get_optimizer") and
227+
hasattr(_testinternalcapi, "new_counter_optimizer"),
226228
"Requires optimizer infrastructure")
227229
class TestExecutorInvalidation(unittest.TestCase):
228230

Lib/test/test_monitoring.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from test.support.import_helper import import_module
1616

1717
_testcapi = test.support.import_helper.import_module("_testcapi")
18+
_testinternalcapi = test.support.import_helper.import_module("_testinternalcapi")
1819

1920
PAIR = (0,1)
2021

@@ -1959,10 +1960,11 @@ def callback(code, instruction_offset):
19591960
sys.monitoring.set_events(0, 0)
19601961

19611962

1963+
@unittest.skipUnless(hasattr(_testinternalcapi, "new_counter_optimizer"),
1964+
"Requires counter optimizer")
19621965
class TestOptimizer(MonitoringTestBase, unittest.TestCase):
19631966

19641967
def setUp(self):
1965-
_testinternalcapi = import_module("_testinternalcapi")
19661968
if hasattr(_testinternalcapi, "get_optimizer"):
19671969
self.old_opt = _testinternalcapi.get_optimizer()
19681970
opt = _testinternalcapi.new_counter_optimizer()

Modules/_testinternalcapi.c

-7
Original file line numberDiff line numberDiff line change
@@ -989,12 +989,6 @@ get_co_framesize(PyObject *self, PyObject *arg)
989989

990990
#ifdef _Py_TIER2
991991

992-
static PyObject *
993-
new_counter_optimizer(PyObject *self, PyObject *arg)
994-
{
995-
return _PyOptimizer_NewCounter();
996-
}
997-
998992
static PyObject *
999993
new_uop_optimizer(PyObject *self, PyObject *arg)
1000994
{
@@ -2112,7 +2106,6 @@ static PyMethodDef module_functions[] = {
21122106
#ifdef _Py_TIER2
21132107
{"get_optimizer", get_optimizer, METH_NOARGS, NULL},
21142108
{"set_optimizer", set_optimizer, METH_O, NULL},
2115-
{"new_counter_optimizer", new_counter_optimizer, METH_NOARGS, NULL},
21162109
{"new_uop_optimizer", new_uop_optimizer, METH_NOARGS, NULL},
21172110
{"add_executor_dependency", add_executor_dependency, METH_VARARGS, NULL},
21182111
{"invalidate_executors", invalidate_executors, METH_O, NULL},

Objects/object.c

-1
Original file line numberDiff line numberDiff line change
@@ -2345,7 +2345,6 @@ static PyTypeObject* static_types[] = {
23452345
&_PyCoroWrapper_Type,
23462346
#ifdef _Py_TIER2
23472347
&_PyCounterExecutor_Type,
2348-
&_PyCounterOptimizer_Type,
23492348
&_PyDefaultOptimizer_Type,
23502349
#endif
23512350
&_Py_GenericAliasIterType,

Python/optimizer.c

-22
Original file line numberDiff line numberDiff line change
@@ -1387,28 +1387,6 @@ static PyMethodDef counter_optimizer_methods[] = {
13871387
{ NULL, NULL },
13881388
};
13891389

1390-
PyTypeObject _PyCounterOptimizer_Type = {
1391-
PyVarObject_HEAD_INIT(&PyType_Type, 0)
1392-
.tp_name = "Counter optimizer",
1393-
.tp_basicsize = sizeof(_PyCounterOptimizerObject),
1394-
.tp_itemsize = 0,
1395-
.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_DISALLOW_INSTANTIATION,
1396-
.tp_methods = counter_optimizer_methods,
1397-
.tp_dealloc = (destructor)PyObject_Free,
1398-
};
1399-
1400-
PyObject *
1401-
_PyOptimizer_NewCounter(void)
1402-
{
1403-
_PyCounterOptimizerObject *opt = (_PyCounterOptimizerObject *)_PyObject_New(&_PyCounterOptimizer_Type);
1404-
if (opt == NULL) {
1405-
return NULL;
1406-
}
1407-
opt->base.optimize = counter_optimize;
1408-
opt->count = 0;
1409-
return (PyObject *)opt;
1410-
}
1411-
14121390

14131391
/*****************************************
14141392
* Executor management

Tools/c-analyzer/cpython/ignored.tsv

-1
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,6 @@ Python/sysmodule.c - _PySys_ImplName -
384384
Python/sysmodule.c - whatstrings -
385385
Python/optimizer.c - _PyDefaultOptimizer_Type -
386386
Python/optimizer.c - _PyCounterExecutor_Type -
387-
Python/optimizer.c - _PyCounterOptimizer_Type -
388387
Python/optimizer.c - _PyUOpExecutor_Type -
389388
Python/optimizer.c - _PyUOpOptimizer_Type -
390389
Python/optimizer.c - _PyOptimizer_Default -

0 commit comments

Comments
 (0)