Hi! Trying my hand at writing a platform, based on the existing examples. Even with the simplest example, I run into a compiler panic and can't figure out what's wrong.
The setup is simple: export a sayHello
function from Rust (well, roc_fx_sayHello
) that returns a RocStr
, and wrap it in a nice File.sayHello
interface for platform users. Then, simply call it from main.
The error I get:
thread '<unnamed>' panicked at 'invalid content in tag union variable: (113, Structure(Apply(`3.IdentId(0)`, SubsSlice { start: 50, length: 0 })))', compiler/mono/src/layout.rs:1776:23
It seems related to the use of Effect.sayHello
, since the error goes away if I just use a regular Roc function in File.sayHello
Here's a repo with my code: https://github.com/erwinkn/advent-of-code-2021
(yes I'm catching up on AoC and yes I got sidetracked into writing a platform :joy: )
in the package config sayHello : {} -> Str
must be sayHello : {} -> Effect Str
functions from the platform must always return an Effect
(to roc)
no changes are needed on the rust side
OK, got it! I'll have to propagate the Effect
to main
to File.sayHello
and main
then I guess
exactly. That's required for purity: your rust code could do whatever sideeffects, and we have to manage that on the roc side somehow
On that note, is there any documentation somewhere regarding the difference in the Rust functions exposed in the hello-X
examples (where only roc_main
is exposed in the "linked" block) vs other examples like the CLI platform, where you also have roc_main_size
, call_Fx
, size_Fx
and size_Fx_Result
?
no, that is still very unstable. Right now host-exposed functions get a _size
constant, and aliases defined in its signature also get a bunch of size constants and if it's a closure type it also gets a caller
but, the best place to learn about that right now is looking at that working code. We will be changing things there in the future
So, I should probably copy / paste the code from the CLI platform, to make sure the size constants and callers are handled correctly?
that's a good starting point, yes
Alright, thanks!
Last thing: would there be an interest in a documented platform example, kinda like a "platform author starter pack"? Basically one of the existing examples, with comments to explain what's happening, what is compiler boilerplate and where your code should go
Or is it too early for this?
it is early, and it will change. But it could be helpful right now, and show us where the current approach is lacking
I'd be interested in writing this, to learn myself! I'll crosspost this in #ideas
Last updated: Jul 06 2025 at 12:14 UTC