Skip to content

Abc

Attribute dataclass

Attribute()

Bases: ABC, Printable

ABC for compile-time values. All attributes are hashable and thus need to implement the __hash__ method.

Pretty Printing

This object is pretty printable via .print() method.

dialect class-attribute

dialect: Optional[Dialect] = field(
    default=None, init=False, repr=False
)

Dialect of the attribute. (default: None)

name class-attribute

name: str = field(init=False, repr=False)

Name of the attribute in printing and other text format.

traits class-attribute

traits: frozenset[Trait[Attribute]] = field(
    default=frozenset(), init=False, repr=False
)

Set of Attribute traits.

get_trait

get_trait(trait: type[TraitType]) -> Optional[TraitType]

Get the trait of the attribute.

Parameters:

Name Type Description Default
trait type[Trait]

the trait to get

required

Returns:

Type Description
Optional[TraitType]

Optional[Trait]: the trait if found, None otherwise

Source code in src/kirin/ir/attrs/abc.py
70
71
72
73
74
75
76
77
78
79
80
81
82
83
def get_trait(self, trait: type[TraitType]) -> Optional[TraitType]:
    """Get the trait of the attribute.

    Args:
        trait (type[Trait]): the trait to get

    Returns:
        Optional[Trait]: the trait if found, None otherwise
    """
    for t in self.traits:
        if isinstance(t, trait):
            return t

    return None

has_trait classmethod

has_trait(trait_type: type[Trait[Attribute]]) -> bool

Check if the Statement has a specific trait.

Parameters:

Name Type Description Default
trait_type type[Trait]

The type of trait to check for.

required

Returns:

Name Type Description
bool bool

True if the class has the specified trait, False otherwise.

Source code in src/kirin/ir/attrs/abc.py
53
54
55
56
57
58
59
60
61
62
63
64
65
66
@classmethod
def has_trait(cls, trait_type: type[Trait["Attribute"]]) -> bool:
    """Check if the Statement has a specific trait.

    Args:
        trait_type (type[Trait]): The type of trait to check for.

    Returns:
        bool: True if the class has the specified trait, False otherwise.
    """
    for trait in cls.traits:
        if isinstance(trait, trait_type):
            return True
    return False

AttributeMeta

Bases: ABCMeta

Metaclass for attributes.

LatticeAttributeMeta

Bases: LatticeMeta, AttributeMeta

Metaclass for lattice attributes.

SingletonLatticeAttributeMeta

SingletonLatticeAttributeMeta(name, bases, attrs)

Bases: LatticeAttributeMeta, SingletonMeta

Metaclass for singleton lattice attributes.

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