Skip to content

Add Set dialect and support of ListComp & SetComp lowering#634

Open
kaihsin wants to merge 3 commits intomainfrom
khwu/set
Open

Add Set dialect and support of ListComp & SetComp lowering#634
kaihsin wants to merge 3 commits intomainfrom
khwu/set

Conversation

@kaihsin
Copy link
Copy Markdown
Collaborator

@kaihsin kaihsin commented Apr 5, 2026

This PR add py.set dialect and support over ListComp & SetComp lowering

from kirin.prelude import basic

@basic
def main(n_elem: int):
    return [x*2 for x in range(n_elem) if x%2 == 0]

lower to

func.func @main(n_elem : !py.int) -> !Any {
  ^0(%main_self, %n_elem):
  │   %_kirin_listcomp_tmp = py.constant.constant IList([]) : !py.IList[!Any, Literal(0,int)]
  │                     %0 = py.constant.constant 0 : !py.int%1 = py.constant.constant 1 : !py.int%2 = py.ilist.range(start=%0, stop=%n_elem : !py.int, step=%1) : !py.IList[!py.int, !Any]
  │                     %3 = py.iterable.iter(value=%2) : !Any%4 = py.constant.constant None : !py.NoneType%5 = py.iterable.next(iter=%3) : !Any%6 = py.cmp.is(lhs=%5, rhs=%4) : !py.boolcf.cond_br %6 goto ^4(%_kirin_listcomp_tmp) else ^1(%5, %_kirin_listcomp_tmp)
  ^1(%x_1, %_kirin_listcomp_tmp_2):
  │                     %7 = py.constant.constant 2 : !py.int%8 = py.binop.mod(%x_1, %7) : ~T%9 = py.constant.constant 0 : !py.int%10 = py.cmp.eq(lhs=%8, rhs=%9) : !py.boolcf.cond_br %10 goto ^2(%10) else ^3(%_kirin_listcomp_tmp_2 : !py.IList[!Any, Literal(0,int)])
  ^2(%16):
  │                    %11 = py.constant.constant 2 : !py.int%12 = py.binop.mult(%x_1, %11) : ~T%13 = py.ilist.new(values=(%12)){elem_type=~T} : !py.IList[~T, Literal(1,int)]
  │ %_kirin_listcomp_tmp_1 = py.binop.add(%_kirin_listcomp_tmp_2 : !py.IList[!Any, Literal(0,int)], %13) : ~Tcf.br ^3(%_kirin_listcomp_tmp_1)
  ^3(%_kirin_listcomp_tmp_3):
  │                    %14 = py.iterable.next(iter=%3) : !Any%15 = py.cmp.is(lhs=%14, rhs=%4) : !py.boolcf.cond_br %15 goto ^4(%_kirin_listcomp_tmp_3) else ^1(%14, %_kirin_listcomp_tmp_3)
  ^4(%_kirin_listcomp_tmp_4):
  │                          func.return %_kirin_listcomp_tmp_4 : !py.IList[!Any, Literal(0,int)]
} // func.func main

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 5, 2026

Codecov Report

❌ Patch coverage is 98.14815% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/kirin/dialects/py/list/lowering.py 66.66% 1 Missing ⚠️
src/kirin/dialects/py/set/lowering.py 93.75% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 5, 2026

☂️ Python Coverage

current status: ✅

Overall Coverage

Lines Covered Coverage Threshold Status
11554 10388 90% 0% 🟢

New Files

File Coverage Status
src/kirin/dialects/py/_comprehension.py 100% 🟢
src/kirin/dialects/py/set/_init_.py 100% 🟢
src/kirin/dialects/py/set/_dialect.py 100% 🟢
src/kirin/dialects/py/set/interp.py 100% 🟢
src/kirin/dialects/py/set/lowering.py 94% 🟢
src/kirin/dialects/py/set/stmts.py 100% 🟢
src/kirin/dialects/py/set/typeinfer.py 100% 🟢
TOTAL 99% 🟢

Modified Files

File Coverage Status
src/kirin/dialects/func/typeinfer.py 92% 🟢
src/kirin/dialects/ilist/lowering.py 89% 🟢
src/kirin/dialects/py/_init_.py 100% 🟢
src/kirin/dialects/py/list/lowering.py 76% 🟢
src/kirin/dialects/scf/typeinfer.py 79% 🟢
src/kirin/prelude.py 100% 🟢
TOTAL 90% 🟢

updated for commit: ca45a09 by action🐍

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 5, 2026

PR Preview Action v1.8.1

QR code for preview link

🚀 View preview at
https://QuEraComputing.github.io/kirin/pr-preview/pr-634/

Built to branch gh-pages at 2026-04-05 22:37 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

@kaihsin kaihsin requested review from Roger-luo and weinbe58 April 5, 2026 22:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant