Stream: compiler development

Topic: roc_expect_failed


view this post on Zulip Brendan Hansknecht (Jan 28 2024 at 02:11):

Like roc_dbg we want expect failures to call out to a function in the platform.

view this post on Zulip Brendan Hansknecht (Jan 28 2024 at 02:11):

The current proposed api is:

fn roc_expect_failed(loc: *RocStr, src: *RocStr, variables: *RocList<{name: RocStr, value: RocStr}>)

view this post on Zulip Brendan Hansknecht (Jan 28 2024 at 02:17):

One thing that makes expect less direct than dbg is that we fundamentally only want to run all of the Inspect.toStr calls if the expectation actually failed.

So the final code gen would be something like:

  1. run the conditional if success skip all the following steps
  2. write the cached location to a string
  3. grab the source and write it to a string
  4. For every symbol used by the expect expression:
    1. Write the symbol name to string (hmm, not sure what name would be used for temporaries, maybe just the actual sourced that the symbol references)
    2. Inspect.toStr the intermediate value.
    3. Append that to the variables list for passing to the plaftorm
  5. Call the platform expect function.

I am not sure this will exactly be the easiest thing to pipeline all information around for and code gen for, but feel like it should be relatively reasonable. Any specific considerations around how this should be done? I just kinda feel that if I go and hack this in, it will be messier than I want it to be. Also, I guess I probably need some smart solution to avoid accidentally making IR nodes too large with extra data.

view this post on Zulip Brendan Hansknecht (Jan 28 2024 at 02:19):

So just thought I would throw it up here first and get general opinions. I still currently feel like I never know what level of IR to instrument this kind of stuff at. Cause it feels more complicated then just desugaring, but maybe it is best to just see it as a really large desugaring (hmm...though that probably won't work for top level expects. only for mid function expects).

view this post on Zulip Richard Feldman (Jan 28 2024 at 12:35):

yeah this looks reasonable, but it's only for inline expects - top level expects only get run by roc test, never by the platform

view this post on Zulip Brendan Hansknecht (Jan 28 2024 at 16:33):

I think we should also do this with top level expects and a compiler internal platform when using the roc test. That way we can still remove all the memory sharing infrastructure and just rely on this for all testing.

But yeah, by default, we don't want to generate anything for top level expects.


Last updated: Jul 06 2025 at 12:14 UTC