Stream: compiler development

Topic: Rust and Zig stdlib


view this post on Zulip Richard Feldman (Sep 13 2023 at 20:23):

I'm trying to remember some details about the time when we tried out Zig as an alternative to Rust for the stdlib - as I recall (maybe @Jared Ramirez remembers?) we first tried out Rust, and then it wasn't going well, and then we talked about "wouldn't it be easier if we just did it in C?" and then "if we're going to do it in C, why not Zig?"

view this post on Zulip Richard Feldman (Sep 13 2023 at 20:23):

I definitely remember one of the challenges we ran into was a toolchain thing, something along the lines of the --emit=llvm-ir flag not working the way we wanted to, or something like that

view this post on Zulip Richard Feldman (Sep 13 2023 at 20:23):

might also have been wasm-related?

view this post on Zulip Richard Feldman (Sep 13 2023 at 20:24):

does anyone remember the specifics of what originally motivated looking at non-Rust options?

view this post on Zulip Richard Feldman (Sep 13 2023 at 20:25):

(besides just "this uses unsafe all over the place, so we aren't really getting much from Rust" and the opportunity cost of other languages having things like nicer opt-in runtime checking for memory management mistakes etc.)

view this post on Zulip Folkert de Vries (Sep 13 2023 at 20:26):

I specifically remember that rust just added in lots of stuff we did not want/need

view this post on Zulip Folkert de Vries (Sep 13 2023 at 20:26):

I'm guessing panics specifically?

view this post on Zulip Folkert de Vries (Sep 13 2023 at 20:27):

also yeah LLVM might sort of work but getting the object files from rust is not easy

view this post on Zulip Folkert de Vries (Sep 13 2023 at 20:27):

llvm would also get split into many separate files I think with rust

view this post on Zulip Richard Feldman (Sep 13 2023 at 20:34):

oh yeah

view this post on Zulip Richard Feldman (Sep 13 2023 at 20:35):

I would have thought no_std would get rid of panic infrastructure, but maybe we didn't know about that at the time?

view this post on Zulip Folkert de Vries (Sep 13 2023 at 20:39):

well it does panic = abort, which might not be what you want either?

view this post on Zulip Folkert de Vries (Sep 13 2023 at 20:39):

generally rust generated code is pretty bloaty

view this post on Zulip Richard Feldman (Sep 13 2023 at 20:44):

yeah I just remember there was a moment where it was like "ugh, this is really painful...what if we did C?" and I remember it being a couple of specific development pain points rather than code gen

view this post on Zulip Richard Feldman (Sep 13 2023 at 20:44):

but I don't remember what exactly they were :laughing:

view this post on Zulip Jared Ramirez (Sep 13 2023 at 20:53):

I don't recall the specific pain points either unfortunately, but I think the the rust generated llvm-ir needed quite a bit of transforming to get it to work with the output after the roc compiler gen was done (I seem to recall a lot of duplicate def issues, among other things). I also remember the dev process was pretty painful and it being annoying to link the generated bitcode back into the gen crate

view this post on Zulip Jared Ramirez (Sep 13 2023 at 20:55):

also found this old PR: https://github.com/roc-lang/roc/pull/568

the comment says

After talking, Richard and I decided to go with the completely different approach of using libc/c for builtins bitcode generation

so not very helpful as to what was the reasoning at the time

view this post on Zulip Jared Ramirez (Sep 13 2023 at 20:55):

then we did use c for a bit which had it's own problems so we ultimately switched to zig

view this post on Zulip Brendan Hansknecht (Sep 13 2023 at 21:07):

I definitely think the big thing was that everything was unsafe rust and it didn't feel very useful to use rust.

view this post on Zulip Brendan Hansknecht (Sep 13 2023 at 21:07):

Like none of the benefits of rust

view this post on Zulip Richard Feldman (Sep 13 2023 at 21:18):

oh yeah! I forgot that we literally used C briefly - @Jared Ramirez do you remember what any of the C pain points were by any chance? :smiley:

view this post on Zulip Folkert de Vries (Sep 13 2023 at 21:20):

a guess: cross-compilation?

view this post on Zulip Richard Feldman (Sep 13 2023 at 21:43):

but I think we always emit llvm bitcode, right? :thinking:

view this post on Zulip Brendan Hansknecht (Sep 13 2023 at 21:46):

Not for dev backends

view this post on Zulip Brendan Hansknecht (Sep 13 2023 at 21:46):

but that wasn't a real concern back then, I don't think.

view this post on Zulip Brendan Hansknecht (Sep 13 2023 at 21:46):

Cause dev backends didn't exist

view this post on Zulip Jared Ramirez (Sep 13 2023 at 23:38):

Maybe pain points was the wrong wording, I think it might've worked okay but Zig was easier to write safely and was new/exciting. Plus I think we just weren't psyched on writing C in general at the time


Last updated: Jul 06 2025 at 12:14 UTC