Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions src/kirin/dialects/ilist/rewrite/flatten_add.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,16 @@ class FlattenAdd(RewriteRule):
def rewrite_Statement(self, node: ir.Statement) -> RewriteResult:
if not (
isinstance(node, py.binop.Add)
and node.lhs.type.is_subseteq(ilist.IListType)
and node.rhs.type.is_subseteq(ilist.IListType)
and (lhs_type := node.lhs.type).is_subseteq(ilist.IListType)
and (rhs_type := node.rhs.type).is_subseteq(ilist.IListType)
and not lhs_type.is_structurally_equal(types.Bottom)
and not rhs_type.is_structurally_equal(types.Bottom)
):
return RewriteResult()

assert isinstance(rhs_type, types.Generic), "Expecting generic type for IList"
assert isinstance(lhs_type, types.Generic), "Expecting generic type for IList"

# check if we are adding two ilist.New objects
new_data = ()

Expand Down Expand Up @@ -46,9 +51,6 @@ def rewrite_Statement(self, node: ir.Statement) -> RewriteResult:
):
return RewriteResult()

assert isinstance(rhs_type := rhs.type, types.Generic), "Impossible"
assert isinstance(lhs_type := lhs.type, types.Generic), "Impossible"

lhs_elem_type = lhs_type.vars[0]
rhs_elem_type = rhs_type.vars[0]

Expand Down