[mypyc] Fast tuple equality checks - #9343
Conversation
|
The tests failures are due to the runtime error described in the issue. |
|
some performance numbers(running on my mac locally, very imprecise) On master with this PR: |
| # Cast to bool if necessary since most types uses comparison returning a object type | ||
| # See generic_ops.py for more information | ||
| if not is_bool_rprimitive(compare.type): | ||
| comapre = self.coerce(compare, bool_rprimitive, line) |
There was a problem hiding this comment.
Thanks! But I've already addressed that in e34c025. The problem now is the Tuple[T, ...] nested within a regular Tuple
|
@JukkaL I think it's ready for review now. |
msullivan
left a comment
There was a problem hiding this comment.
Looks good, but I have on question
| equal = True if op == '==' else False | ||
| result = self.alloc_temp(bool_rprimitive) | ||
| # empty tuples | ||
| if (equal and len(lhs.type.types) == 0 and len(rhs.type.types) == 0): |
There was a problem hiding this comment.
Why a special case for just equality?
|
No need for this to be in this PR, but it would be pretty straightforward to do |
Sure, only need to do some minor modifications. But they appear much less frequently than these two ops, so probably it's OK to lower their priority IMO. |
| # Cast to bool if necessary since most types uses comparison returning a object type | ||
| # See generic_ops.py for more information | ||
| if not is_bool_rprimitive(compare.type): | ||
| compare = self.coerce(compare, bool_rprimitive, line) |
There was a problem hiding this comment.
Coerce only does a type check. I think that the normal CPython semantics would be to allow arbitrary objects that have a truth value, i.e. it may be better to use bool_op instead. Consider what happens if a user-defined class defines __eq__ that returns a non-bool value such as 1 or 'x'.
closes mypyc/mypyc#728