Skip to content

Commit 0c97fd1

Browse files
committed
Make Literal compare as == intead of just id (#499)
As per discussion, we are making this Literal comparison `is_equal` to be == instead of just compare id, since it contain runtime. Another issue will be created to refactor this to make it more performant
1 parent fe49c4d commit 0c97fd1

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/kirin/ir/attrs/types.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ class Literal(TypeAttribute, typing.Generic[LiteralType], metaclass=LiteralMeta)
222222
name = "Literal"
223223
data: LiteralType
224224
type: TypeAttribute
225+
225226
"""type of the literal, this is useful when the Python type of
226227
data does not represent the type in IR, e.g Literal(1, types.Int32)
227228
"""
@@ -231,7 +232,11 @@ def __init__(self, data: LiteralType, datatype: TypeAttribute | None = None):
231232
self.type = datatype or PyClass(type(data))
232233

233234
def is_equal(self, other: TypeAttribute) -> bool:
234-
return self is other
235+
return (
236+
isinstance(other, Literal)
237+
and self.type.is_equal(other.type)
238+
and self.data == other.data
239+
)
235240

236241
def is_subseteq_TypeVar(self, other: "TypeVar") -> bool:
237242
return self.is_subseteq(other.bound)

0 commit comments

Comments
 (0)