Skip to content

Refactoring AST lowering transform#343

Merged
Roger-luo merged 24 commits into
mainfrom
roger/lowering-refactor
Apr 2, 2025
Merged

Refactoring AST lowering transform#343
Roger-luo merged 24 commits into
mainfrom
roger/lowering-refactor

Conversation

@Roger-luo
Copy link
Copy Markdown
Collaborator

@Roger-luo Roger-luo commented Mar 31, 2025

finally decide to just do it... gonna supercede #315

This PR refactors the AST lowering framework to make it more generic. So that other langauge AST can reuse the framework to generate SSA IR (e.g QASM2, etc.). We will also try to clean up the APIs in the process.

Highlights

  • new error message of lowering
image
  • removing the push_frame and pop_frame in lowering.State. Now you can just write
with state.frame(stmts) as body_frame:
   ...

The main changes are mostly splitting the APIs into several classes. We still need to improve the precision of error reports here, but we will do that in a few following PRs.

cc: @weinbe58

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 31, 2025

PR Preview Action v1.6.0
Preview removed because the pull request was closed.
2025-04-02 18:06 UTC

@Roger-luo Roger-luo added category: breaking change Category: breaking changes or proposed changes to APIs. area: python lowering Area: Python lowering related issues. labels Mar 31, 2025
@Roger-luo Roger-luo changed the title refactoring AST lowering transform WIP: refactoring AST lowering transform Mar 31, 2025
@Roger-luo Roger-luo marked this pull request as draft March 31, 2025 23:29
@Roger-luo Roger-luo changed the title WIP: refactoring AST lowering transform Refactoring AST lowering transform Mar 31, 2025
@Roger-luo Roger-luo marked this pull request as ready for review April 2, 2025 17:32
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 2, 2025

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 2, 2025

☂️ Python Coverage

current status: ✅

Overall Coverage

Lines Covered Coverage Threshold Status
9116 8018 88% 0% 🟢

New Files

File Coverage Status
src/kirin/lowering/abc.py 90% 🟢
src/kirin/lowering/exception.py 63% 🟢
src/kirin/lowering/python/_init_.py 100% 🟢
src/kirin/lowering/python/glob.py 83% 🟢
src/kirin/lowering/python/lowering.py 88% 🟢
src/kirin/lowering/python/traits.py 82% 🟢
TOTAL 84% 🟢

Modified Files

File Coverage Status
src/kirin/_init_.py 100% 🟢
src/kirin/dialects/debug.py 94% 🟢
src/kirin/dialects/ilist/_wrapper.py 100% 🟢
src/kirin/dialects/ilist/lowering.py 100% 🟢
src/kirin/dialects/ilist/stmts.py 100% 🟢
src/kirin/dialects/lowering/call.py 96% 🟢
src/kirin/dialects/lowering/cf.py 96% 🟢
src/kirin/dialects/lowering/func.py 93% 🟢
src/kirin/dialects/lowering/range.py 94% 🟢
src/kirin/dialects/math/_init_.py 100% 🟢
src/kirin/dialects/math/stmts.py 100% 🟢
src/kirin/dialects/py/assertion.py 92% 🟢
src/kirin/dialects/py/assign.py 93% 🟢
src/kirin/dialects/py/attr.py 93% 🟢
src/kirin/dialects/py/base.py 82% 🟢
src/kirin/dialects/py/binop/lowering.py 92% 🟢
src/kirin/dialects/py/binop/stmts.py 100% 🟢
src/kirin/dialects/py/boolop.py 91% 🟢
src/kirin/dialects/py/builtin.py 90% 🟢
src/kirin/dialects/py/cmp/lowering.py 96% 🟢
src/kirin/dialects/py/cmp/stmts.py 100% 🟢
src/kirin/dialects/py/constant.py 95% 🟢
src/kirin/dialects/py/indexing.py 90% 🟢
src/kirin/dialects/py/iterable.py 76% 🟢
src/kirin/dialects/py/len.py 87% 🟢
src/kirin/dialects/py/list/lowering.py 79% 🟢
src/kirin/dialects/py/list/stmts.py 100% 🟢
src/kirin/dialects/py/range.py 94% 🟢
src/kirin/dialects/py/slice.py 92% 🟢
src/kirin/dialects/py/tuple.py 85% 🟢
src/kirin/dialects/py/unary/lowering.py 90% 🟢
src/kirin/dialects/py/unary/stmts.py 100% 🟢
src/kirin/dialects/py/unpack.py 80% 🟢
src/kirin/dialects/scf/lowering.py 96% 🟢
src/kirin/exceptions.py 94% 🟢
src/kirin/ir/_init_.py 100% 🟢
src/kirin/ir/dialect.py 88% 🟢
src/kirin/ir/group.py 95% 🟢
src/kirin/ir/traits/_init_.py 100% 🟢
src/kirin/ir/traits/abc.py 88% 🟢
src/kirin/ir/traits/callable.py 83% 🟢
src/kirin/ir/traits/symbol.py 73% 🟢
src/kirin/lowering/_init_.py 100% 🟢
src/kirin/lowering/frame.py 94% 🟢
src/kirin/lowering/state.py 81% 🟢
src/kirin/lowering/stream.py 72% 🟢
TOTAL 92% 🟢

updated for commit: 1b4d067 by action🐍

@Roger-luo Roger-luo merged commit df6efeb into main Apr 2, 2025
11 of 12 checks passed
@Roger-luo Roger-luo deleted the roger/lowering-refactor branch April 2, 2025 18:05
Roger-luo added a commit that referenced this pull request Apr 5, 2025
finally decide to just do it... gonna supercede #315 

This PR refactors the AST lowering framework to make it more generic. So
that other langauge AST can reuse the framework to generate SSA IR (e.g
QASM2, etc.). We will also try to clean up the APIs in the process.

### Highlights

- new error message of lowering

<img width="682" alt="image"
src="https://github.com/user-attachments/assets/b5591b7a-a3dc-44fa-b977-538a2049d691"
/>

- removing the `push_frame` and `pop_frame` in `lowering.State`. Now you
can just write

```python
with state.frame(stmts) as body_frame:
   ...
```

The main changes are mostly splitting the APIs into several classes. We
still need to improve the precision of error reports here, but we will
do that in a few following PRs.

cc: @weinbe58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: python lowering Area: Python lowering related issues. category: breaking change Category: breaking changes or proposed changes to APIs.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant