Skip to content

Commit fcf4116

Browse files
committed
Add optimization path to _TO_BOOL_STR
1 parent 23695d6 commit fcf4116

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

Python/optimizer_bytecodes.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,19 @@ dummy_func(void) {
429429
res = sym_new_type(ctx, &PyBool_Type);
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, &PyUnicode_Type);
443+
}
444+
}
432445
}
433446

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

Python/optimizer_cases.c.h

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)