Segfault (139) when filling a list with 1M entries
The following program segfaults in our LLVM backend:
def main() = {
val l1 = fill(1000000, 1)
println(l1.sum)
}
with
terminated by signal SIGSEGV (Address boundary error)
The example can be further simplified to
def main() = {
def go(i: Int, acc: List[Int]): List[Int] =
if (i < 1000000) {
go(i + 1, Cons(1, acc))
} else acc
val l = go(0, Nil())
()
}
which does not have any other stdlib function calls and results in the following machine:
def main_123750() = {
def go_123752(i_123749 : Int, acc_123751 : Positive) = {
let longLiteral_123829 = 1000000;
let pureApp_123828 = infixLt_16465(i_123749, longLiteral_123829);
tmp_123827 := pureApp_123828;
switch tmp_123827
0 : { () =>
return acc_123751
}
1 : { () =>
let longLiteral_123831 = 1;
let pureApp_123830 = infixAdd_16383(i_123749, longLiteral_123831);
tmp_123823 := pureApp_123830;
let longLiteral_123833 = 1;
let pureApp_123832 = boxInt_16591(longLiteral_123833);
tmp_123824 := pureApp_123832;
let make_123834 = 1(tmp_123824, acc_123751);
tmp_123825 := make_123834;
i_123749 := tmp_123823, acc_123751 := tmp_123825;
jump go_123752
}
};
let make_123835 = 0();
tmp_123826 := make_123835;
val (l_123753 : Positive) = {
let longLiteral_123837 = 0;
i_123749 := longLiteral_123837, acc_123751 := tmp_123826;
jump go_123752
};
let unitLiteral_123836 = 0();
return unitLiteral_123836
};
jump main_123750
Maybe this is something for our LLVM bug hunters @marvinborner and @MattisKra ?
Maybe useful: This is an eraser stack overflow that doesn't happen with larger stack limits (e.g. ulimit -s unlimited)
This explains everything, thanks @marvinborner. 1-2 years ago I discussed with @phischu how the erasers should look like and I wished that for cons-lists they would happen to be tail-recursive so that they do not stack overflow....
Well 1-2 years later we are here :)
Seems like the refunctionalized approach also has its significant downsides compared to the "work list" approach, where the eraser is one loop.
The same will also apply to sharers, btw.