mirror of
https://github.com/python/cpython.git
synced 2025-08-22 17:55:18 +00:00
gh-115859: Re-enable T2 optimizer pass by default (#116062)
This undoes the *temporary* default disabling of the T2 optimizer pass in gh-115860. - Add a new test that reproduces Brandt's example from gh-115859; it indeed crashes before gh-116028 with PYTHONUOPSOPTIMIZE=1 - Re-enable the optimizer pass in T2, stop checking PYTHONUOPSOPTIMIZE - Rename the env var to disable T2 entirely to PYTHON_UOPS_OPTIMIZE (must be explicitly set to 0 to disable) - Fix skipIf conditions on tests in test_opt.py accordingly - Export sym_is_bottom() (for debugging) - Fix various things in the `_BINARY_OP_` specializations in the abstract interpreter: - DECREF(temp) - out-of-space check after sym_new_const() - add sym_matches_type() checks, so even if we somehow reach a binary op with symbolic constants of the wrong type on the stack we won't trigger the type assert
This commit is contained in:
parent
75c6c05fea
commit
3409bc29c9
7 changed files with 96 additions and 28 deletions
|
@ -25,6 +25,7 @@ typedef struct _Py_UOpsAbstractFrame _Py_UOpsAbstractFrame;
|
|||
#define sym_set_non_null _Py_uop_sym_set_non_null
|
||||
#define sym_set_type _Py_uop_sym_set_type
|
||||
#define sym_set_const _Py_uop_sym_set_const
|
||||
#define sym_is_bottom _Py_uop_sym_is_bottom
|
||||
#define frame_new _Py_uop_frame_new
|
||||
#define frame_pop _Py_uop_frame_pop
|
||||
|
||||
|
@ -107,7 +108,9 @@ dummy_func(void) {
|
|||
}
|
||||
|
||||
op(_BINARY_OP_ADD_INT, (left, right -- res)) {
|
||||
if (sym_is_const(left) && sym_is_const(right)) {
|
||||
if (sym_is_const(left) && sym_is_const(right) &&
|
||||
sym_matches_type(left, &PyLong_Type) && sym_matches_type(right, &PyLong_Type))
|
||||
{
|
||||
assert(PyLong_CheckExact(sym_get_const(left)));
|
||||
assert(PyLong_CheckExact(sym_get_const(right)));
|
||||
PyObject *temp = _PyLong_Add((PyLongObject *)sym_get_const(left),
|
||||
|
@ -115,7 +118,9 @@ dummy_func(void) {
|
|||
if (temp == NULL) {
|
||||
goto error;
|
||||
}
|
||||
OUT_OF_SPACE_IF_NULL(res = sym_new_const(ctx, temp));
|
||||
res = sym_new_const(ctx, temp);
|
||||
Py_DECREF(temp);
|
||||
OUT_OF_SPACE_IF_NULL(res);
|
||||
// TODO gh-115506:
|
||||
// replace opcode with constant propagated one and add tests!
|
||||
}
|
||||
|
@ -125,7 +130,9 @@ dummy_func(void) {
|
|||
}
|
||||
|
||||
op(_BINARY_OP_SUBTRACT_INT, (left, right -- res)) {
|
||||
if (sym_is_const(left) && sym_is_const(right)) {
|
||||
if (sym_is_const(left) && sym_is_const(right) &&
|
||||
sym_matches_type(left, &PyLong_Type) && sym_matches_type(right, &PyLong_Type))
|
||||
{
|
||||
assert(PyLong_CheckExact(sym_get_const(left)));
|
||||
assert(PyLong_CheckExact(sym_get_const(right)));
|
||||
PyObject *temp = _PyLong_Subtract((PyLongObject *)sym_get_const(left),
|
||||
|
@ -133,7 +140,9 @@ dummy_func(void) {
|
|||
if (temp == NULL) {
|
||||
goto error;
|
||||
}
|
||||
OUT_OF_SPACE_IF_NULL(res = sym_new_const(ctx, temp));
|
||||
res = sym_new_const(ctx, temp);
|
||||
Py_DECREF(temp);
|
||||
OUT_OF_SPACE_IF_NULL(res);
|
||||
// TODO gh-115506:
|
||||
// replace opcode with constant propagated one and add tests!
|
||||
}
|
||||
|
@ -143,7 +152,9 @@ dummy_func(void) {
|
|||
}
|
||||
|
||||
op(_BINARY_OP_MULTIPLY_INT, (left, right -- res)) {
|
||||
if (sym_is_const(left) && sym_is_const(right)) {
|
||||
if (sym_is_const(left) && sym_is_const(right) &&
|
||||
sym_matches_type(left, &PyLong_Type) && sym_matches_type(right, &PyLong_Type))
|
||||
{
|
||||
assert(PyLong_CheckExact(sym_get_const(left)));
|
||||
assert(PyLong_CheckExact(sym_get_const(right)));
|
||||
PyObject *temp = _PyLong_Multiply((PyLongObject *)sym_get_const(left),
|
||||
|
@ -151,7 +162,9 @@ dummy_func(void) {
|
|||
if (temp == NULL) {
|
||||
goto error;
|
||||
}
|
||||
OUT_OF_SPACE_IF_NULL(res = sym_new_const(ctx, temp));
|
||||
res = sym_new_const(ctx, temp);
|
||||
Py_DECREF(temp);
|
||||
OUT_OF_SPACE_IF_NULL(res);
|
||||
// TODO gh-115506:
|
||||
// replace opcode with constant propagated one and add tests!
|
||||
}
|
||||
|
@ -161,7 +174,9 @@ dummy_func(void) {
|
|||
}
|
||||
|
||||
op(_BINARY_OP_ADD_FLOAT, (left, right -- res)) {
|
||||
if (sym_is_const(left) && sym_is_const(right)) {
|
||||
if (sym_is_const(left) && sym_is_const(right) &&
|
||||
sym_matches_type(left, &PyFloat_Type) && sym_matches_type(right, &PyFloat_Type))
|
||||
{
|
||||
assert(PyFloat_CheckExact(sym_get_const(left)));
|
||||
assert(PyFloat_CheckExact(sym_get_const(right)));
|
||||
PyObject *temp = PyFloat_FromDouble(
|
||||
|
@ -171,6 +186,8 @@ dummy_func(void) {
|
|||
goto error;
|
||||
}
|
||||
res = sym_new_const(ctx, temp);
|
||||
Py_DECREF(temp);
|
||||
OUT_OF_SPACE_IF_NULL(res);
|
||||
// TODO gh-115506:
|
||||
// replace opcode with constant propagated one and update tests!
|
||||
}
|
||||
|
@ -180,7 +197,9 @@ dummy_func(void) {
|
|||
}
|
||||
|
||||
op(_BINARY_OP_SUBTRACT_FLOAT, (left, right -- res)) {
|
||||
if (sym_is_const(left) && sym_is_const(right)) {
|
||||
if (sym_is_const(left) && sym_is_const(right) &&
|
||||
sym_matches_type(left, &PyFloat_Type) && sym_matches_type(right, &PyFloat_Type))
|
||||
{
|
||||
assert(PyFloat_CheckExact(sym_get_const(left)));
|
||||
assert(PyFloat_CheckExact(sym_get_const(right)));
|
||||
PyObject *temp = PyFloat_FromDouble(
|
||||
|
@ -190,6 +209,8 @@ dummy_func(void) {
|
|||
goto error;
|
||||
}
|
||||
res = sym_new_const(ctx, temp);
|
||||
Py_DECREF(temp);
|
||||
OUT_OF_SPACE_IF_NULL(res);
|
||||
// TODO gh-115506:
|
||||
// replace opcode with constant propagated one and update tests!
|
||||
}
|
||||
|
@ -199,7 +220,9 @@ dummy_func(void) {
|
|||
}
|
||||
|
||||
op(_BINARY_OP_MULTIPLY_FLOAT, (left, right -- res)) {
|
||||
if (sym_is_const(left) && sym_is_const(right)) {
|
||||
if (sym_is_const(left) && sym_is_const(right) &&
|
||||
sym_matches_type(left, &PyFloat_Type) && sym_matches_type(right, &PyFloat_Type))
|
||||
{
|
||||
assert(PyFloat_CheckExact(sym_get_const(left)));
|
||||
assert(PyFloat_CheckExact(sym_get_const(right)));
|
||||
PyObject *temp = PyFloat_FromDouble(
|
||||
|
@ -209,6 +232,8 @@ dummy_func(void) {
|
|||
goto error;
|
||||
}
|
||||
res = sym_new_const(ctx, temp);
|
||||
Py_DECREF(temp);
|
||||
OUT_OF_SPACE_IF_NULL(res);
|
||||
// TODO gh-115506:
|
||||
// replace opcode with constant propagated one and update tests!
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue