Skip to content

Lattice

BoundedLattice

Bases: Lattice[BoundedLatticeType]


              flowchart TD
              kirin.lattice.abc.BoundedLattice[BoundedLattice]
              kirin.lattice.abc.Lattice[Lattice]

                              kirin.lattice.abc.Lattice --> kirin.lattice.abc.BoundedLattice
                


              click kirin.lattice.abc.BoundedLattice href "" "kirin.lattice.abc.BoundedLattice"
              click kirin.lattice.abc.Lattice href "" "kirin.lattice.abc.Lattice"
            

ABC for bounded lattices as Python class.

BoundedLattice is an abstract class that can be inherited from. It requires the implementation of the bottom and top methods.

Lattice

Bases: ABC, Generic[LatticeType]


              flowchart TD
              kirin.lattice.abc.Lattice[Lattice]

              

              click kirin.lattice.abc.Lattice href "" "kirin.lattice.abc.Lattice"
            

ABC for lattices as Python class.

While Lattice is only an interface, LatticeABC is an abstract class that can be inherited from. This provides a few default implementations for the lattice operations.

is_structurally_equal

is_structurally_equal(
    other: LatticeType, context: dict | None = None
) -> bool

Check if two lattices are equal.

Source code in src/kirin/lattice/abc.py
52
53
54
55
56
57
58
59
def is_structurally_equal(
    self, other: LatticeType, context: dict | None = None
) -> bool:
    """Check if two lattices are equal."""
    if self is other:
        return True
    else:
        return self.is_subseteq(other) and other.is_subseteq(self)

is_subseteq abstractmethod

is_subseteq(other: LatticeType) -> bool

Subseteq operation.

Source code in src/kirin/lattice/abc.py
47
48
49
50
@abstractmethod
def is_subseteq(self, other: LatticeType) -> bool:
    """Subseteq operation."""
    ...

join abstractmethod

join(other: LatticeType) -> LatticeType

Join operation.

Source code in src/kirin/lattice/abc.py
37
38
39
40
@abstractmethod
def join(self, other: LatticeType) -> LatticeType:
    """Join operation."""
    ...

meet abstractmethod

meet(other: LatticeType) -> LatticeType

Meet operation.

Source code in src/kirin/lattice/abc.py
42
43
44
45
@abstractmethod
def meet(self, other: LatticeType) -> LatticeType:
    """Meet operation."""
    ...

SingletonMeta

SingletonMeta(name, bases, attrs)

Bases: LatticeMeta


              flowchart TD
              kirin.lattice.abc.SingletonMeta[SingletonMeta]
              kirin.lattice.abc.LatticeMeta[LatticeMeta]

                              kirin.lattice.abc.LatticeMeta --> kirin.lattice.abc.SingletonMeta
                


              click kirin.lattice.abc.SingletonMeta href "" "kirin.lattice.abc.SingletonMeta"
              click kirin.lattice.abc.LatticeMeta href "" "kirin.lattice.abc.LatticeMeta"
            

Singleton metaclass for lattices. It ensures that only one instance of a lattice is created.

See https://stackoverflow.com/questions/674304/why-is-init-always-called-after-new/8665179#8665179

Source code in src/kirin/lattice/abc.py
16
17
18
def __init__(cls, name, bases, attrs):
    super().__init__(name, bases, attrs)
    cls._instance = None

UnionMeta

UnionMeta(name, bases, attrs)

Bases: LatticeMeta


              flowchart TD
              kirin.lattice.abc.UnionMeta[UnionMeta]
              kirin.lattice.abc.LatticeMeta[LatticeMeta]

                              kirin.lattice.abc.LatticeMeta --> kirin.lattice.abc.UnionMeta
                


              click kirin.lattice.abc.UnionMeta href "" "kirin.lattice.abc.UnionMeta"
              click kirin.lattice.abc.LatticeMeta href "" "kirin.lattice.abc.LatticeMeta"
            

Meta class for union types. It simplifies the union if possible.

Source code in src/kirin/lattice/abc.py
95
96
97
98
99
def __init__(self, name, bases, attrs):
    super().__init__(name, bases, attrs)
    if not issubclass(base := bases[0], BoundedLattice):
        raise TypeError(f"Union must inherit from Lattice, got {bases[0]}")
    self._bottom = base.bottom()