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.
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.
Looks like release with profiling still eats most of the stack trace due to inlining.
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.
So may be a case of needing some fix up.
in general the code for backtraces probably has a lot of room for improvement.
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
7 messages were moved here from #ideas > Safe Number calculations by Brendan Hansknecht.
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.
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
Sorry, debug as in without --optimize
Not related to building the compiler itself
Debug of the final app
@Ryan Bates what platform and what os?
@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.
Interesting. Basic CLI for the platform?
@Brendan Hansknecht ah, yes, basic CLI 0.7.0
Also, what does just straight roc program.roc get you?
@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:
$
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
just copied your code into the hellowrold file
@Brendan Hansknecht which nightly build are you on? I'll try the same.
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.
yeah, works for me on commit 9ba7f0f6677
@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.
interesting, maybe roc is consuming the segfault somehow
I think I saw this happening when using --optimize
Some reason there is a segfault in the backtrace library
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.
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.
@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?
Still would be nice to solve for other panics though.
If foo was a bigger function it would show it.
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.
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
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?
First we need to get better debug info, but should be doable in general
currently our debug info is super primitive. Just function regions
Here's a GitHub issue for the stack trace not showing up: https://github.com/roc-lang/roc/issues/6296
@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