Stream: beginners

Topic: panic on recursive tasks


view this post on Zulip dank (Mar 06 2023 at 12:47):

so I wrote some weird code which I tend to believe isn't sound to begin with, something along these lines

test = \x ->
  if x == 0 then
    Stdout.line "done"
  else
    _ <- Stdout.line "going down" |> Task.await
    test (x-1)

main = test 6

so my questions are firstly should this theoretically work?
if so then what is the correct form to represent it (bear in mind it has to be recursive for the actual code)
and lastly the error that comes out of it is odd. it's like a big ast dump

thread 'main' panicked at 'internal error: entered unreachable code: symbol/layout `17.IdentId(48)` ProcLayout {
    arguments: [
        Struct {
            hash: FieldOrderHash(
                0,
# like a 1000 more lines of this

view this post on Zulip Richard Feldman (Mar 06 2023 at 13:50):

theoretically I'd expect this to work!

view this post on Zulip dank (Mar 06 2023 at 13:54):

damn i kinda hoped not (so that there'd be an obvious way to make it work) lol

view this post on Zulip Ayaz Hafiz (Mar 06 2023 at 13:55):

I thought I fixed this a couple weeks ago. Could you cut a minimal reproduction and file an issue please?

view this post on Zulip dank (Mar 06 2023 at 13:56):

sure, be up in a couple minutes

up

view this post on Zulip dank (Mar 06 2023 at 19:35):

Ayaz Hafiz said:

I thought I fixed this a couple weeks ago. Could you cut a minimal reproduction and file an issue please?

do you know where this panic originates? i would be interested in reading the source on this

view this post on Zulip Ayaz Hafiz (Mar 06 2023 at 20:11):

Sure, the exact source of the panic is here: https://github.com/roc-lang/roc/blob/e1719b6fe28d8ceff61ca9ef45d68d012087987e/crates/compiler/mono/src/borrow.rs#L196-L199

view this post on Zulip Ayaz Hafiz (Mar 06 2023 at 20:13):

However that will not really help much. The problem is that the compiler is looking for a specific specialization of the task function (Roc monomorphizes all user code) that wasn't actually produced. The process of specialization happens in this massive file. The reasons why this might happen are varying and historically aren't for any one particular reason.

view this post on Zulip dank (Mar 06 2023 at 20:40):

im gonna need some more braincells for this
thanks

view this post on Zulip Ayaz Hafiz (Mar 06 2023 at 20:40):

If you want, feel free to DM me and we can talk through some of it


Last updated: Jul 05 2025 at 12:14 UTC