Skip to content

Info

ArgumentField dataclass

ArgumentField(
    kw_only: bool,
    alias: Optional[str],
    type: TypeAttribute,
    print: bool = True,
    group: bool = False,
)

Bases: Field


              flowchart TD
              kirin.decl.info.ArgumentField[ArgumentField]
              kirin.decl.info.Field[Field]

                              kirin.decl.info.Field --> kirin.decl.info.ArgumentField
                


              click kirin.decl.info.ArgumentField href "" "kirin.decl.info.ArgumentField"
              click kirin.decl.info.Field href "" "kirin.decl.info.Field"
            

group class-attribute instance-attribute

group: bool = False

if True, this argument is annotated with Tuple[SSAValue, ...]

print class-attribute instance-attribute

print: bool = True

if True, this argument name is printed in the signature.

type instance-attribute

type: TypeAttribute

type of the argument, will be used in validation.

AttributeField dataclass

AttributeField(
    kw_only: bool,
    alias: Optional[str],
    default: Any,
    init: bool,
    repr: bool,
    default_factory: Optional[Callable[[], Attribute]],
    type: TypeAttribute,
    pytype: bool = False,
)

Bases: Field


              flowchart TD
              kirin.decl.info.AttributeField[AttributeField]
              kirin.decl.info.Field[Field]

                              kirin.decl.info.Field --> kirin.decl.info.AttributeField
                


              click kirin.decl.info.AttributeField href "" "kirin.decl.info.AttributeField"
              click kirin.decl.info.Field href "" "kirin.decl.info.Field"
            

pytype class-attribute instance-attribute

pytype: bool = False

if True, annotation is a python type hint instead of TypeAttribute

StatementFields dataclass

StatementFields(
    std_args: dict[str, ArgumentField] = dict(),
    kw_args: dict[str, ArgumentField] = dict(),
    results: dict[str, ResultField] = dict(),
    regions: dict[str, RegionField] = dict(),
    blocks: dict[str, BlockField] = dict(),
    attributes: dict[str, AttributeField] = dict(),
)

args property

args

iterable of all argument fields.

attributes class-attribute instance-attribute

attributes: dict[str, AttributeField] = field(
    default_factory=dict
)

attributes of the statement.

blocks class-attribute instance-attribute

blocks: dict[str, BlockField] = field(default_factory=dict)

blocks of the statement.

kw_args class-attribute instance-attribute

kw_args: dict[str, ArgumentField] = field(
    default_factory=dict
)

keyword-only arguments of the statement.

regions class-attribute instance-attribute

regions: dict[str, RegionField] = field(
    default_factory=dict
)

regions of the statement.

required_names cached property

required_names

set of all fields that do not have a default value.

results class-attribute instance-attribute

results: dict[str, ResultField] = field(
    default_factory=dict
)

results of the statement.

std_args class-attribute instance-attribute

std_args: dict[str, ArgumentField] = field(
    default_factory=dict
)

standard arguments of the statement.

argument

argument(
    type: TypeAttribute = types.Any,
    *,
    print: bool = True,
    kw_only: bool = False,
    alias: Optional[str] = None
) -> Any

Field specifier for arguments.

Parameters:

Name Type Description Default
type TypeAttribute

type of the argument, will be used in validation.

Any
print bool

if True, this argument name is printed in the signature.

True
kw_only bool

if True, this argument is keyword-only.

False
alias Optional[str]

an alias for the argument name in the __init__ method.

None
Source code in src/kirin/decl/info.py
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
def argument(
    type: types.TypeAttribute = types.Any,
    *,
    print: bool = True,
    kw_only: bool = False,
    alias: Optional[str] = None,
) -> Any:
    """Field specifier for arguments.

    Args:
        type(TypeAttribute): type of the argument, will be used in validation.
        print(bool): if `True`, this argument name is printed in the signature.
        kw_only(bool): if `True`, this argument is keyword-only.
        alias(Optional[str]): an alias for the argument name in the `__init__` method.
    """
    return ArgumentField(
        type=type,
        print=print,
        kw_only=kw_only,
        alias=alias,
    )

block

block(
    *,
    init: bool = True,
    repr: bool = True,
    kw_only: bool = True,
    alias: Optional[str] = None,
    default_factory: Callable[[], Block] = Block
) -> Any

Field specifier for blocks.

Parameters:

Name Type Description Default
init bool

if True, this block field is included in the __init__ method.

