darklang / dark

Darklang main repo, including language, backend, and infra
https://darklang.com
Other
1.66k stars 90 forks source link

Bug: List.map Causes Stack Overflow Error on Large Lists #5222

Open OceanOak opened 8 months ago

OceanOak commented 8 months ago

Preamble: this is probably one of the most pressing limitations of our runtime. It requires some interpreter work, but should be generally accessible to anyone interested.


List.map causes a stack overflow when run in Debug mode, but not when running in Release mode

Code to reproduce the issue:

((PACKAGE.Darklang.Stdlib.List.repeat_v0 348L 1L)
 |> Builtin.unwrap
 |> PACKAGE.Darklang.Stdlib.List.map (fun f -> f)) = []

After running some tests @StachuDotNet found that 348 is the threshold

The tests pass in CI but fail when run locally, indicating that something is different between Release and Debug builds

Potential reasons for this issue:

StachuDotNet commented 8 months ago

some relevant links, from some chatter in discord a bit back

I found a set of blog posts that I thought you might find interesting, related to the recursion stuff you've been doing in the StdLib

OceanOak commented 8 months ago

Related to convo about tail recursion, saw this https://devblogs.microsoft.com/dotnet/safer-recursion-in-fsharp/