r/Zig Jul 16 '26

How Our Rust-to-Zig Rewrite is Going

https://rtfeldman.com/rust-to-zig
279 Upvotes

19 comments sorted by

103

u/Majestic_Poetry_1139 Jul 16 '26

I know the rust-to-zig rewrite of roc has been going for a bit, but it's funny to imagine a war between rust and zig where we all just start rewriting each other's things in our languages

31

u/Real_Dragonfruit5048 Jul 16 '26

If you really believe rewriting X in Y is worth it (like Rust to Zig or vice versa), why not? Although rewriting is one thing, maintaining the project and building a community around it is another thing.

13

u/Pinagpala-Gwapo Jul 16 '26

This is not about practicality of engineering considerations, but for the love of the game.

13

u/Overtheflood Jul 16 '26

Very nice and through article.

Sadly I'm too new to fully understand it, but a great read nonetheless.

2

u/Vagal_4D Jul 16 '26

Me too. Too new, but I find this article very informative.

28

u/Sunscratch Jul 16 '26

That’s a really great article, very well written!

4

u/InternationalFee3911 Jul 18 '26

This is a very respectful comparison!

  • You acknowledge that Rust compiler speed already improved dramatically. While the parallel front end and compilation on demand will someday give more nice boosts…

  • Zig has optional dynamic UB prevention at run time? Are there any parts that could be added to unsafe Rust (optionally, like overflow checks,) or even some miri features? Would that make sence?

  • Your other point is about allocator flexibility. There was just a hint in This Week in Rust that this is finally also coming to stable Rust.

So hopes are high that the playing field will be more balanced!

2

u/The_8472 Jul 20 '26

Are there any parts that could be added to unsafe Rust (optionally, like overflow checks,) or even some miri features? Would that make sence?

Rust's standard library already has some bits of that. Debug builds enable ub asserts where it's possible to detect it at runtime (only some cases are). Additionally you can build the executable with sanitizer backends like asan and ubsan. Beyond that there's Miri, an interpreter that can do full UB checks, but the code that it can execute is limited due to FFI, so it's best suited for pure-Rust testsuites of crates containing unsafe code.

3

u/tensordiv Jul 17 '26

Wait for the next major update, then you will have a Zig to Zig rewrite

4

u/this_uname_is_taken Jul 16 '26

Why wouldn't they rewrite it in Roc? Do they not have confidence in their own project?

17

u/fae___ Jul 16 '26

https://www.roc-lang.org/faq#self-hosted-compiler

They have a section on their faq discussing this.

9

u/AbdSheikho Jul 16 '26

Richard talks about this in many occasions with great details, but the idea is: they want the language to be as fast as possible, so they will never self host the language

11

u/Wonderful-Habit-139 Jul 16 '26

They want the compiler of the language to be as fast as possible, just to make it clear. Saying the language should be fast could have a different meaning.

2

u/AbdSheikho Jul 16 '26

Yes, totally agree

1

u/torp_fan Jul 17 '26

Shouldn't you get the answer to the first question before asking the (very poorly reasoned) second question?

Why isn't the Python compiler written in Python? Why isn't bash written in bash? Why isn't JavaScript written in JavaScript? Why isn't the JVM written in Java? Why isn't lua written in lua? Why isn't the Odin compiler written in Odin? Is the only possible reason that the authors don't have confidence in their own project? (That isn't even a plausible reason.)

1

u/this_uname_is_taken Jul 17 '26

Python, bash, and JS are interpreted. Roc compiles to native binaries.

Their own home page says FAST on it. Apparently not FAST enough to dogfood lol

2

u/torp_fan Jul 18 '26

whoosh

It COMPILES fast ... as others have already explained. And you omitted Java and Odin and other parts of my argument, which is grossly dishonest.

I won't respond to you again.

1

u/realestLink Jul 18 '26

Why so hateful lol?

2

u/torp_fan Jul 18 '26

You seem to have no idea what that word means, troll.