Skip to content

Commit

Permalink
Address code review
Browse files Browse the repository at this point in the history
  • Loading branch information
corona10 committed Nov 21, 2024
1 parent c08f8b7 commit 6bc4c90
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions Python/specialize.c
Original file line number Diff line number Diff line change
Expand Up @@ -2665,6 +2665,7 @@ _Py_Specialize_Send(_PyStackRef receiver_st, _Py_CODEUNIT *instr)
cache->counter = adaptive_counter_cooldown();
}

#ifdef Py_STATS
static int
to_bool_fail_kind(PyObject *value)
{
Expand All @@ -2691,6 +2692,7 @@ to_bool_fail_kind(PyObject *value)
}
return SPEC_FAIL_OTHER;
}
#endif // Py_STATS

static int
check_type_always_true(PyTypeObject *ty)
Expand All @@ -2710,15 +2712,13 @@ check_type_always_true(PyTypeObject *ty)
return 0;
}


void
_Py_Specialize_ToBool(_PyStackRef value_o, _Py_CODEUNIT *instr)
{
assert(ENABLE_SPECIALIZATION_FT);
assert(_PyOpcode_Caches[TO_BOOL] == INLINE_CACHE_ENTRIES_TO_BOOL);
_PyToBoolCache *cache = (_PyToBoolCache *)(instr + 1);
PyObject *value = PyStackRef_AsPyObjectBorrow(value_o);
int reason;
uint8_t specialized_op;
if (PyBool_Check(value)) {
specialized_op = TO_BOOL_BOOL;
Expand All @@ -2744,11 +2744,11 @@ _Py_Specialize_ToBool(_PyStackRef value_o, _Py_CODEUNIT *instr)
unsigned int version = 0;
int err = _PyType_Validate(Py_TYPE(value), check_type_always_true, &version);
if (err < 0) {
reason = SPEC_FAIL_OUT_OF_VERSIONS;
SPECIALIZATION_FAIL(instr, SPEC_FAIL_OUT_OF_VERSIONS);
goto failure;
}
else if (err > 0) {
reason = err;
SPECIALIZATION_FAIL(instr, err);
goto failure;
}

Expand All @@ -2758,9 +2758,10 @@ _Py_Specialize_ToBool(_PyStackRef value_o, _Py_CODEUNIT *instr)
specialized_op = TO_BOOL_ALWAYS_TRUE;
goto success;
}
reason = to_bool_fail_kind(value);

SPECIALIZATION_FAIL(instr, to_bool_fail_kind(value));
failure:
unspecialize(instr, reason);
unspecialize(instr);
return;
success:
specialize(instr, specialized_op);
Expand Down

0 comments on commit 6bc4c90

Please sign in to comment.