effekt icon indicating copy to clipboard operation
effekt copied to clipboard

Region of local mutable variables disagrees with llvm backend semantics

Open phischu opened this issue 1 month ago • 1 comments

Consider the following program:

def test3(): Int = {
  val f = {
    var l = 1;
    box { l }
  }
  f()
}

def main() = println(test3())

It should print 1, which it does. Except when run with effekt --backend=llvm --no-optimize, where it prints 105971318358032, some garbage value. The local mutable variable l escapes its region, which in the llvm backend operationally is only until the end of the local compound statement (block).

phischu avatar Nov 06 '25 15:11 phischu

Shouldn't this code be illegal? f: () -> Int at { l } right? And test3's body does not have access to l, so it shouldn't be able to use it. Thus, the code should be rejected. I also see the argument that the local variable gets stored in the closest enclosing function (so the closest lambda or def). Then the LLVM backend needs to allocate it into test3's region

kyay10 avatar Nov 07 '25 17:11 kyay10