Skip to content

Commit ac41f19

Browse files
committed
debug block eq check
1 parent 0b0e58e commit ac41f19

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/kirin/analysis/const/lattice.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,12 @@ class Predecessor(Result):
275275

276276
def __hash__(self) -> int:
277277
return id(self)
278+
279+
def __eq__(self, other: object) -> bool:
280+
if isinstance(other, Predecessor):
281+
return self.block.is_structurally_equal(other.block) and self.value == other.value
282+
else:
283+
return False
278284

279285
def is_subseteq(self, other: Result) -> bool:
280286
if isinstance(other, Predecessor):
@@ -313,6 +319,17 @@ def meet(self, other: Result) -> Result:
313319
class Union(Result):
314320

315321
predecessors: frozenset[Predecessor]
322+
323+
def __hash__(self) -> int:
324+
return id(self)
325+
326+
def is_subseteq(self, other: Result) -> bool:
327+
if isinstance(other, Union):
328+
return self.predecessors.issubset(other.predecessors)
329+
elif isinstance(other, Predecessor):
330+
return all(pred.is_subseteq(other) for pred in self.predecessors)
331+
else:
332+
return super().is_subseteq(other)
316333

317334
def join(self, other: Result) -> Result:
318335
if isinstance(other, Union):
@@ -321,6 +338,8 @@ def join(self, other: Result) -> Result:
321338
elif isinstance(other, Predecessor):
322339
union_preds = self.predecessors.union({other})
323340
return Union(predecessors=union_preds)
341+
else:
342+
return Unknown()
324343

325344
def meet(self, other: Result) -> Result:
326345
if isinstance(other, Union):
@@ -329,4 +348,6 @@ def meet(self, other: Result) -> Result:
329348
elif isinstance(other, Predecessor):
330349
common_preds = self.predecessors.intersection({other})
331350
return Union(predecessors=common_preds)
351+
else:
352+
return self.bottom()
332353

test/analysis/dataflow/constprop/test_worklist.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,5 @@ def test(x: str, y: float, flag: bool):
3030
# test.print()
3131
prop = const.Propagate(basic_no_opt)
3232
frame, ret = prop.run(test)
33+
frame.code.print(analysis=frame.entries)
3334
assert isinstance(ret, const.PartialLambda)

0 commit comments

Comments
 (0)