True
repr bool

if True, this block field is included in the __repr__ and pretty printing.

True
kw_only bool

if True, this block field is keyword-only.

True
alias Optional[str]

an alias for the block field name in the __init__ method.

None
default_factory Callable[[], Block]

a factory function to create a default block.

Block
Source code in src/kirin/decl/info.py
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
def block(
    *,
    init: bool = True,
    repr: bool = True,
    kw_only: bool = True,
    alias: Optional[str] = None,
    default_factory: Callable[[], Block] = Block,
) -> Any:
    """Field specifier for blocks.

    Args:
        init(bool): if `True`, this block field is included in the `__init__` method.
        repr(bool): if `True`, this block field is included in the `__repr__` and pretty printing.
        kw_only(bool): if `True`, this block field is keyword-only.
        alias(Optional[str]): an alias for the block field name in the `__init__` method.
        default_factory(Callable[[], Block]): a factory function to create a default block.
    """
    if kw_only is False:
        raise TypeError("block fields must be keyword-only")

    return BlockField(
        init=init,
        repr=repr,
        kw_only=kw_only,
        alias=alias,
        default_factory=default_factory,
    )

region

region(
    *,
    init: bool = True,
    repr: bool = True,
    kw_only: bool = True,
    alias: Optional[str] = None,
    multi: bool = False,
    default_factory: Callable[[], Region] = Region
) -> Any

Field specifier for regions.

Parameters:

Name Type Description Default
init bool

if True, this region field is included in the __init__ method.

True
repr bool

if True, this region field is included in the __repr__ and pretty printing.

True
kw_only bool

if True, this region field is keyword-only.

True
alias Optional[str]

an alias for the region field name in the __init__ method.

None
multi bool

if True, this region can contain multiple blocks.

False
default_factory Callable[[], Region]

a factory function to create a default region.

Region
Source code in src/kirin/decl/info.py
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
def region(
    *,
    init: bool = True,  # so we can use the default_factory
    repr: bool = True,
    kw_only: bool = True,
    alias: Optional[str] = None,
    multi: bool = False,
    default_factory: Callable[[], Region] = Region,
) -> Any:
    """Field specifier for regions.

    Args:
        init(bool): if `True`, this region field is included in the `__init__` method.
        repr(bool): if `True`, this region field is included in the `__repr__` and pretty printing.
        kw_only(bool): if `True`, this region field is keyword-only.
        alias(Optional[str]): an alias for the region field name in the `__init__` method.
        multi(bool): if `True`, this region can contain multiple blocks.
        default_factory(Callable[[], Region]): a factory function to create a default region.
    """
    if kw_only is False:
        raise TypeError("region fields must be keyword-only")

    return RegionField(
        init=init,
        repr=repr,
        kw_only=kw_only,
        alias=alias,
        multi=multi,
        default_factory=default_factory,
    )

result

result(
    type: TypeAttribute = types.Any,
    *,
    init: bool = False,
    repr: bool = True,
    kw_only: bool = True,
    alias: Optional[str] = None
) -> Any

Field specifier for results.

Parameters:

Name Type Description Default
type TypeAttribute

type of the result.

Any
init bool

if True, this result field is included in the __init__ method.

False
repr bool

if True, this result field is included in the __repr__ and pretty printing.

True
kw_only bool

if True, this result field is keyword-only.

True
alias Optional[str]

an alias for the result field name in the __init__ method.

None
Source code in src/kirin/decl/info.py
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
def result(
    type: types.TypeAttribute = types.Any,
    *,
    # NOTE: init is false, use other hooks to set custom results
    # or just mutate the statement after creation
    init: bool = False,
    repr: bool = True,
    kw_only: bool = True,
    alias: Optional[str] = None,
) -> Any:
    """Field specifier for results.

    Args:
        type(TypeAttribute): type of the result.
        init(bool): if `True`, this result field is included in the `__init__` method.
        repr(bool): if `True`, this result field is included in the `__repr__` and pretty printing.
        kw_only(bool): if `True`, this result field is keyword-only.
        alias(Optional[str]): an alias for the result field name in the `__init__` method.
    """
    if kw_only is False:  # for linting
        raise TypeError("result fields must be keyword-only")

    if init is True:
        raise TypeError("result fields cannot appear in __init__")

    return ResultField(
        type=type,
        init=init,
        repr=repr,
        kw_only=kw_only,
        alias=alias,
    )