jfecher / ante

A safe, easy systems language
http://antelang.org
MIT License
1.9k stars 79 forks source link

captured value will be destroyed #141

Closed eldesh closed 2 years ago

eldesh commented 2 years ago

I found a compiler bug. The compiler accepts the following code but outputs a broken program. It mysteriously destroys the captured value v.

Environment

Code

f (v:float) : float =
  go x =
    if x < 2.0 then x
    else
      print v
      go (x / 2.0)
  go (v / 2.0)

x = f 123.0

Output

ante test.an
123.0
61.5000
30.7500
15.3750
7.6875
jfecher commented 2 years ago

Took a quick look at the hir and cranelift/llvm irs. Looks like the closure value is being referenced to like a normal lambda without its environment within the closure's recursive calls