So I'm working on todays advent of code.
I started using @Luke Boswell's roc-parser because it looks like it has the comfy parser stuff I want.
It works pretty well, but it fails with an "out of memory" panic in some places, and I can't figure out why.
I don't think I'm doing any spooky infinite recusion stuff.
The error I get on the tests that panic is:
thread 'main' panicked at 'out of memory', /build/cargo-vendor-dir/bumpalo-3.14.0/src/li
b.rs:1854:5
I've been going mad about this for over an hour now; I can't seem to work around it.
So now I'm asking for help in here again :sweat_smile:
I've whittled it down to some small-ish things that fail:
Color : [Red, Green, Blue]
parseColor : Parser RawStr Color
parseColor = oneOf [
string "red" |> map (\_ -> Red),
string "green" |> map (\_ -> Green),
string "green" |> map (\_ -> Blue)
]
expect # this one works
in = "red"
result = parseStr parseColor in
result == Ok Red
expect # this one works too
in = "a;a;a"
parser = sepBy1 (string "a") (string ";")
out = parseStr parser in
out == Ok (["a", "a", "a"])
expect # this panics... why???
in = "red;green;blue"
parser = sepBy1 parseColor (string ";")
out = parseStr parser in
out == Ok ([Red, Green, Blue])
expect # this works
in = "a"
result = parseStr (string "a") in
result == Ok "a"
expect # ..but this panics
in = "ab"
result = parseStr (string "a") in
result == Ok "a"
Using roc from commit 66fa633fde6cb7067de5303445a8402c15921b3d
(current main), built using the nix flake.
You have string "green" |> map (\_ -> Blue)
, not sure if that is related to the panics though
hahah thanks! good catch. I don't think that should cause the memory error, though.
at least I hope not
it seems to happen whenever I
sepBy
or sepBy1
on a more complicated parser (something with oneOf
or many
)parseStr
on any string that is longer than the expected input (e.g. parseStr (string "a") "ab"
)For me changing it from green to blue did actually fix the error. But I don't think it should be causing one
I ran into the same issue when I was writing my solution
hmm yeah that does fix the "red;green;blue" test I posted
maybe that's enough that I can keep going
but parseStr (string "a") "ab"
still panics
probably a compiler bug, right? I really feel there's no way that line should cause an "out of memory" error
hmm hold on; I'm not sure I can reproduce any more.
My guess either:
Haven't actually looked into what is going, might dig in a bit more if I have time.
I can reproduce it again. It seems to not happen if my expectation is actually correct. Maybe only happens on expectation fail?
expect # this succeeds. perfect
out = parseStr (string "a") "ab"
out == Err (ParsingIncomplete "b")
expect # this panics
out = parseStr (string "a") "ab"
out == Ok "a"
In any case I have 10+ gigs of unused memory, and it fails pretty quickly (doesn't seem like it's slowly eat up all my RAM first)
It also happens inside bumpalo, which seems to be an arena allocator? Sorry I don't know a whole lot about how that works :sweat_smile:
Yeah, my guess is it is an internal compiler buffer that has limited size
In case it's useful, this does not panic
expect # this does not panic
parseStr (string "a") "ab" == Ok "a"
Do you have a full sample that I can just copy into an app.roc
file that is a minimal-ish repro?
here:
app "hello"
packages {
pf: "https://github.com/roc-lang/basic-cli/releases/download/0.7.0/bkGby8jb0tmZYsy2hg1E_B2QrCgcSTxdUlHtETwm5m4.tar.br",
parser: "https://github.com/lukewilliamboswell/roc-parser/releases/download/0.2.0/dJQSsSmorujhiPNIvJKlQoI92RFIG_JQwUfIxZsCSwE.tar.br"
}
imports [
pf.Stdout,
pf.Task.{ Task },
parser.String.{ string, parseStr },
]
provides [main] to pf
expect # this works
out = parseStr (string "a") "ab"
out == Err (ParsingIncomplete "b")
expect # this runs too (but fails)
parseStr (string "a") "ab" == Ok "a"
expect # this panics
out = parseStr (string "a") "ab"
out == Ok "a"
main : Task.Task {} I32
main =
Stdout.line "hi"
What do you mean you can't allocate a string of length: 9223372036854775809
haha
Cool, I know exactly what the bug is actually. (maybe cause I indirectly caused it :shushing_face:)
Should be fixed by #6158
Last updated: Jul 06 2025 at 12:14 UTC