What is currently the recommended approach to look at what IR is being generated by a particular Roc program or function?
with environment variables, like this
ROC_PRINT_IR_AFTER_RESET_REUSE=1 cargo test-gen-dev gen_primitives::nested_switch -- --nocapture
there are a couple other stages at which we can print the IR, search for ROC_PRINT_IR
do you mean llvm ir? Or other?
I was mainly asking for the Roc IR (for which Folkert's answer works nicely), but I'm definitely also interested in how to print the LLVM IR. :blush:
--debug
flag
I'm on an M1 mac. Passing the --debug
flag creates a nice .ll
file with LLVM IR. But it also creates the error message
An internal compiler expectation was broken.
This is definitely a compiler bug.
Please file an issue here: https://github.com/roc-lang/roc/issues/new/choose
thread 'main' panicked at 'I could not find the `debugir` tool on the PATH, install it from https://github.com/vaivaswatha/debugir', crates/compiler/build/src/program.rs:387:44
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
I've tried installing debugir
but it seems we're now on a different LLVM version than debugir
expects or something?
hmm yeah you may need to build it from source and give it the llvm version that you want. although, if it works it works
the error seems to be about something very different though?
The error only appears when adding the --debug
flag to a call to roc build
Folkert de Vries said:
hmm yeah you may need to build it from source and give it the llvm version that you want. although, if it works it works
Ok, I'll try to do that
fwiw I use nix develop
when working on Roc stuff, and it Just Works for me there
if you use nix you can load the flake in the compiler repo which should give you the right debugir. But if you only care about the llvm or without debugir on top you can ignore the error entirely. There is nothing meaningful that happens after we attempt to run debugir that differs from a normal build
to use ROC_PRINT_IR_* you will need to build a debug version of the compiler anyway
Richard Feldman said:
fwiw I use
nix develop
when working on Roc stuff, and it Just Works for me there
Aaah! Nice! Yes, that works! :happy:
Last updated: Jul 06 2025 at 12:14 UTC