Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
OceanOak opened this issue Dec 26, 2023 · 2 comments · May be fixed by #5406
Open

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

OceanOak opened this issue Dec 26, 2023 · 2 comments · May be fixed by #5406
Labels
ready-for-contribs There's work here that's relatively approachable, if you're interested!

Comments

@OceanOak
Copy link
Collaborator

OceanOak commented Dec 26, 2023

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:

  • Bad implementation of List.map
let map (list: List<'a>) (fn: 'a -> 'b) : List<'b> =
 (PACKAGE.Darklang.Stdlib.List.fold list [] (fun acc elem ->
   PACKAGE.Darklang.Stdlib.List.push_v0 acc (fn elem)))
 |> PACKAGE.Darklang.Stdlib.List.reverse
  • An issue with our interpreter
@StachuDotNet StachuDotNet changed the title List.map Causes Stack Overflow Error on Large Lists Bug: List.map Causes Stack Overflow Error on Large Lists Jan 9, 2024
@StachuDotNet
Copy link
Member

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
Copy link
Collaborator Author

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

@StachuDotNet StachuDotNet added needs-review I plan on going through each of the issues and clarifying them -- this is to mark remaining issues contributor-friendly and removed needs-review I plan on going through each of the issues and clarifying them -- this is to mark remaining issues labels Feb 14, 2024
@StachuDotNet StachuDotNet added ready-for-contribs There's work here that's relatively approachable, if you're interested! and removed contributor-friendly labels Mar 5, 2024
@StachuDotNet StachuDotNet linked a pull request Aug 14, 2024 that will close this issue
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready-for-contribs There's work here that's relatively approachable, if you're interested!
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants