Open
Description
The following lowering doesn't look right to me:
from kirin.prelude import structual
@structural
def test(cond: bool) -> int:
c = 0
if cond:
c = 1
else:
return 2
return c
currently lowers to:
func.func @test(cond : !py.bool) -> !py.int {
^0(%test_self, %cond_1):
│ %c = py.constant.constant 0 : !py.int
│ %cond = scf.if %cond_1 : !py.bool {
│ │ ^1(%cond_2):
│ │ │ scf.yield %cond_2 : !py.bool
│ } else {
│ │ ^2(%cond_3):
│ │ │ %0 = py.constant.constant 2 : !py.int
│ │ │ func.return %0
│ } -> purity=False
│ func.return %c
} // func.func test
shuold be something more like:
func.func @test(cond : !py.bool) -> !py.int {
^0(%test_self, %cond_1):
│ %c = py.constant.constant 0 : !py.int
│ %cond, %c_1 = scf.if %cond_1 : !py.bool {
│ │ ^1(%cond_2):
│ │ │ %c_2 = py.constant 1
│ │ │ scf.yield %cond_2 : !py.bool, %c_2 : !py.int
│ } else {
│ │ ^2(%cond_3):
│ │ │ %0 = py.constant.constant 2 : !py.int
│ │ │ func.return %0
│ } -> purity=False
│ func.return %c_1
} // func.func test