Since kirin has everything thats immutable, the x+=3 in the following cases gets mangled upon lowering
from kirin.prelude import basic
@basic
def gam(y):
x = 1
a = x + y
x += 3
b = x + y
return a,b
gam.print()
gives:
func.func @gam(y : !Any) -> !Any {
^0(%gam_self, %y):
│ %x = py.constant.constant 1 : !py.int
│ %a = py.binop.add(%x, %y) : ~T
│ %x_1 = py.constant.constant 4 : !py.int
│ %b = py.binop.add(%x_1, %y) : ~T
│ %0 = py.tuple.new(%a, %b) : !py.tuple[~T, ~T]
│ func.return %0
} // func.func gam
However in the case where lambda is involved:
@basic
def main(z):
x = 3
def y(i):
return x + i + z
a = y(1)
x += 1
b = y(1)
return a,b
main.print()
def main2():
x = 3
def y(i):
return x + i
a = y(1)
x += 1
b = y(1)
return a,b
print("py",main2())
print("kirin",main())
The kirin gives wrong result than the python:
Since kirin has everything thats immutable, the x+=3 in the following cases gets mangled upon lowering
gives:
However in the case where lambda is involved:
The kirin gives wrong result than the python: