Stream: ideas

Topic: Save the builtins in the Roc cache


view this post on Zulip Sam Mohr (Feb 07 2025 at 22:35):

In the new compiler, it would be nice to treat the builtin modules as close to normal modules as possible to make compiling them simpler. One way to do that would be to save builtins into the Roc cache per Roc version, something like ~/.cache/roc/builtins/<version>/List.roc,Num.roc,etc.. This would pair with us saving results of a compiled file based on its hash and Roc version, meaning we don't need a special compiler pass that compiles builtins during compilation of our compiler. More valuable though would be builtins being available for "go to definition" for the LSP.

view this post on Zulip Sam Mohr (Feb 07 2025 at 22:36):

I'm not confident that we'll be able to make caching of builtin compilation work, but the LSP integration makes this seem worth it even without that.

view this post on Zulip Sam Mohr (Feb 07 2025 at 22:37):

We'd want to expose an archive of the builtins for each Roc version, I don't think we'd want to embed the builtins in the compiler or something like that.

view this post on Zulip Isaac Van Doren (Feb 07 2025 at 22:59):

We'd want to expose an archive of the builtins for each Roc version, I don't think we'd want to embed the builtins in the compiler or something like that.

Are you thinking there would be a separate folder that you would need to download when installing the compiler that would contain the builtins? Or that roc would download them at compile time like it does with platforms? I very much like that you only need the roc executable and nothing else.

view this post on Zulip Isaac Van Doren (Feb 07 2025 at 23:00):

Downloading them like is done with platforms might be fine, but it feels a bit strange that a freshly downloaded compiler wouldn't actually be able to run any programs without first downloading more things

view this post on Zulip Sam Mohr (Feb 07 2025 at 23:01):

In which case, it's probably best to include an archive in the compiler binary.

view this post on Zulip Sam Mohr (Feb 07 2025 at 23:02):

Which would incur a compilation cost on the first compilation, but it should be within like a millisecond or two, which I think is a fine cost to eat.

view this post on Zulip Sam Mohr (Feb 07 2025 at 23:02):

If we end up only wanting this for the LSP, the LSP could download them at startup

view this post on Zulip Isaac Van Doren (Feb 07 2025 at 23:17):

Yeah it seems like it would be fine to include them in the binary

view this post on Zulip Brendan Hansknecht (Feb 07 2025 at 23:41):

Yeah, the biggest concern with caching is simply making sure the wiring to the stdlib still works with no hiccups.

view this post on Zulip Sam Mohr (Feb 07 2025 at 23:42):

The current builtins are 68kb in a .tar.gz archive

view this post on Zulip Brendan Hansknecht (Feb 07 2025 at 23:48):

Wow, that's actually bigger than I expected

view this post on Zulip Sam Mohr (Feb 07 2025 at 23:48):

I expect Str.roc and List.roc are like half of that

view this post on Zulip Brendan Hansknecht (Feb 07 2025 at 23:48):

But, we package llvm, so no size concerns here


Last updated: Jun 16 2026 at 16:19 UTC