| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
- Add TO_BOOL_GENERIC: a catch-all specialization for types not covered by existing TO_BOOL variants (dict, tuple, float, set, bytes, frozenset, etc. and heap types with __bool__/__len__). Records type info for the JIT. - Add _TO_BOOL_DICT: a tier2-only uop that checks dict.ma_used directly instead of calling PyObject_IsTrue(). The JIT optimizer replaces _TO_BOOL with _TO_BOOL_DICT when the type is known to be dict or frozendict. - Fix _GUARD_TYPE_VERSION optimizer handler to resolve types from recorded type info even when the type version cache has a collision. This enables the optimizer to eliminate redundant type guards (e.g. _GUARD_NOS_LIST) in more cases. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
| self.assert_specialized(to_bool_str, "TO_BOOL_STR") | ||
| self.assert_no_opcode(to_bool_str, "TO_BOOL") | ||
|
|
||
| def to_bool_generic_dict(): |
There was a problem hiding this comment.
There is quite some redundancy in the added tests (and also the existing tests). We could refactor this, but it is a bit tricky as re-using the same method (with different arguments) makes it more difficult to reason about the specialization that takes place.
If we want this, I suggest we open a separate PR.
Sorry, something went wrong.
| // already added one earlier. | ||
| if (sym_set_type_version(owner, type_version)) { | ||
| // sym_set_type_version can resolve the type from recorded type info | ||
| // even when the version cache has a collision |
There was a problem hiding this comment.
This change has as side effect the list.append needs less checks.
Sorry, something went wrong.
|
I don't think we want TO_BOOL_GENERIC as it is basically duplicating TO_BOOL. The "generic" form is only useful if we also add a _PY form that inlines calls to __bool__() for classes where __bool__() is implemented in Python. What you can do is add the _RECORD_TOS_TYPE uop to TO_BOOL and use that to implement the _TO_BOOL_DICT optimization. You might also want to add _TO_BOOL_SIZED and apply it to any class where __bool__() is equivalent to Py_SIZE(obj) != 0. We could then specialize TO_BOOL for tuples, bytes, bytearrays and others, in the JIT. |
Sorry, something went wrong.
|
@markshannon It seems I misinterpreted the comments at the issue. I though the TO_BOOL_GENERIC/TO_BOOL_PY pair would cover most (all types) and allow tier2 specialization. I am having some trouble adding the _RECORD_TOS_TYPE to TO_BOOL as that has _SPECIALIZE_TO_BOOL and I cannot combine the two. I created a separate PR with just the tier2 opcodes. (they work in the jit, but could benefit from more type information from either a _RECORD_TOS_TYPE or tier1 opcodes). |
Sorry, something went wrong.
Sorry, something went wrong.
|
The issue with _SPECIALIZE_TO_BOOL preventing recording has been fixed, if you want to pick this up again |
Sorry, something went wrong.
|
@markshannon I am closing this in favor of #148271. That PR only currently adds the tier2 opcodes (not yet the recording uop). I will add the recording uop on top of the PR or a followup PR depending how hard it is. |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
We add TO_BOOL_GENERIC as suggested in #143732 (comment). This adds type information for several builtin classes. We also add _TO_BOOL_DICT (tier 2). In the jit conversion of a dict to bool is about 30% faster.