Skip to content

Commit 11b0e43

Browse files
committed
Add test for T2 symbols
1 parent bc4583c commit 11b0e43

File tree

4 files changed

+19
-19
lines changed

4 files changed

+19
-19
lines changed

Include/internal/pycore_optimizer.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,7 @@ extern bool _Py_uop_sym_matches_type(_Py_UOpsSymType *sym, PyTypeObject *typ);
9696
extern void _Py_uop_sym_set_null(_Py_UOpsSymType *sym);
9797
extern void _Py_uop_sym_set_type(_Py_UOpsSymType *sym, PyTypeObject *tp);
9898

99-
extern int _Py_uop_abstractcontext_init(
100-
_Py_UOpsAbstractInterpContext *ctx, PyCodeObject *co,
101-
int curr_stacklen, int ir_entries);
99+
extern int _Py_uop_abstractcontext_init(_Py_UOpsAbstractInterpContext *ctx);
102100
extern void _Py_uop_abstractcontext_fini(_Py_UOpsAbstractInterpContext *ctx);
103101

104102
extern _Py_UOpsAbstractFrame *_Py_uop_ctx_frame_new(
@@ -109,6 +107,9 @@ extern _Py_UOpsAbstractFrame *_Py_uop_ctx_frame_new(
109107
int curr_stackentries);
110108
extern int _Py_uop_ctx_frame_pop(_Py_UOpsAbstractInterpContext *ctx);
111109

110+
PyAPI_FUNC(PyObject *)
111+
_Py_uop_symbols_test(PyObject *self, PyObject *ignored);
112+
112113
#ifdef __cplusplus
113114
}
114115
#endif

Lib/test/test_optimizer.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,5 +77,12 @@ def func(x=0):
7777
_testinternalcapi.get_rare_event_counters()["func_modification"]
7878
)
7979

80+
81+
class TestOptimizerSymbols(unittest.TestCase):
82+
83+
def test_optimizer_symbols(self):
84+
_testinternalcapi.uop_symbols_test()
85+
86+
8087
if __name__ == "__main__":
8188
unittest.main()

Modules/_testinternalcapi.c

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1678,17 +1678,6 @@ get_py_thread_id(PyObject *self, PyObject *Py_UNUSED(ignored))
16781678
}
16791679
#endif
16801680

1681-
1682-
static PyObject *
1683-
test_uop_symbols(PyObject *self, PyObject *Py_UNUSED(ignored))
1684-
{
1685-
_Py_UOpsAbstractInterpContext context;
1686-
_Py_UOpsAbstractInterpContext *ctx = &context;
1687-
_Py_UOpsSymType * unknown = Py_uop_sym_newunknown(ctx);
1688-
1689-
}
1690-
1691-
16921681
static PyMethodDef module_functions[] = {
16931682
{"get_configs", get_configs, METH_NOARGS},
16941683
{"get_recursion_depth", get_recursion_depth, METH_NOARGS},
@@ -1758,7 +1747,7 @@ static PyMethodDef module_functions[] = {
17581747
#ifdef Py_GIL_DISABLED
17591748
{"py_thread_id", get_py_thread_id, METH_NOARGS},
17601749
#endif
1761-
{"test_uop_symbols", test_uop_symbols, METH_NOARGS},
1750+
{"uop_symbols_test", _Py_uop_symbols_test, METH_NOARGS},
17621751
{NULL, NULL} /* sentinel */
17631752
};
17641753

Python/optimizer_analysis.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -296,12 +296,15 @@ uop_redundancy_eliminator(
296296
_Py_UOpsAbstractInterpContext context;
297297
_Py_UOpsAbstractInterpContext *ctx = &context;
298298

299-
if (_Py_uop_abstractcontext_init(
300-
ctx,
301-
co, curr_stacklen,
302-
trace_len) < 0) {
299+
if (_Py_uop_abstractcontext_init(ctx) < 0) {
303300
goto out_of_space;
304301
}
302+
_Py_UOpsAbstractFrame *frame = _Py_uop_ctx_frame_new(ctx, co, ctx->n_consumed, 0, curr_stacklen);
303+
if (frame == NULL) {
304+
return -1;
305+
}
306+
ctx->curr_frame_depth++;
307+
ctx->frame = frame;
305308

306309
for (_PyUOpInstruction *this_instr = trace;
307310
this_instr < trace + trace_len && !op_is_end(this_instr->opcode);

0 commit comments

Comments
 (0)