Skip to content

Commit d89b4f3

Browse files
authored
fix dataclass eq in types (#203)
thank you dataclass :-) cc: @weinbe58 @johnzl-777
1 parent ce2e38a commit d89b4f3

File tree

2 files changed

+40
-9
lines changed

2 files changed

+40
-9
lines changed

src/kirin/ir/attrs/types.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def __hash__(self) -> int: ...
8686

8787

8888
@typing.final
89-
@dataclass
89+
@dataclass(eq=False)
9090
class AnyType(TypeAttribute, metaclass=SingletonTypeMeta):
9191
name = "Any"
9292

@@ -98,7 +98,7 @@ def __hash__(self) -> int:
9898

9999

100100
@typing.final
101-
@dataclass
101+
@dataclass(eq=False)
102102
class BottomType(TypeAttribute, metaclass=SingletonTypeMeta):
103103
name = "Bottom"
104104

@@ -140,7 +140,7 @@ def __call__(self, typ):
140140

141141

142142
@typing.final
143-
@dataclass
143+
@dataclass(eq=False)
144144
class PyClass(TypeAttribute, typing.Generic[PyClassType], metaclass=PyClassMeta):
145145
name = "PyClass"
146146
typ: type[PyClassType]
@@ -197,7 +197,7 @@ def __call__(self, data):
197197

198198

199199
@typing.final
200-
@dataclass
200+
@dataclass(eq=False)
201201
class Literal(TypeAttribute, typing.Generic[LiteralType], metaclass=LiteralMeta):
202202
name = "Literal"
203203
data: LiteralType
@@ -222,7 +222,7 @@ def print_impl(self, printer: Printer) -> None:
222222

223223

224224
@typing.final
225-
@dataclass
225+
@dataclass(eq=False)
226226
class Union(TypeAttribute, metaclass=UnionTypeMeta):
227227
name = "Union"
228228
types: frozenset[TypeAttribute]
@@ -283,7 +283,7 @@ def print_impl(self, printer: Printer) -> None:
283283

284284

285285
@typing.final
286-
@dataclass
286+
@dataclass(eq=False)
287287
class TypeVar(TypeAttribute):
288288
name = "TypeVar"
289289
varname: str
@@ -320,7 +320,7 @@ def print_impl(self, printer: Printer) -> None:
320320

321321

322322
@typing.final
323-
@dataclass
323+
@dataclass(eq=False)
324324
class Vararg(Attribute):
325325
name = "Vararg"
326326
typ: TypeAttribute
@@ -338,7 +338,7 @@ def print_impl(self, printer: Printer) -> None:
338338

339339

340340
@typing.final
341-
@dataclass
341+
@dataclass(eq=False)
342342
class Generic(TypeAttribute, typing.Generic[PyClassType]):
343343
name = "Generic"
344344
body: PyClass[PyClassType]
@@ -461,7 +461,7 @@ def where(self, typ: TypeVarValue | tuple[TypeVarValue, ...]) -> "Generic":
461461

462462

463463
@typing.final
464-
@dataclass
464+
@dataclass(eq=False)
465465
class Hinted(TypeAttribute, typing.Generic[HintedData]):
466466
"""Type wrapped with a hint.
467467

test/ir/test_isequal.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
from kirin import ir
2+
from kirin.analysis import const
3+
from kirin.dialects import func
4+
5+
6+
def test_is_equal_ignoring_hint():
7+
block = ir.Block()
8+
block.args.append_from(
9+
ir.types.Hinted(ir.types.PyClass(ir.Method), const.Value(None)), "self"
10+
)
11+
source_func = func.Function(
12+
sym_name="main",
13+
signature=func.Signature(
14+
inputs=(),
15+
output=ir.types.NoneType,
16+
),
17+
body=ir.Region(block),
18+
)
19+
20+
block = ir.Block()
21+
block.args.append_from(ir.types.PyClass(ir.Method), "self")
22+
expected_func = func.Function(
23+
sym_name="main",
24+
signature=func.Signature(
25+
inputs=(),
26+
output=ir.types.NoneType,
27+
),
28+
body=ir.Region(block),
29+
)
30+
31+
assert expected_func.is_equal(source_func)

0 commit comments

Comments
 (0)