Stream: ideas

Topic: Better Backtraces


view this post on Zulip Ryan Bates (Dec 18 2023 at 22:11):

In a similar vein, is there a stack trace when it panics due to number overflow? I didn't see a stack trace last time I ran into this and it made it difficult finding the problem line.

view this post on Zulip Brendan Hansknecht (Dec 18 2023 at 22:16):

With debug builds and the legacy linker it definitely should have a nice stack trace. Now that we have debug function info, optimized builds with profiling might work as well.

view this post on Zulip Brendan Hansknecht (Dec 18 2023 at 22:25):

Looks like release with profiling still eats most of the stack trace due to inlining.

view this post on Zulip Brendan Hansknecht (Dec 18 2023 at 22:26):

Also, there is a change our current code is written for mac function symbol names instead of x86, which may be messing with things. I noticed that it assumes the prefix _, which I think is. a mac only thing.

view this post on Zulip Brendan Hansknecht (Dec 18 2023 at 22:26):

So may be a case of needing some fix up.

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

in general the code for backtraces probably has a lot of room for improvement.

view this post on Zulip Brendan Hansknecht (Dec 18 2023 at 22:28):

Lives here if anyone wants to take a crack at cleaning it up: https://github.com/roc-lang/basic-cli/blob/d11fda1c16683e09fac036a1a062aa5889ae8fab/src/src/lib.rs#L119-L213

view this post on Zulip Notification Bot (Dec 18 2023 at 22:28):

7 messages were moved here from #ideas > Safe Number calculations by Brendan Hansknecht.

view this post on Zulip Ryan Bates (Dec 19 2023 at 00:53):

With debug builds and the legacy linker it definitely should have a nice stack trace

Just to clarify here, do you mean I should be seeing a stack trace in the current nightly build under roc dev and roc test? If so I'll need to check it again.

view this post on Zulip Luke Boswell (Dec 19 2023 at 01:06):

I think debug build refers to building from source without --release, and I am pretty sure the nightlies are built with --release so they would not be debug builds

view this post on Zulip Brendan Hansknecht (Dec 19 2023 at 01:43):

Sorry, debug as in without --optimize

view this post on Zulip Brendan Hansknecht (Dec 19 2023 at 01:44):

Not related to building the compiler itself

view this post on Zulip Brendan Hansknecht (Dec 19 2023 at 01:44):

Debug of the final app

view this post on Zulip Brendan Hansknecht (Dec 19 2023 at 01:45):

@Ryan Bates what platform and what os?

view this post on Zulip Ryan Bates (Dec 19 2023 at 04:47):

@Brendan Hansknecht I'm on Mac OS X 14.1.2 M3 chip, nightly build 9ba7f0f6677 from Dec 15. I can try another nightly build if you like.

I just tested it again and when I run roc dev the error says Here is the call stack that led to the crash: but nothing is shown after that. When I run roc test it doesn't show that message, just Integer multiplication overflowed!. I can provide code if you need.

view this post on Zulip Brendan Hansknecht (Dec 19 2023 at 04:48):

Interesting. Basic CLI for the platform?

view this post on Zulip Ryan Bates (Dec 19 2023 at 04:48):

@Brendan Hansknecht ah, yes, basic CLI 0.7.0

view this post on Zulip Brendan Hansknecht (Dec 19 2023 at 04:48):

Also, what does just straight roc program.roc get you?

view this post on Zulip Ryan Bates (Dec 19 2023 at 04:53):

@Brendan Hansknecht same thing. Here's some code.

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

main =
    Stdout.line (Num.toStr (foo 0u64))

foo = \num ->
    num - 123
$ roc foo.roc
Roc crashed with:

    Integer subtraction overflowed!

Here is the call stack that led to the crash:

$

view this post on Zulip Brendan Hansknecht (Dec 19 2023 at 04:54):

Interesting. I wonder why it works on m1 for me:

roc run examples/helloWorld.roc
Roc crashed with:

    Integer subtraction overflowed!

