Skip to content

Conversation

@zhenrongliew
Copy link
Contributor

A ClosureFieldLowering pass that lowers closure-captured fields into py.Constant.
e.g. the higher-order function outer returns inner which closes over parameter y.

@basic
def outer(y: int):
    def inner(x: int):
        return x * y + 1
    return outer

inner_ker = outer(y=10)

inner_ker.print() will go from:

func.lambda inner(%y : !py.int) -> !Any {
  ^0(%inner_self, %x):
  │ %y_1 = func.getfield(%inner_self, 0) : !py.int
  │   %0 = py.binop.mult(%x : !py.int, %y_1) : ~T
  │   %1 = py.constant.constant 1 : !py.int
  │   %2 = py.binop.add(%0, %1) : ~T
  │        func.return %2
} // func.lambda inner

to:

func.lambda inner(%y : !py.int) -> !Any {
  ^0(%inner_self, %x):
  │ %y_1 = py.constant.constant 10 : !py.int
  │   %0 = py.binop.mult(%x : !py.int, %y_1) : ~T
  │   %1 = py.constant.constant 1 : !py.int
  │   %2 = py.binop.add(%0, %1) : ~T
  │        func.return %2
} // func.lambda inner

…ting closure getfield lowering. `ir.Block`'s `is_structurally_equal`: Added early return if self is already in context.
@github-actions
Copy link
Contributor

github-actions bot commented Oct 22, 2025

PR Preview Action v1.6.2
Preview removed because the pull request was closed.
2025-10-22 19:50 UTC

@codecov
Copy link

codecov bot commented Oct 22, 2025

Codecov Report

❌ Patch coverage is 92.59259% with 4 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/kirin/rewrite/closurefieldlowering.py 93.18% 3 Missing ⚠️
src/kirin/dialects/scf/stmts.py 75.00% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@github-actions
Copy link
Contributor

github-actions bot commented Oct 22, 2025

☂️ Python Coverage

current status: ✅

Overall Coverage

Lines Covered Coverage Threshold Status
11382 10144 89% 0% 🟢

New Files

File Coverage Status
src/kirin/rewrite/closurefieldlowering.py 93% 🟢
TOTAL 93% 🟢

Modified Files

File Coverage Status
src/kirin/dialects/scf/stmts.py 83% 🟢
src/kirin/ir/nodes/block.py 80% 🟢
src/kirin/lowering/frame.py 94% 🟢
src/kirin/passes/fold.py 100% 🟢
src/kirin/rewrite/_init_.py 100% 🟢
TOTAL 91% 🟢

updated for commit: 3d82e63 by action🐍

zhenrongliew and others added 3 commits October 22, 2025 15:31
Fix Pyright complains from #535 and #536 (that removed`isinstance`
causing performance issue).
Casts to correct type so pyright doesn't complain
…ting closure getfield lowering. `ir.Block`'s `is_structurally_equal`: Added early return if self is already in context.
@Roger-luo Roger-luo merged commit a61e51f into main Oct 22, 2025
13 checks passed
@Roger-luo Roger-luo deleted the dl/lambda-rewrite branch October 22, 2025 19:49
@zhenrongliew zhenrongliew restored the dl/lambda-rewrite branch October 22, 2025 20:02
@zhenrongliew zhenrongliew deleted the dl/lambda-rewrite branch October 22, 2025 20:56
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.

3 participants