11from __future__ import annotations
22
3- from dataclasses import dataclass
3+ import sys
4+ from dataclasses import field , dataclass
45
56from kirin import ir
67from kirin .rewrite .abc import RewriteRule , RewriteResult
78
9+ _IS_PYTHON_310 = sys .version_info [0 ] == 3 and sys .version_info [1 ] == 10
10+
811
912@dataclass
1013class Info :
@@ -15,22 +18,31 @@ class Info:
1518 attributes : tuple [ir .Attribute , ...]
1619 successors : tuple [ir .Block , ...]
1720 regions : tuple [ir .Region , ...]
21+ _hash : int = field (init = False , repr = False )
22+ _hashable : bool = field (init = False , repr = False )
23+
24+ def __post_init__ (self ):
25+ if _IS_PYTHON_310 and any (isinstance (attr , slice ) for attr in self .attributes ):
26+ self ._hash = id (self )
27+ self ._hashable = False
28+ else :
29+ self ._hash = hash (
30+ (id (self .head ),)
31+ + tuple (id (ssa ) for ssa in self .args )
32+ + tuple (hash (attr ) for attr in self .attributes )
33+ + tuple (id (succ ) for succ in self .successors )
34+ + tuple (id (region ) for region in self .regions )
35+ )
36+ self ._hashable = True
1837
1938 def __hash__ (self ) -> int :
20- return hash (
21- (id (self .head ),)
22- + tuple (id (ssa ) for ssa in self .args )
23- + tuple (hash (attr ) for attr in self .attributes )
24- + tuple (id (succ ) for succ in self .successors )
25- + tuple (id (region ) for region in self .regions )
26- )
39+ return self ._hash
2740
2841 def __eq__ (self , other : object ) -> bool :
29- if not isinstance (other , Info ):
30- return False
31-
32- return (
33- self .head == other .head
42+ return self is other or (
43+ self ._hashable
44+ and isinstance (other , Info )
45+ and self .head == other .head
3446 and self .args == other .args
3547 and self .attributes == other .attributes
3648 and self .successors == other .successors
0 commit comments