Here is the call stack that led to the crash:

    roc.panic
    throw.on
    Num.sub
    app.main
    rust.main

view this post on Zulip Brendan Hansknecht (Dec 19 2023 at 04:55):

just copied your code into the hellowrold file

view this post on Zulip Ryan Bates (Dec 19 2023 at 04:55):

@Brendan Hansknecht which nightly build are you on? I'll try the same.

view this post on Zulip Brendan Hansknecht (Dec 19 2023 at 04:57):

I always build from source, but my latest commit is looks to be a tiny bit later than yours. Some time later in the day on the 15th after the nightly was cut. That said, none of the commits look relevant to this.

view this post on Zulip Brendan Hansknecht (Dec 19 2023 at 04:58):

yeah, works for me on commit 9ba7f0f6677

view this post on Zulip Ryan Bates (Dec 19 2023 at 04:58):

@Brendan Hansknecht interestingly, if I do roc run foo.roc I get the same output as I did before (without the stack trace) but this line at the end zsh: segmentation fault roc run foo.roc. That line doesn't show up with roc dev foo.roc or roc foo.roc.

view this post on Zulip Brendan Hansknecht (Dec 19 2023 at 04:58):

interesting, maybe roc is consuming the segfault somehow

view this post on Zulip Brendan Hansknecht (Dec 19 2023 at 04:58):

I think I saw this happening when using --optimize

view this post on Zulip Brendan Hansknecht (Dec 19 2023 at 04:59):

Some reason there is a segfault in the backtrace library

view this post on Zulip Brendan Hansknecht (Dec 19 2023 at 05:00):

maybe you hit the segfault in debug for some reason. I don't really know how the backtrace library works, so not sure why it is segfaulting currently.

view this post on Zulip Ryan Bates (Dec 19 2023 at 05:00):

Would it be a difference between M1 and M3? Anyone else with an M3 chip able to try?

Specifically I'm on an M3 Max MBP.

view this post on Zulip Ryan Bates (Dec 19 2023 at 05:03):

@Brendan Hansknecht I'm not sure how useful the stack trace is here since it looks like the stack is within Rust and not Roc (I see no mention of foo). Does Roc even keep a stack trace?

view this post on Zulip Ryan Bates (Dec 19 2023 at 05:03):

Still would be nice to solve for other panics though.

view this post on Zulip Brendan Hansknecht (Dec 19 2023 at 05:06):

If foo was a bigger function it would show it.

view this post on Zulip Brendan Hansknecht (Dec 19 2023 at 05:06):

The issue is that foo only contains a call to Num.sub and I think that overwrites the debug info (we might also not have it fully set up right.

view this post on Zulip Brendan Hansknecht (Dec 19 2023 at 05:07):

changing foo to this:

foo = \num ->
    x = 123
    dbg x
    num - x

cause the trace to be this for me:

    throw.on
    Num.sub
    app.foo
    app.main

view this post on Zulip Ryan Bates (Dec 19 2023 at 05:07):

Nice, that would help a lot solving overflow bugs.

Since we're on the topic of better backtraces, any chance of getting line numbers in that?

view this post on Zulip Brendan Hansknecht (Dec 19 2023 at 05:08):

First we need to get better debug info, but should be doable in general

view this post on Zulip Brendan Hansknecht (Dec 19 2023 at 05:08):

currently our debug info is super primitive. Just function regions

view this post on Zulip Ryan Bates (Dec 19 2023 at 20:28):

Here's a GitHub issue for the stack trace not showing up: https://github.com/roc-lang/roc/issues/6296

view this post on Zulip Ryan Bates (Dec 19 2023 at 22:13):

@Brendan Hansknecht Looks like no stack traces are showing up on M1 here: https://github.com/roc-lang/roc/issues/6295#issuecomment-1863495663

When you tested it on your end, did you build it from source? Maybe a difference between how nightly builds are done. Can you test a nightly build?


Last updated: Jun 16 2026 at 16:19 UTC