Skip to content

Commit 601392d

Browse files
committed
Assign truthiness to empty strings in JIT
1 parent d5bfcdc commit 601392d

File tree

3 files changed

+5
-29
lines changed

3 files changed

+5
-29
lines changed

Python/optimizer_bytecodes.c

+1-14
Original file line numberDiff line numberDiff line change
@@ -426,22 +426,9 @@ dummy_func(void) {
426426

427427
op(_TO_BOOL_STR, (value -- res)) {
428428
if (!optimize_to_bool(this_instr, ctx, value, &res)) {
429-
res = sym_new_type(ctx, &PyBool_Type);
429+
res = sym_new_truthiness(ctx, value, true);
430430
sym_set_type(value, &PyUnicode_Type);
431431
}
432-
if (!sym_is_const(value)) {
433-
assert(sym_matches_type(value, &PyUnicode_Type));
434-
int next_opcode = (this_instr + 1)->opcode;
435-
assert(next_opcode == _CHECK_VALIDITY_AND_SET_IP);
436-
next_opcode = (this_instr + 2)->opcode;
437-
// If the next uop is a guard, we can narrow value. However, we
438-
// *can't* narrow res, since that would cause the guard to be
439-
// removed and the narrowed value to be invalid:
440-
if (next_opcode == _GUARD_IS_FALSE_POP) {
441-
sym_set_const(value, Py_GetConstant(Py_CONSTANT_EMPTY_STR));
442-
res = sym_new_type(ctx, &PyBool_Type);
443-
}
444-
}
445432
}
446433

447434
op(_UNARY_NOT, (value -- res)) {

Python/optimizer_cases.c.h

+1-15
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/optimizer_symbols.c

+3
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,9 @@ _Py_uop_sym_set_const(JitOptContext *ctx, JitOptSymbol *sym, PyObject *const_val
299299
else if (type == &PyBool_Type) {
300300
_Py_uop_sym_set_const(ctx, value, Py_False);
301301
}
302+
else if (type == &PyUnicode_Type) {
303+
_Py_uop_sym_set_const(ctx, value, Py_GetConstant(Py_CONSTANT_EMPTY_STR));
304+
}
302305
// TODO: More types (GH-130415)!
303306
make_const(sym, const_val);
304307
return;

0 commit comments

Comments
 (0)