Is there a way to build roc and keeping the dbg statements?
What I am trying to do is building an app with an go platform. The only way I know to do this, is building roc with roc build --no-link --output=host.o
and then give the build host.o to go. But this binary object does not call dbg.
If this is currently not possible, is this something worth adding? For example an build argument like roc build --with-dbg
?
I'm in favor of keeping dbg
statements by default and only discarding them when the --optimize
flag is used.
We want to do that. Just hasn't been fixed yet
Dbg is at least partially tied to expect. So the plan was update expect to also be a platform required function. (Currently expect is still stuck depending on the roc compiler in a way that stops it from being added to the build output). Then change the defaults.
That is good to know (with the hope of a higher priority :sweat_smile:)
I am looking though the code. Here is the function, that decides if dbg statements are included: https://github.com/roc-lang/roc/blob/c63b6ca507fd401a94bde083c764e05054d9de08/crates/compiler/gen_llvm/src/llvm/build.rs#L721
Currently, there are only the modes Binary
and BinaryDev
(and other, that are not related). Would this mean, that a new mode BinaryOptimize
has to be added?
For the llvm backend, I'm pretty sure binary is optimized and binary dev is non-optimized. It is unrelated to the dev backend.
I can only speak for my usecase. It seems, that go build --no-link
uses the llvm backend. When I change the line LlvmBackendMode::Binary => false,
to LlvmBackendMode::Binary => true,
, then dbg works.
Hmm...maybe optimize is a sub flag on binary.... anyway. Though that will work, if someone has an expect it will also generate. Which will break
I will try this
You are right. When I compile with the llvm backend, with the patch that includes dbg
and expect
, and the code contains a failing expect, then I get an error like this:
Bus error at address 0x7f8d84efd000
???:?:?: 0x55b56bebd17f in ??? (???)
Unwind error at address `:0x55b56bebd17f` (error.AddressOutOfRange), trace may be incomplete
/zig/0.11.0/files/lib/std/fmt.zig:1995:39: 0x55b56be32205 in bufPrint__anon_4972 (host)
var fbs = std.io.fixedBufferStream(buf);
^
Abgebrochen (Speicherabzug geschrieben)
This is from a zig-platform and not the go-platform.
I don't understand why expect does not work with llvm? I would think, that it calls the same C-functions then the dev-backend.
A few things are conflated here:
--dev
.roc_dbg
Some context on what needs to be done is in #compiler development > roc_expect_failed
Ahh. Ok. I understand. So for the moment, I do not use inline expects, use a patched roc binary, and hope, that someone finds the time to update the expect
statement.
Yeah, that works.
Last updated: Jul 06 2025 at 12:14 UTC