Stream: compiler development

Topic: snapshot testing experience


view this post on Zulip Prokop Randacek (Apr 15 2026 at 13:20):

Hi! :D i noticed that roc is using snapshot tests that verbatim compare the IR against the golden file snapshot. this is unlike what is done in gcc and llvm where they have patterns instead of literal outputs and do pattern matching instead of byte for byte comparisons.

Was this deliberate decision? i hear that not doing patterns results in too britle test suites. what is the experience from doing this in roc?

im asking because im doing a similar decision in a different compiler and im curious :D

view this post on Zulip Anton (Apr 15 2026 at 14:08):

i hear that not doing patterns results in too britle test suites. what is the experience from doing this in roc?

The experience has been good for me, I rarely need to check more than a few snapshots for a PR but that may just be the case for the things I tend to work on.

view this post on Zulip Anton (Apr 15 2026 at 14:09):

If you check the edit dates of the folders in https://github.com/roc-lang/roc/tree/main/test/snapshots you see that they do not change that often.

view this post on Zulip Norbert Hajagos (Apr 16 2026 at 09:44):

There was (is?) also a plan to output snapshots in the form of valid roc source code, for the first couple of IRs that could be represented this way. You've mentioned gcc and LLVM. I think this can work for us, since we're not writing a backend with multiple optimizing passes which cannot be represented with source code. We have more IRs that can be repr as Roc. Though maybe if your language has lower level primitives, like goto, you can go quiet far with this approach. The last one of our IRs would have these properties when printed out as roc source code (among others):

tmp0=1
tmp1=2
tmp2=U8.times(tmp0, tmp1)
tmp3=3
result=U8.plus(tmp2,tmp3)

view this post on Zulip Norbert Hajagos (Apr 16 2026 at 09:49):

I don't contribute that much, but I didn't find them brittle when working with them. I would have preferred this approach back then though, since reading roc source code is easyer than ir dumps.

view this post on Zulip Norbert Hajagos (Apr 16 2026 at 12:18):

idk what's the term for this

It's "A-normal form"


Last updated: May 01 2026 at 12:45 UTC