You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
JS lane: List.length over a long list dies with a stack overflow (the base recursion is not in tail position); a tail counter over the same list completes #802
A 200,000-element list (built by a tail-recursive helper, no large literals), counted two ways:
bend llist.bend (JS lane), List.length
bend llist.bend -o llist && ./llist (native C lane)
same with an inner tail counter instead of List.length
What happened
JS lane, List.length:
bend: memory fault (machine stack overflow?)
JS lane, tail counter over the same list: len=200000. Native, both: len=200000.
Threshold on the JS lane: 10,000 elements count fine, 50,000 fails. Base.List.length is not tail-recursive (1n+List.length(a, A, t), bend2/base.bend:742-747 at 0b7e2b1), so the emitted JS keeps one frame per element. Same class as #798 for String.split/String.length (which is why our parser lane avoids it with a counter), but this is the List helper. Reproduces on 2.0.4 and 2.0.5.
The file
import Base
def gen(n: Nat, acc: List<&2, U32>) -> List<&2, U32>:
match n:
case 0n:
acc
case 1n+p:
gen(p, 1 <> acc)
def main() -> IO(Unit):
do IO<Unit>:
IO.print("len=" ++ Nat.show(List.length(&2, U32, gen(Nat.mul(100n, 2000n), Nil{}))))
The counter variant replaces List.length(...) with count.go(gen(...), 0n); count.go is Nil{} -> n; h <> t -> count.go(t, 1n+n).
Same root cause as #798 (a non-tail call is a host frame on the JS lane). String.length got an intrinsic in 2.0.7; List.length and the other folds wait for continuation passing in the JS emitter, which we will add soon (WONTFIX.txt, SOON). Closing to keep the thread in #798.
Note: this reply was written by an AI after it reported the issue to me and I made the decision. If anything here is wrong, reply and I will review it myself.
Activity
VictorTaelin commentedon Sep 18, 2026
Same root cause as #798 (a non-tail call is a host frame on the JS lane).
String.lengthgot an intrinsic in 2.0.7;List.lengthand the other folds wait for continuation passing in the JS emitter, which we will add soon (WONTFIX.txt, SOON). Closing to keep the thread in #798.Note: this reply was written by an AI after it reported the issue to me and I made the decision. If anything here is wrong, reply and I will review it myself.