so Folkert and I were talking about the neverending source of bugs and safety that is trying to correctly implement the C ABI for host-exposed functions, and we ended up deciding to make this change:
_generic
version does today)this means that the amount of time we spend messing around with C ABI problems immediately goes to zero and stays there
the downside is that it's some amount less efficient than using the C ABI
given the (very small) magnitude of that performance delta, and the (very large) magnitude of the (implementation cost + bugs everyone has to deal with until we sort them out) delta, maybe someday it will seem like a reasonable project to implement the whole C ABI, but for now this seems like a better tradeoff all around
oh, and of course glue can take care of generating these calls anyway, and wrap them in something that looks appropriate for the native host language
I know I am thinking at least medium term here, but once we get the async state machine where everything is returned via main, won't a lot of this pain go away. No more arbitrary function calling. Just one single tag union return from main.
Also, this idea is probably mostly ok if the data is stack allocated. Given io is a boundary it probably isn't called "too" much.
Plus will probably help unlock new platforms, and more language glue wrappers faster, which is a huge boon
I know this is a little off-topic, and may be obvious... but if I have something like a List U8
in the return struct does it need to have a predetermined size? Or would I simply give it an initialised empty list (like now), and roc_alloc would assign more memory if needed?
Does this decision help with the unknown size problem that was not yet resolved?
I'm essentially certain the caller would just allocate the size of the list pointer, size, and capacity. It would not care about any of the actual data in the list or its size. So you would just give the roc function 24 bytes of stack space. Roc would allocate the list and fill in those 24 bytes. After that, the host can access the list.
I don't think you should even initialize the list. Just give it uninitialized bytes for roc to store the initialized list in later.
Last updated: Jul 06 2025 at 12:14 UTC