Skip to content

Commit 6f6d7d4

Browse files
authored
implement griffe extension + try it on kirin builtin dialects (#196)
This implements a griffe extension for Kirin so that we can correctly display the generated constructor of Kirin statements and mark which is `argument`, `region`, `block` in the field labels, e.g <img width="706" alt="image" src="https://github.com/user-attachments/assets/15989f72-01e8-4ae7-a6b4-086efa8eb1d6" /> A follow up work is to actually move the extension into a package so that downstream packages can use it in combination with mkdocs.
1 parent f348f9c commit 6f6d7d4

File tree

25 files changed

+612
-17
lines changed

25 files changed

+612
-17
lines changed

docs/dialects/cf.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,8 @@
22
This page is under construction. The content may be incomplete or incorrect. Submit an issue
33
on [GitHub](https://github.com/QuEraComputing/kirin/issues/new) if you need help or want to
44
contribute.
5+
6+
7+
::: kirin.dialects.cf.stmts
8+
options:
9+
show_if_no_docstring: true

docs/dialects/func.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,7 @@
22
This page is under construction. The content may be incomplete or incorrect. Submit an issue
33
on [GitHub](https://github.com/QuEraComputing/kirin/issues/new) if you need help or want to
44
contribute.
5+
6+
::: kirin.dialects.func.stmts
7+
options:
8+
show_if_no_docstring: true

docs/dialects/ilist.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,8 @@
22
This page is under construction. The content may be incomplete or incorrect. Submit an issue
33
on [GitHub](https://github.com/QuEraComputing/kirin/issues/new) if you need help or want to
44
contribute.
5+
6+
7+
::: kirin.dialects.ilist.stmts
8+
options:
9+
show_if_no_docstring: true

docs/dialects/python/core.md

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
!!! warning
2+
This page is under construction. The content may be incomplete or incorrect. Submit an issue
3+
on [GitHub](https://github.com/QuEraComputing/kirin/issues/new) if you need help or want to
4+
contribute.
5+
6+
# Core Python Dialects
7+
8+
This page contains the core Python dialects that are used most frequently when designing an
9+
embedded DSL in Python.
10+
11+
## Reference
12+
13+
### Base
14+
15+
::: kirin.dialects.py.base
16+
options:
17+
filters:
18+
- "!statement"
19+
show_root_heading: true
20+
show_if_no_docstring: true
21+
22+
### Constant
23+
24+
::: kirin.dialects.py.constant
25+
options:
26+
filters:
27+
- "!statement"
28+
show_root_heading: true
29+
show_if_no_docstring: true
30+
31+
### UnaryOp
32+
33+
::: kirin.dialects.py.unary.stmts
34+
options:
35+
filters:
36+
- "!statement"
37+
show_root_heading: true
38+
show_if_no_docstring: true
39+
40+
41+
### BinOp
42+
43+
::: kirin.dialects.py.binop.stmts
44+
options:
45+
filters:
46+
- "!statement"
47+
show_root_heading: true
48+
show_if_no_docstring: true
49+
50+
### Assertion
51+
52+
::: kirin.dialects.py.assertion
53+
options:
54+
filters:
55+
- "!statement"
56+
show_root_heading: true
57+
show_if_no_docstring: true
58+
59+
### Assignment
60+
61+
::: kirin.dialects.py.assign
62+
options:
63+
filters:
64+
- "!statement"
65+
show_root_heading: true
66+
show_if_no_docstring: true
67+
68+
69+
### Unpack
70+
71+
::: kirin.dialects.py.unpack
72+
options:
73+
filters:
74+
- "!statement"
75+
show_root_heading: true
76+
show_if_no_docstring: true
77+
78+
79+
### Boolean Operation
80+
81+
::: kirin.dialects.py.boolop
82+
options:
83+
filters:
84+
- "!statement"
85+
show_root_heading: true
86+
show_if_no_docstring: true
87+
88+
### Comparison
89+
90+
::: kirin.dialects.py.cmp.stmts
91+
options:
92+
filters:
93+
- "!statement"
94+
show_root_heading: true
95+
show_if_no_docstring: true

docs/dialects/python/data.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
!!! warning
2+
This page is under construction. The content may be incomplete or incorrect. Submit an issue
3+
on [GitHub](https://github.com/QuEraComputing/kirin/issues/new) if you need help or want to
4+
contribute.
5+
6+
# Dialects that brings in common Python data types
7+
8+
This page provides a reference for dialects that bring in semantics for common Python data types.
9+
10+
!!! note
11+
While it is worth noting that using Python semantics can be very convenient, it is also important to remember that the Python semantics are not designed for compilation. Therefore, it is important to be aware of the limitations of using Python semantics in a compilation context especially when it comes to data types.
12+
An example of this is the `list` data type in Python which is a dynamic mutable array. When the low-level code is not expecting a dynamic mutable array, it can lead to extra complexity for compilation. An immutable array or a fixed-size array can be a better choice in such cases (see `ilist` dialect).
13+
14+
## References
15+
16+
### Tuple
17+
18+
::: kirin.dialects.py.tuple
19+
options:
20+
filters:
21+
- "!statement"
22+
show_root_heading: true
23+
show_if_no_docstring: true
24+
25+
### List
26+
27+
::: kirin.dialects.py.list
28+
options:
29+
filters:
30+
- "!statement"
31+
show_root_heading: true
32+
show_if_no_docstring: true

docs/dialects/python/index.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
!!! warning
2+
This page is under construction. The content may be incomplete or incorrect. Submit an issue
3+
on [GitHub](https://github.com/QuEraComputing/kirin/issues/new) if you need help or want to
4+
contribute.
5+
6+
# Python Dialects
7+
8+
Kirin provides a set of dialects that represents fractions of Python semantics. We will describe
9+
each dialect in this page. The general design principle of these dialects is to provide a composable
10+
set of Python semantics that can be used to build different embedded DSLs inside Python.

docs/dialects/python/sfunc.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
!!! warning
2+
This page is under construction. The content may be incomplete or incorrect. Submit an issue
3+
on [GitHub](https://github.com/QuEraComputing/kirin/issues/new) if you need help or want to
4+
contribute.
5+
6+
# Dialects for special Python functions
7+
8+
There are some special built-in Python functions that does not necessarily provide new data types when
9+
using them as Kirin dialects.
10+
11+
For example, the `py.range` dialect may not use a Python `range` type,
12+
the actual type can be decided by another dialect that implements the type inference method for [`Range`][kirin.dialects.py.Range] statement, e.g `ilist` dialect provides an `IList` implementation for `Range` statement.
13+
14+
The reason for this is that in many cases, eDSLs are not interested in the actual data type of the result, but rather the semantics of the operation. For `ilist` dialect, the `Range` statement is just a syntax sugar for creating a list of integers. The compiler will decide what the actual implementation (such as the memory layout) of the list should be.
15+
16+
# References
17+
18+
## Iterable
19+
20+
::: kirin.dialects.py.iterable
21+
options:
22+
filters:
23+
- "!statement"
24+
show_root_heading: true
25+
show_if_no_docstring: true
26+
27+
## Len
28+
29+
::: kirin.dialects.py.len
30+
options:
31+
filters:
32+
- "!statement"
33+
show_root_heading: true
34+
show_if_no_docstring: true
35+
36+
## Range
37+
38+
::: kirin.dialects.py.range
39+
options:
40+
filters:
41+
- "!statement"
42+
show_root_heading: true
43+
show_if_no_docstring: true
44+
45+
## Slice
46+
47+
::: kirin.dialects.py.slice
48+
options:
49+
filters:
50+
- "!statement"
51+
show_root_heading: true
52+
show_if_no_docstring: true
53+
54+
## Built-in Function
55+
56+
::: kirin.dialects.py.builtin
57+
options:
58+
filters:
59+
- "!statement"
60+
show_root_heading: true
61+
show_if_no_docstring: true

docs/dialects/python/sugar.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
!!! warning
2+
This page is under construction. The content may be incomplete or incorrect. Submit an issue
3+
on [GitHub](https://github.com/QuEraComputing/kirin/issues/new) if you need help or want to
4+
contribute.
5+
6+
# Dialects for Python Syntax Sugar
7+
8+
This page contains the dialects designed to represent Python syntax sugar. They provide an implementation
9+
of lowering transform from the corresponding Python AST to the dialects' statements. All the statements are
10+
typed `Any` thus one can always use a custom rewrite pass after type inference to support the desired syntax sugar.
11+
12+
## Reference
13+
14+
### Indexing
15+
16+
::: kirin.dialects.py.indexing
17+
options:
18+
filters:
19+
- "!statement"
20+
show_root_heading: true
21+
show_if_no_docstring: true
22+
23+
### Attribute
24+
25+
::: kirin.dialects.py.attr
26+
options:
27+
filters:
28+
- "!statement"
29+
show_root_heading: true
30+
show_if_no_docstring: true
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,11 @@
22
This page is under construction. The content may be incomplete or incorrect. Submit an issue
33
on [GitHub](https://github.com/QuEraComputing/kirin/issues/new) if you need help or want to
44
contribute.
5+
6+
# SCF Dialects
7+
8+
# Reference
9+
10+
::: kirin.dialects.scf.stmts
11+
options:
12+
show_if_no_docstring: true

docs/interp.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ class Assert(Statement):
9898
message: SSAValue = info.argument(String)
9999
```
100100

101-
When interpreting an `Assert` statement, we need to check the condition and raise an error if it is false, this can be either returning the [`interp.Err`][kirin.interp.Err] object:
101+
When interpreting an `Assert` statement, we need to check the condition and raise an error if it is false:
102102

103103
```python
104104
@dialect.register
@@ -110,9 +110,9 @@ class CfMethods(MethodTable):
110110
return ()
111111

112112
if stmt.message:
113-
return Err(AssertionError(frame.get(stmt.message)), interp.state.frames)
113+
raise interp.WrapException(AssertionError(frame.get(stmt.message)))
114114
else:
115-
return Err(AssertionError(), interp.state.frames)
115+
raise interp.WrapException(AssertionError("Assertion failed"))
116116
```
117117

118118
or raising an [`InterpreterError`][kirin.exceptions.InterpreterError]:

0 commit comments

Comments
 (0)