hey, just trying to read some tagged unions (these: https://github.com/rtfeldman/rbt/blob/f6fb63e103147e795d7187b8d1a76842354f3c35/Rbt.roc) out of Roc using Rust and having some difficulties, specifically getting some segfaults. Y'all got any tips on how to read the memory for tags? Here's what I'm working with now: https://github.com/rtfeldman/rbt/blob/2c9337212cc59a05814f88e5adfa869ba86c2cf9/src/lib.rs
Also, there has to be a better way to debug this than to try things blindly—what is it? I know I could make a lot more progress if I knew how to enter a debugger or at least dump the memory to stdout somehow. Surely options exist and I'm just unaware of them. Someone enlighten me so I can get off your lawn. :laughing:
getting tagged unions out of roc into rust or anything will be tricky. There are a lot of ways that we can represent those compactly (e.g. just a number if none of the tags have payloads as a simple example)
looks like you actually just want to pass records though?
then what's important is that roc sorts fields first by alignment, and then alphabetically. That has to be mirrored on the rust side to have things line up
thing is, eventually Tool will need to depend on Job, creating a loop. If I understand that correctly, it means that all the records will need to exist in a single union. Is that right? So even though I’m currently just making private records, I think it will have to change
so I think I'd need to do this:
RbtObj : [ InternalJob { command : RbtObj, ... }, InternalCommand { tool : RbtObj }, InternalTool { ..., from : RbtObj } ]
Job : [ @Job RbtObj ]
Command : [ @Command RbtObj ]
Tool : [ @Tool RbtObj ]
Does that seem right? I don't like that it loses type safety, but I don't know that there's a cleaner way to resolve the cycle between the type aliases that it creates. Then I'm gonna have to unwrap two levels of tags here.
@Folkert de Vries any advice here?
I don't think this is needed. What sort of functions would you want to write for the host <-> roc communication?
or rather, what are their signatures
In this host, the Roc code just provides data for the platform to use. It’s for build specification.
I wasn’t planning on exposing any functions at all
There will be a separate discovery platform that will though
Last updated: Jul 05 2025 at 12:14 UTC