Stream: beginners

Topic: very annoying crash


view this post on Zulip Artur Swiderski (Nov 21 2023 at 18:46):

Commit "crash section line 240 - 244"
18b860962c077031007f96150f6367787bb194d0
in file https://github.com/salarii/peek/blob/main/regex.roc

this crash is very annoying because unlike in other cases I can't figure out ways around it : ( . I have to uncomment for now

view this post on Zulip Anton (Nov 22 2023 at 10:04):

I'll try to take a look today

view this post on Zulip Artur Swiderski (Nov 22 2023 at 14:24):

this commit 37f0e9be0b014590b346cc75b6642938b352d78b also crash
It is vicious because it does not inform even that it is crashing, and it is unrelated to previous issue

view this post on Zulip Anton (Nov 22 2023 at 17:34):

I won't be able to look at this today or tomorrow, is someone else able to help out?

view this post on Zulip Brendan Hansknecht (Nov 22 2023 at 18:27):

I wanted to look but didn't get to it and will be travelling. Not sure I'll get a chance.

view this post on Zulip Luke Boswell (Nov 22 2023 at 20:49):

I haven't found the issue causing this segfault yet.

But I do have some tips which I find help me with these kind of issues.

  1. I like to use type annotations it help the compiler to check the types are what I expect at various points. Even just top level definitions is really helpful, and significantly improves the error messages.
  2. I like to unit tests for my functions using expect
  3. I find using roc check and working through to resolve all the warnings oftens helps lead me to a place where I see an issue.

view this post on Zulip Luke Boswell (Nov 22 2023 at 20:49):

The current implementation of dbg has been a common cause of bugs. It will soon be replaced with the Inspect ability which will significantly improve dbg stability I think.

view this post on Zulip Luke Boswell (Nov 22 2023 at 21:08):

In the below snippet you are using the Character tag in two different ways, one without a payload and one with.

getRegexTokens = \result ->
    when result.tag is
        Character ->
            when List.first result.parsedResult.matched is
                Ok matched ->
                    Ok [createToken (Character matched) Once Bool.false]

                Err _ -> Err "character  tag problem"

        _ ->
            Err "wrong tag"

view this post on Zulip Luke Boswell (Nov 22 2023 at 21:28):

I'm finding it difficult to follow the types through this. I've spent some time adding annotations and looking at this, but it is a pretty big and complex.

I would love to find the segfault, but I probably should move on to other things.

If you have the time and are able add more type annotations, I think you could narrow this issue down, and it would be really helpful to make an issue with a minimal reproduction of the segfault. Just keep removing code until you have a minimal example.

view this post on Zulip Artur Swiderski (Nov 22 2023 at 23:14):

sorry I knew where bug was I spotted it myself but I was complaining that that application does not report crash or anything was it ok ?

view this post on Zulip Artur Swiderski (Nov 22 2023 at 23:17):

clearly I made mistake but that wasn't the point , I did not expect compiler to show just nothing as it is and I was reporting that

view this post on Zulip Artur Swiderski (Nov 22 2023 at 23:23):

regarding type annotation good and bad point at the same time, usually I don't know what I want, so I let compiler to decide, additionally I do not have skill to add proper types anyway. Still compiler should do it's work and provide some feedback about crash or some discrepancies.

view this post on Zulip Artur Swiderski (Nov 22 2023 at 23:27):

beside that, some types, I am using are complex and to write them down it would be painful , and I am grateful I don't have to

view this post on Zulip Elias Mulhall (Nov 22 2023 at 23:27):

You might find out helpful to use roc check until there are 0 reported errors, and only then use roc run. Roc will still try to run your code when there are issues, but if it runs into one of the invalid code paths it will crash. Right now that crash message is not helpful.

view this post on Zulip Artur Swiderski (Nov 22 2023 at 23:28):

I was using run dev , I expect it to show something

view this post on Zulip Artur Swiderski (Nov 22 2023 at 23:28):

because it usually does but not this time

view this post on Zulip Artur Swiderski (Nov 22 2023 at 23:32):

sorry I messed up completely I was talking about second problem :joy:
Thx for tips for first problem :sweat_smile:

view this post on Zulip Luke Boswell (Nov 22 2023 at 23:34):

Sorry, I should have mentioned this additional context. I misunderstood your original question.

It looks like you have found a compiler bug. The issue you are seeing is that the executable that is generated is invalid, and when executed it segfaults on your machine.

You are not seeing a nice error message because it is not caused by a roc crash or rust panic.

This is certainly a bug in the compiler.

As Roc is still young and maturing, it is unfortunately still easy to run into these issues.

In future these will be really uncommon as the compiler is battle tested against lots of different kinds of programs. To help us get there, it is really helpful when you find an issue like this to report it. This way it can be fixed, and a test added to prevent future regressions.

view this post on Zulip Artur Swiderski (Nov 22 2023 at 23:44):

to be clear first issue I haven't solved yet <--- your tips for that is to annotate more ??
second reported issue <--- this is easy , just reported that compiler is silent

type annotations may help me solve first one?

The problem is that when I narrowed down a bit problematic code it seemed to work only together it seems to fail.

btw. it is true. In this specific code I am using sometimes the same tag by name in different context without warning.


Last updated: Jul 06 2025 at 12:14 UTC