Skip to content

Types

AnyType dataclass

AnyType()

Bases: TypeAttribute

name class-attribute instance-attribute

name = 'Any'

Name of the attribute in printing and other text format.

BottomType dataclass

BottomType()

Bases: TypeAttribute

name class-attribute instance-attribute

name = 'Bottom'

Name of the attribute in printing and other text format.

is_subseteq

is_subseteq(other: TypeAttribute) -> bool

Subseteq operation.

Source code in src/kirin/ir/attrs/types.py
136
137
138
139
def is_subseteq(self, other: TypeAttribute) -> bool:
    if isinstance(other, TypeVar):
        return self.is_subseteq(other.bound)
    return True

FunctionType dataclass

FunctionType(
    params_type: tuple[TypeAttribute, ...],
    return_type: TypeAttribute | None = None,
)

Bases: TypeAttribute

Source code in src/kirin/ir/attrs/types.py
771
772
773
774
775
776
777
def __init__(
    self,
    params_type: tuple[TypeAttribute, ...],
    return_type: TypeAttribute | None = None,
):
    self.params_type = params_type
    self.return_type = return_type

name class-attribute instance-attribute

name = 'MethodType'

Name of the attribute in printing and other text format.

Generic dataclass

Generic(
    body: type[PyClassType] | PyClass[PyClassType],
    *vars: TypeAttribute | list | Vararg
)

Bases: TypeAttribute, Generic[PyClassType]

Source code in src/kirin/ir/attrs/types.py
562
563
564
565
566
567
568
569
570
571
def __init__(
    self,
    body: type[PyClassType] | PyClass[PyClassType],
    *vars: TypeAttribute | list | Vararg,
):
    if isinstance(body, PyClass):
        self.body = body
    else:
        self.body = PyClass(body)
    self.vars, self.vararg = _split_type_args(vars)

name class-attribute instance-attribute

name = 'Generic'

Name of the attribute in printing and other text format.

Literal dataclass

Literal(
    data: LiteralType, datatype: TypeAttribute | None = None
)

Bases: TypeAttribute, Generic[LiteralType]

Source code in src/kirin/ir/attrs/types.py
310
311
312
def __init__(self, data: LiteralType, datatype: TypeAttribute | None = None):
    self.data = data
    self.type = datatype or PyClass(type(data))

name class-attribute instance-attribute

name = 'Literal'

Name of the attribute in printing and other text format.

type instance-attribute

type: TypeAttribute = datatype or PyClass(type(data))

type of the literal, this is useful when the Python type of data does not represent the type in IR, e.g Literal(1, types.Int32)

PyClass dataclass

PyClass(
    typ: type[PyClassType],
    *,
    display_name: str | None = None,
    prefix: str = "py"
)

Bases: TypeAttribute, Generic[PyClassType]

Source code in src/kirin/ir/attrs/types.py
211
212
213
214
215
216
217
218
219
220
def __init__(
    self,
    typ: type[PyClassType],
    *,
    display_name: str | None = None,
    prefix: str = "py",
) -> None:
    self.typ = typ
    self.display_name = display_name if display_name is not None else typ.__name__
    self.prefix = prefix

name class-attribute instance-attribute

name = 'PyClass'

Name of the attribute in printing and other text format.

SingletonTypeMeta

SingletonTypeMeta(name, bases, attrs)

Bases: TypeAttributeMeta, SingletonMeta

Metaclass for singleton type attributes.

Singleton type attributes are attributes that have only one instance.

Examples: - AnyType - BottomType

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

TypeAttribute dataclass

TypeAttribute()

Bases: _TypeAttribute, SimpleMeetMixin['TypeAttribute'], IsSubsetEqMixin['TypeAttribute'], BoundedLattice['TypeAttribute']

join

join(other: TypeAttribute) -> TypeAttribute

Join operation.

Source code in src/kirin/ir/attrs/types.py
73
74
75
76
77
78
79
80
def join(self, other: "TypeAttribute") -> "TypeAttribute":
    if self.is_subseteq(other):
        return other
    elif other.is_subseteq(self):
        return self
    elif isinstance(other, TypeAttribute):
        return Union(self, other)
    return AnyType()  # don't know how to join

TypeAttributeMeta

Bases: LatticeAttributeMeta

Metaclass for type attributes.

TypeVar dataclass

TypeVar(name: str, bound: TypeAttribute | None = None)

Bases: TypeAttribute

Source code in src/kirin/ir/attrs/types.py
459
460
461
def __init__(self, name: str, bound: TypeAttribute | None = None):
    self.varname = name
    self.bound = bound or AnyType()

name class-attribute instance-attribute

name = 'TypeVar'

Name of the attribute in printing and other text format.

TypeofMethodType dataclass

TypeofMethodType()

Bases: TypeAttribute

name class-attribute instance-attribute

name = 'TypeofMethodType'

Name of the attribute in printing and other text format.

Union dataclass

Union(
    typ_or_set: (
        TypeAttribute | typing.Iterable[TypeAttribute]
    ),
    *typs: TypeAttribute
)

Bases: TypeAttribute

Source code in src/kirin/ir/attrs/types.py
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
def __init__(
    self,
    typ_or_set: TypeAttribute | typing.Iterable[TypeAttribute],
    *typs: TypeAttribute,
):
    if isinstance(typ_or_set, TypeAttribute):
        params: typing.Iterable[TypeAttribute] = (typ_or_set, *typs)
    else:
        params = typ_or_set
        assert not typs, "Cannot pass multiple arguments when passing a set"

    types: frozenset[TypeAttribute] = frozenset()
    for typ in params:
        if isinstance(typ, Union):
            types = types.union(typ.types)
        else:
            types = types.union({typ})
    self.types = types

name class-attribute instance-attribute

name = 'Union'

Name of the attribute in printing and other text format.

join

join(other: TypeAttribute) -> TypeAttribute

Join operation.

Source code in src/kirin/ir/attrs/types.py
402
403
404
405
406
407
408
409
410
411
def join(self, other: TypeAttribute) -> TypeAttribute:
    if self.is_subseteq(other):
        return other
    elif other.is_subseteq(self):
        return self
    elif isinstance(other, Union):
        return Union(self.types | other.types)
    elif isinstance(other, TypeAttribute):
        return Union(self.types | {other})
    return BottomType()

meet

meet(other: TypeAttribute) -> TypeAttribute

Meet operation.

Source code in src/kirin/ir/attrs/types.py
413
414
415
416
417
418
419
420
421
422
def meet(self, other: TypeAttribute) -> TypeAttribute:
    if self.is_subseteq(other):
        return self
    elif other.is_subseteq(self):
        return other
    elif isinstance(other, Union):
        return Union(self.types & other.types)
    elif isinstance(other, TypeAttribute):
        return Union(self.types & {other})
    return BottomType()

Vararg dataclass

Vararg(typ: TypeAttribute)

Bases: Attribute

name class-attribute instance-attribute

name = 'Vararg'

Name of the attribute in printing and other text format.