Stream: beginners

Topic: Compiler stack overflow on recursive parser


view this post on Zulip Agus Zubiaga (Jul 19 2023 at 23:17):

I started to write a parser using the modules in the parser example, and everything worked fine until I wanted to write a recursive parser. I used lazy to avoid the cyclic reference like I would with elm/parser and roc check returned 0 errors. However, when I run my tests, the compiler seems to stack overflow.

Is this a known bug?

view this post on Zulip Agus Zubiaga (Jul 19 2023 at 23:22):

Here's the parser source

view this post on Zulip Agus Zubiaga (Jul 19 2023 at 23:26):

Weirdly, if I remove the parser type annotations, I get a different error instead of the stack overflow:

An internal compiler expectation was broken.
This is definitely a compiler bug.
Please file an issue here: https://github.com/roc-lang/roc/issues/new/choose
thread '<unnamed>' panicked at 'I thought a non-nullable-unwrapped variant for a lambda set was impossible: how could such a lambda set be created without a base case?', crates/compiler/mono/src/layout.rs:1711:61
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

view this post on Zulip Ayaz Hafiz (Jul 20 2023 at 02:18):

I know we have lots of bugs around recursive types, but I don't know if this one is unique. It probably is; if you can minimize it, can you make an issue Agus? Even if you can't minimize it, capturing a reference to the program for later would be helpful

view this post on Zulip Ayaz Hafiz (Jul 20 2023 at 02:18):

The second is a known issue. I don't currently know of a good path forward there, but what the problem is is well known

view this post on Zulip Agus Zubiaga (Jul 20 2023 at 10:24):

Sounds good. I'll try to minimize it as much as possible and will open an issue later.

view this post on Zulip Agus Zubiaga (Jul 20 2023 at 13:52):

https://github.com/roc-lang/roc/issues/5682

view this post on Zulip Agus Zubiaga (Jul 20 2023 at 13:53):

I think I boiled it down quite a bit while keeping context

view this post on Zulip Agus Zubiaga (Jul 20 2023 at 13:54):

If that's not enough, let me know and I'll try to make a more abstract reproduction without any of the parser stuff

view this post on Zulip Ayaz Hafiz (Jul 20 2023 at 13:57):

Thanks! Is it possible to get rid of the basic cli dependency and reproduce the bug only in expects? (basic-cli is a pretty big dependency.) And, are all of the expects in your example program necessary to reproduce the issue?

view this post on Zulip Agus Zubiaga (Jul 20 2023 at 14:00):

Good point. I started with app because I initially had all the actual parser logic but now that I don't, we don't need that. I will just make an interface.

view this post on Zulip Agus Zubiaga (Jul 20 2023 at 14:02):

Updated!

view this post on Zulip Ayaz Hafiz (Jul 20 2023 at 14:03):

thanks!

view this post on Zulip Agus Zubiaga (Jul 20 2023 at 14:32):

Added the abstract example which reproduces this in only a few lines. It would never make sense to run because there's no exit condition, but I think roc should still compile it.

view this post on Zulip Agus Zubiaga (Jul 22 2023 at 21:50):

Ha. Found a workaround! Just gotta rewrap the Parser.


Last updated: Jul 05 2025 at 12:14 UTC