Hi! I have a particular problem and a more general question.
I'm looking at issue #6041 to help get a sense of the problems Rust glue is running into. After some prodding, it seems that in the sixteen-variant case, the Roc CLI describes IOError as an Enumeration
tag union, whereas it describes the seventeen-variant case as a NonRecursive
tag union. This could mean that either the Roc compiler is reporting the wrong shape, or that Roc is performing some kind of optimization in the representation for tag unions I'm not aware of.
More generally, I'd be curious if there's some documentation I could read on how tag unions get represented in memory?
@Brendan Hansknecht @Folkert de Vries
16 is suspecious. are we off by one? in the bottom 3 bits we can store 8 variants, and 16 being one more power of two is a clue maybe?
Given there's no payload in any of the variants, I'd expect one byte to be sufficient for a 256-tag union right?
ok, what is happening I think is that [A, B, C]
is represented just as an integer
right, but the 17-variant one must have a payload somewhere then?
Not according to the Roc code
IOError : [
NotFound,
PermissionDenied,
ConnectionRefused,
ConnectionReset,
HostUnreachable,
NetworkUnreachable,
ConnectionAborted,
NotConnected,
AddrInUse,
AddrNotAvailable,
NetworkDown,
BrokenPipe,
AlreadyExists,
WouldBlock,
NotADirectory,
IsADirectory,
DirectoryNotEmpty, # comment out and glue generates correctly
]
ok
well, internally we only have NonRecursive
, an Enumeration
is not a thing in the IR, so that must be something that glue determines
I see
I'm inclined to think this is a bug in the glue part of the compiler then?
I think enumeration is something Richard added for non recursive tags that have no payload
Should just be a simple check, but could have a bug for sure.
Is this documented anywhere? Or is there someone who has a complete picture on this?
"this" being, the in-memory representation of tag unions
see fn add_int_enumeration(
and its usages
it does not perform any sophisticated transformation though, so the 16/17 values difference might be something deeper
so this would require some (dbg!
) debugging
Last updated: Jul 06 2025 at 12:14 UTC