Stream: beginners

Topic: ✔ Is `generates Effect [apply, ...]` a special code gen?


view this post on Zulip mainrs (Nov 29 2023 at 09:12):

No glue code I have looked at seems to ever implement Effect and its functions. What does each function do?
Besides, even if there is no documentation, writing a platform is actually quite easy. I gave myself 1 hour since I really needed a solution for my problem. And I finished writing the basics of it.

Ah, if Effect is indeed a special case, why isn't it inside of the standard library then?

view this post on Zulip Brian Carroll (Nov 29 2023 at 09:21):

The platform implements the effects, not glue.
The glue code just expresses the Roc types in Rust syntax. The actual call itself is in Roc code.

There's a naming convention where the effect functions on the Rust side begin with roc_fx_ or something like that.

Yes generates is special syntax that platforms use. The Effect type is different for different platforms so it needs special code generation.

view this post on Zulip mainrs (Nov 29 2023 at 09:29):

I am not sure if I understood this correct. So far I have managed to implement my own logging effects. The glue generates the function stubs for each architecture inside the glue. And I just went ahead and implemented the function body. Like here: https://github.com/roc-lang/basic-cli/blob/dee04a8ca735f2431e99631041c7105c3cd6d52e/src/src/lib.rs#L303-L313

However, I am wondering where exactly the Effect type is implemented. In every platform so far it is defined as hosted Effect, which for me indicates it is implemented on the host side: https://github.com/roc-lang/basic-cli/blob/dee04a8ca735f2431e99631041c7105c3cd6d52e/src/Effect.roc#L1

But I could never find an Effect struct or the likes nor could I find its accompanying methods apply, forever etc. on any platform so far.

view this post on Zulip mainrs (Nov 29 2023 at 09:29):

Brian Carroll said:

Yes generates is special syntax that platforms use. The Effect type is different for different platforms so it needs special code generation.

But that code generation is not happening when I call the roc glue command, right?

view this post on Zulip Richard Feldman (Nov 29 2023 at 11:30):

that's correct - we haven't wired that up, partially because we're in the process of changing how that works under the hood (so that what gets sent to Rust is a state machine - happy to elaborate on that if desired!) and at that point we'd be discarding the current system

view this post on Zulip Richard Feldman (Nov 29 2023 at 11:30):

but that change isn't done yet

view this post on Zulip Brian Carroll (Nov 29 2023 at 11:45):

mainrs said:

Brian Carroll said:

Yes generates is special syntax that platforms use. The Effect type is different for different platforms so it needs special code generation.

But that code generation is not happening when I call the roc glue command, right?

That's right, I should have explained it's the compiler doing that particular code generation, not roc glue.

view this post on Zulip Notification Bot (Nov 29 2023 at 12:54):

mainrs has marked this topic as resolved.


Last updated: Jul 06 2025 at 12:14 UTC