Stream: beginners

Topic: Unexpected behavior


view this post on Zulip Isaac Van Doren (Oct 01 2023 at 20:40):

This program terminates without printing or panicking or anything. I would have expected it to hang. The weird thing is that if I remove either of the unused record fields it hangs as expected. Any idea what's going on here? I'm using roc nightly pre-release, built from commit e91b50a on Sat Sep 23 09:15:02 UTC 2023 on apple silicon.

app "main"
    packages { pf: "https://github.com/roc-lang/basic-cli/releases/download/0.5.0/Cufzl36_SnJ4QbOoEmiJ5dIpUxBvdB3NEySvuH82Wio.tar.br"}
    imports [pf.Stdout]
    provides [main] to pf

main =
    _ = func {
        val: "foo",
        index: 0,
        result: 0
    }
    Stdout.line "the end"

func = \r -> func { r & index: r.index }

view this post on Zulip Brendan Hansknecht (Oct 01 2023 at 21:38):

Just stack overflows?

view this post on Zulip Brendan Hansknecht (Oct 01 2023 at 21:38):

Also, optimized or dev build if the app?

view this post on Zulip Brendan Hansknecht (Oct 01 2023 at 21:45):

hmm...program segfaults for me on apple silicon. Still not great. But it is just an infinite recursive loop. Funiliy enough, it breaks morphic when trying to optimize

view this post on Zulip Brendan Hansknecht (Oct 01 2023 at 21:49):

Just curious, was there a goal with this function?

view this post on Zulip Brendan Hansknecht (Oct 01 2023 at 21:52):

Also the reason the function works when you comment out val is because it no longer has a Str. Str potentally cause memory allocations and llvm's reasoning falls over. Without val, it realizes that there is nothing to do and just creates an infinite jump cycle.

view this post on Zulip Brendan Hansknecht (Oct 01 2023 at 21:54):

Should still be an infinite loop either way (both that should tail recurse and not stack overflow), but somehow is hitting another issues. I guess when copying data around.

view this post on Zulip Isaac Van Doren (Oct 02 2023 at 00:37):

Ah yeah I stack overflow makes sense. Is there a clear way to tell when a roc program has stack overflowed? I assumed there would be some kind of error message but I see now that that may not be the case.

I was just using roc main.roc. Also, is that the equivalent to roc dev main.roc?

I was writing a parser for a little stack based language and I accidentally made an infinite recursion but then couldn't figure out why it crashed instantly instead of hanging. The example I showed is pretty much just the smallest example I could come to that had the same behavior.

Also the reason the function works when you comment out val is because it no longer has a Str.

It also hangs if I comment out result but leave val in. Do you have a guess why that would be given that it still contains the Str? Maybe the record update is causing some issue? It behaves as expected if I just pass in r instead of (pointlessly) updating r.

view this post on Zulip Brendan Hansknecht (Oct 02 2023 at 00:52):

To be clear, I think this is hitting a weird compiler bug related to copying around data cause it can segfault too. It actually should be tail recursive and just hang without ever stack overflowing either.

view this post on Zulip Brendan Hansknecht (Oct 02 2023 at 00:54):

Also, really strange, that removing result also fixes it. Something funky is going on with types and copying around data. Maybe an alignment issue. I am going to file an issue. All of these should just hang forever (not a great results, but the correct behavior currently).

view this post on Zulip Isaac Van Doren (Oct 02 2023 at 00:56):

Okay cool, sounds good!

view this post on Zulip Brendan Hansknecht (Oct 02 2023 at 00:58):

Filed: #5874


Last updated: Jul 06 2025 at 12:14 UTC