GH-130415: Narrow str to "" based on boolean tests (GH-130476)

This commit is contained in:
Amit Lavon 2025-03-04 13:20:17 -08:00 committed by GitHub
parent b6769e9404
commit 691354ccb0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 40 additions and 2 deletions

View file

@ -426,7 +426,7 @@ dummy_func(void) {
op(_TO_BOOL_STR, (value -- res)) {
if (!optimize_to_bool(this_instr, ctx, value, &res)) {
res = sym_new_type(ctx, &PyBool_Type);
res = sym_new_truthiness(ctx, value, true);
sym_set_type(value, &PyUnicode_Type);
}
}

View file

@ -213,7 +213,7 @@
JitOptSymbol *res;
value = stack_pointer[-1];
if (!optimize_to_bool(this_instr, ctx, value, &res)) {
res = sym_new_type(ctx, &PyBool_Type);
res = sym_new_truthiness(ctx, value, true);
sym_set_type(value, &PyUnicode_Type);
}
stack_pointer[-1] = res;

View file

@ -302,6 +302,9 @@ _Py_uop_sym_set_const(JitOptContext *ctx, JitOptSymbol *sym, PyObject *const_val
else if (type == &PyLong_Type) {
_Py_uop_sym_set_const(ctx, value, Py_GetConstant(Py_CONSTANT_ZERO));
}
else if (type == &PyUnicode_Type) {
_Py_uop_sym_set_const(ctx, value, Py_GetConstant(Py_CONSTANT_EMPTY_STR));
}
// TODO: More types (GH-130415)!
make_const(sym, const_val);
return;