Skip to content

Commit de93800

Browse files
committed
Add optimization path to _TO_BOOL_STR
1 parent 8ba80b8 commit de93800

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

Python/optimizer_bytecodes.c

+13
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,19 @@ dummy_func(void) {
428428
res = sym_new_type(ctx, &PyBool_Type);
429429
sym_set_type(value, &PyUnicode_Type);
430430
}
431+
if (!sym_is_const(value)) {
432+
assert(sym_matches_type(value, &PyUnicode_Type));
433+
int next_opcode = (this_instr + 1)->opcode;
434+
assert(next_opcode == _CHECK_VALIDITY_AND_SET_IP);
435+
next_opcode = (this_instr + 2)->opcode;
436+
// If the next uop is a guard, we can narrow value. However, we
437+
// *can't* narrow res, since that would cause the guard to be
438+
// removed and the narrowed value to be invalid:
439+
if (next_opcode == _GUARD_IS_FALSE_POP) {
440+
sym_set_const(value, Py_GetConstant(Py_CONSTANT_EMPTY_STR));
441+
res = sym_new_type(ctx, &PyUnicode_Type);
442+
}
443+
}
431444
}
432445

433446
op(_COMPARE_OP, (left, right -- res)) {

Python/optimizer_cases.c.h

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

0 commit comments

Comments
 (0)