Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[mypyc] Fast tuple equality checks #9343

Merged
merged 12 commits into from
Aug 27, 2020
Prev Previous commit
Next Next commit
add cast to bool if necessary
  • Loading branch information
TH3CHARLie committed Aug 24, 2020
commit 7ce18965085d34cdcfd8234e082b88e291e6d91b
10 changes: 7 additions & 3 deletions mypyc/irbuild/ll_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
bool_rprimitive, list_rprimitive, str_rprimitive, is_none_rprimitive, object_rprimitive,
c_pyssize_t_rprimitive, is_short_int_rprimitive, is_tagged, PyVarObject, short_int_rprimitive,
is_list_rprimitive, is_tuple_rprimitive, is_dict_rprimitive, is_set_rprimitive, PySetObject,
none_rprimitive, RTuple
none_rprimitive, RTuple, is_bool_rprimitive
)
from mypyc.ir.func_ir import FuncDecl, FuncSignature
from mypyc.ir.class_ir import ClassIR, all_concrete_classes
Expand Down Expand Up @@ -656,10 +656,14 @@ def compare_tuples(self,
lhs_item = lhs_items[i]
rhs_item = rhs_items[i]
compare = self.binary_op(lhs_item, rhs_item, op, line)
# 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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo ("comapre")

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! But I've already addressed that in e34c025. The problem now is the Tuple[T, ...] nested within a regular Tuple

if i < len(lhs.type.types) - 1:
branch = Branch(compare, false_assign, check_blocks[i + 1], Branch.BOOL_EXPR)
branch = Branch(comapre, false_assign, check_blocks[i + 1], Branch.BOOL_EXPR)
else:
branch = Branch(compare, false_assign, true_assign, Branch.BOOL_EXPR)
branch = Branch(comapre, false_assign, true_assign, Branch.BOOL_EXPR)
# branch on false
branch.negated = True
self.add(branch)
Expand Down