Stream: beginners

Topic: How to look at the generated IR?


view this post on Zulip Qqwy / Marten (Jul 22 2023 at 10:40):

What is currently the recommended approach to look at what IR is being generated by a particular Roc program or function?

view this post on Zulip Folkert de Vries (Jul 22 2023 at 10:49):

with environment variables, like this

ROC_PRINT_IR_AFTER_RESET_REUSE=1 cargo test-gen-dev gen_primitives::nested_switch -- --nocapture

view this post on Zulip Folkert de Vries (Jul 22 2023 at 10:49):

there are a couple other stages at which we can print the IR, search for ROC_PRINT_IR

view this post on Zulip Richard Feldman (Jul 22 2023 at 12:18):

do you mean llvm ir? Or other?

view this post on Zulip Qqwy / Marten (Jul 22 2023 at 13:09):

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:

view this post on Zulip Folkert de Vries (Jul 22 2023 at 13:12):

--debug flag

view this post on Zulip Qqwy / Marten (Jul 22 2023 at 13:51):

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?

view this post on Zulip Folkert de Vries (Jul 22 2023 at 13:53):

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

view this post on Zulip Folkert de Vries (Jul 22 2023 at 13:53):

the error seems to be about something very different though?

view this post on Zulip Qqwy / Marten (Jul 22 2023 at 14:35):

The error only appears when adding the --debug flag to a call to roc build

view this post on Zulip Qqwy / Marten (Jul 22 2023 at 14:35):

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

view this post on Zulip Richard Feldman (Jul 22 2023 at 14:50):

fwiw I use nix develop when working on Roc stuff, and it Just Works for me there

view this post on Zulip Ayaz Hafiz (Jul 22 2023 at 14:51):

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

view this post on Zulip Ayaz Hafiz (Jul 22 2023 at 14:52):

to use ROC_PRINT_IR_* you will need to build a debug version of the compiler anyway

view this post on Zulip Qqwy / Marten (Jul 22 2023 at 14:53):

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