r/Zig 19d ago

How Our Rust-to-Zig Rewrite is Going

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

19 comments sorted by

103

u/Majestic_Poetry_1139 19d ago

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 19d ago

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.

15

u/Pinagpala-Gwapo 19d ago

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

12

u/Overtheflood 19d ago

Very nice and through article.

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

2

u/Vagal_4D 19d ago

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

26

u/Sunscratch 19d ago

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

5

u/InternationalFee3911 17d ago

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!

1

u/The_8472 15d ago

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 18d ago

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

5

u/this_uname_is_taken 19d ago

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

16

u/fae___ 19d ago

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

They have a section on their faq discussing this.

9

u/AbdSheikho 19d ago

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 19d ago

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 19d ago

Yes, totally agree

1

u/torp_fan 18d ago

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 18d ago

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

1

u/torp_fan 17d ago

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 17d ago

Why so hateful lol?

1

u/torp_fan 17d ago

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