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

"pop_frame: Empty call stack" when folding a tuple of maps #6

Closed
spbots opened this issue Dec 4, 2020 · 4 comments · Fixed by #7
Closed

"pop_frame: Empty call stack" when folding a tuple of maps #6

spbots opened this issue Dec 4, 2020 · 4 comments · Fixed by #7
Labels
bug Something isn't working

Comments

@spbots
Copy link

spbots commented Dec 4, 2020

See the following example for the issue and a workaround:

import io, koto, string.print

export main = ||
  map_is_valid = |m| m.get("bar") != ()
  tuple_of_maps = ({foo: 2}, {}, {foo: 4, bar: 2})

  # uncomment the following print for the following error:
  #
  #     pop_frame: Empty call stack
  #      --> fold_test.koto - 1:1
  #        |
  #      1 | import io, koto, string.print
  #        | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  #
  # print "is_valid 2: {}" (map_is_valid tuple_of_maps[2])

  print "is_valid 2: {}" (tuple_of_maps[2].get("bar") != ())

  n_valid = tuple_of_maps.fold(0, |acc, m| acc + (if map_is_valid(m) then 1 else 0))

  print "n_valid: {}" n_valid
@spbots
Copy link
Author

spbots commented Dec 4, 2020

I've played around with the minimal case a couple times — it looks like the issue is not actually caused by trying to fold the tuple_of_maps but by calling the map_is_valid function before the fold.

@irh
Copy link
Contributor

irh commented Dec 4, 2020

Thanks for the report 👍

@irh irh added the bug Something isn't working label Dec 4, 2020
@spbots
Copy link
Author

spbots commented Dec 4, 2020

Thanks for the fun language! It looks like it's not necessary to use the map_is_valid function for the fold e.g.

import io, koto, string.print

export main = ||
  map_is_valid = |m| m.get("bar") != ()

  tuple_of_maps = ({foo: 2}, {}, {foo: 4, bar: 2})

  # okay:
  # x = (tuple_of_maps[2].get("bar") != ())

  # explosion:
  # x = (map_is_valid tuple_of_maps[2])

  n_valid = tuple_of_maps.fold(
    0,
    |acc, mm| debug acc + (if mm.get("bar") != () then 1 else 0))

irh added a commit that referenced this issue Dec 4, 2020
Fixes #6 - stack overflow / empty call stack on pop when using fold() after
calling another function.
@irh irh mentioned this issue Dec 4, 2020
@irh
Copy link
Contributor

irh commented Dec 4, 2020

It turns out that calling any function before calling fold() can trigger the issue, it seems to be an unfortunate fluke that this hasn't come up before 🙃

f = || 1, 2, 3
f().fold 0 |x, n| x += n # error: empty call stack 

@irh irh closed this as completed in #7 Dec 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants