gh-134584: Eliminate redundant refcounting from TO_BOOL_STR (GH-143417)

Signed-off-by: Manjusaka <me@manjusaka.me>
This commit is contained in:
Nadeshiko Manju 2026-01-07 05:11:53 +08:00 committed by GitHub
parent 98e55d70bc
commit 0a5c04a5ce
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 138 additions and 82 deletions

View file

@ -44,7 +44,8 @@ optimize_to_bool(
_PyUOpInstruction *this_instr,
JitOptContext *ctx,
JitOptSymbol *value,
JitOptSymbol **result_ptr);
JitOptSymbol **result_ptr,
bool insert_mode);
extern void
eliminate_pop_guard(_PyUOpInstruction *this_instr, bool exit);
@ -377,21 +378,21 @@ dummy_func(void) {
}
op(_TO_BOOL, (value -- res)) {
int already_bool = optimize_to_bool(this_instr, ctx, value, &res);
int already_bool = optimize_to_bool(this_instr, ctx, value, &res, false);
if (!already_bool) {
res = sym_new_truthiness(ctx, value, true);
}
}
op(_TO_BOOL_BOOL, (value -- value)) {
int already_bool = optimize_to_bool(this_instr, ctx, value, &value);
int already_bool = optimize_to_bool(this_instr, ctx, value, &value, false);
if (!already_bool) {
sym_set_type(value, &PyBool_Type);
}
}
op(_TO_BOOL_INT, (value -- res)) {
int already_bool = optimize_to_bool(this_instr, ctx, value, &res);
int already_bool = optimize_to_bool(this_instr, ctx, value, &res, false);
if (!already_bool) {
sym_set_type(value, &PyLong_Type);
res = sym_new_truthiness(ctx, value, true);
@ -399,14 +400,14 @@ dummy_func(void) {
}
op(_TO_BOOL_LIST, (value -- res)) {
int already_bool = optimize_to_bool(this_instr, ctx, value, &res);
int already_bool = optimize_to_bool(this_instr, ctx, value, &res, false);
if (!already_bool) {
res = sym_new_type(ctx, &PyBool_Type);
}
}
op(_TO_BOOL_NONE, (value -- res)) {
int already_bool = optimize_to_bool(this_instr, ctx, value, &res);
int already_bool = optimize_to_bool(this_instr, ctx, value, &res, false);
if (!already_bool) {
sym_set_const(value, Py_None);
res = sym_new_const(ctx, Py_False);
@ -431,8 +432,9 @@ dummy_func(void) {
sym_set_type(value, &PyUnicode_Type);
}
op(_TO_BOOL_STR, (value -- res)) {
int already_bool = optimize_to_bool(this_instr, ctx, value, &res);
op(_TO_BOOL_STR, (value -- res, v)) {
int already_bool = optimize_to_bool(this_instr, ctx, value, &res, true);
v = value;
if (!already_bool) {
res = sym_new_truthiness(ctx, value, true);
}