Top
Best
New

Posted by jorangreef 10 hours ago

How Our Rust-to-Zig Rewrite Is Going(rtfeldman.com)
326 points | 176 commentspage 2
g42gregory 3 hours ago|
Does this mean every time you find yourself using lots of “unsafe” Rust blocks, it’s not the right tool for the job? I suspect it’s not that simple, but what are people’s experience?
steveklabnik 2 hours ago|
It really depends. For example, it might mean that you do not know the way to do the same thing, but in a safe manner. It might mean that you could refactor your code to do things more safely.

Of course, reasonable people may also believe that it is easier to use an unsafe language directly rather than change the ways that you code.

In my experience doing embedded, operating systems work, compiler work, and others, you never need a large amount of unsafe code. 1%/4% is really about it.

g42gregory 2 hours ago||
Makes sense. Thanks!
KoleSeise1277 7 hours ago||
The 35ms incremental rebuild is the part that sold me. I'd be curious to see the same benchmark on ARM once -fincremental gets there.
mlugg 1 hour ago|
Zig team member here---obviously I can't say for sure yet, but I'm pretty confident the number will be basically identical. In the Zig compiler, incremental updates (rebuilds) have a small amount of overhead which is roughly proportional to the total size of the codebase (rather than just the amount of code which was changed). This comes from a) detecting which source files changed, and b) traversing a graph to figure out which declarations are referenced (necessary due to Zig's "lazy analysis" feature). But performance analysis reveals that for small updates, this overhead actually dominates the update time, by a lot. Of the 35ms, I would guess that under 5ms are actually spent rebuilding the function(s) that changed. Of that 5ms, code generation---the only thing which would really be different on AArch64---is an even smaller slice of the pie (it often doesn't even impact the overall time, since it runs in parallel with other parts of the pipeline, and those other parts are usually the bottleneck there). So even if the AArch64 backend was significantly slower (which, right now, is the opposite of what we expect---instruction selection and encoding for x86_64 is unusually complicated!), I wouldn't expect the number to change from 35ms.
maybebug 5 hours ago||
Nitpicking ahead:

I am not sure, but there might be a bug in their pattern matching example.

What happens if 'verb' is "GET" and 'path' is "/users/1234/posts/1234/extra_path/and/more/"? Will 'post_id' become "extra_path/and/more/"?

I tried running it in the sandbox, and it does indeed seem to buggily result in:

"Post ID: 1234/extra_path/and/more"

I suspect that the reason it is behaving like it is, is due to how it handles characters in the string literal. The example program exploits that only the slashes present in the string literal pattern are matched, to enable matching on 'page' having slashes. But then in the nested 'match', it forgot to account for any possible extra slashes.

Nitpicking end.

I have not read the whole post yet, but the pattern matching not requiring any allocations, seems very nice. The string literal patterns also seem interesting, though I am not completely sold on them, also as per the above possible bug. It seems really clean in some ways, but the specific semantics, I am not fully sure about. Maybe it is excellent, and is so clean and concise that it is overall less bug-prone than alternatives in other programming languages. I do not know.

Fervicus 2 hours ago||
Roc seems interesting. But for some reason I find it very grating to have the type definition on a separate line. Very much prefer F# syntax for that.
coffeeindex 7 hours ago||
Didn’t know Roc was still being worked on. I think it’s an interesting concept for a language that I personally haven’t seen elsewhere
sarchertech 4 hours ago||
What made you think it was no longer being worked on?
denismenace 3 hours ago||
What concepts do you find interesting, compared to other FP languages?
dev_l1x_be 6 hours ago||
Zig is a pre-1.0 language while Rust is post-1.0. This alone is settles which one to pick for may developers. The library support is probably favours Rust too. Rust build times are much slower than Zig, I get that, but I rarely optimize software for build times.
drdexebtjl 5 hours ago|
Zig is not pre-1.0 because it’s not ready for production (bugs or missing features), it’s pre-1.0 because they want to be able to make breaking language changes.

Nowadays when you can just point an agent at release notes and have it update everything, I actually prefer not having to wait through rare major releases to get new language features.

Aurornis 5 hours ago|||
> Zig is not pre-1.0 because it’s not ready for production (bugs or missing features), it’s pre-1.0 because they want to be able to make breaking language changes.

This is a solved problem in other projects. Either use the version numbers as intended and bump the major version number on breaking changes, or use Rust-style editions to opt in to the newer versions of the changes.

Calling a project production-ready but keeping the version number below 1.0 and saying breaking changes are expected is a tired game. We've seen it backfire across a number of language projects like Elm, where the exact same claim was used to both encourage people to use it and then blame them when it backfired.

If it's production ready, go to 1.0 and then follow semver for breaking changes. I don't care if we get to Zig v73.2.0 as a result. At least we can see from a glance which versions need to be checked for breaking changes.

em-bee 4 hours ago|||
languages ideally should not have breaking changes ever.

on the other hand, a language with frequent breaking changes should not be considered production ready.

people are of course free to live on the edge, and if someone decided that zig is good enough and they are not bothered by breaking changes then they are free to use it for their production system, but that doesn't mean it's ready for everyone. so i prefer the zig approach.

bsder 1 hour ago||
> languages ideally should not have breaking changes ever.

I disagree MIGHTILY. This is how you wind up with C++ and Java.

Languages need to be able to remove features to stay coherent. Occasionally, you get things wrong, it takes time to figure that out, and that's just the way life is.

drdexebtjl 4 hours ago|||
[dead]
afdbcreid 5 hours ago||||
> Nowadays when you can just point an agent at release notes and have it update everything

Except that means that not only you lose compiler bugfixes, you also pretty much has no access to the ecosystem. For most production codebases, this is a deal breaker.

rwz 5 hours ago|||
> they want to be able to make breaking language changes

That sounds like it's not ready for production to me.

drdexebtjl 5 hours ago||
I invite you to read the release notes and see for yourself the types of breaking changes we’re talking about.

To me it is not much different from Lua, which despite being on 5.x for decades, makes breaking changes on minor releases (because it predates SemVer).

I also don’t see it being much different from any other language or language runtime that has a major release every year.

It’s fine to update at your own pace.

uaksom 2 hours ago||
> I invite you to read the release notes and see for yourself the types of breaking changes we’re talking about.

I did, and I immediately found this in the latest release: https://ziglang.org/download/0.16.0/release-notes.html#IO-as...

That seems like it would require changing a lot of code. Calling it "production ready" is dishonest at best

drdexebtjl 11 minutes ago||
Not really. It’s find and replace work.

If by production-ready you mean you can forever avoid changing code you wrote 8 months ago, sure, pick something else.

To me production-ready means it can be trusted to power production workloads, has all tooling I need, and has a consistent long-term vision. Zig ticks all the boxes.

satyambnsal 6 hours ago||
is this uno reverse for bun post of zig to rust port ?
dbacar 4 hours ago||
why not rewrite in ROC?? Would be much more cooler.

I think precious cognitive time should be spent more on the language itself rather than wasting it on rewrites.

steveklabnik 4 hours ago|
The article links to https://www.roc-lang.org/faq#self-hosted-compiler to discuss this.
christkv 4 hours ago||
Can anybody explain to me why anthropic bought bun in the first place ?
3D39739091 58 minutes ago||
Nobody can.

"Claude Code uses Bun" is the reason that's given. But even though Anthropic tells us that "coding is solved", instead of rewriting Claude Code in something other than JS, they bought a company that made a JS runtime and then did a mass rewrite of that JS runtime.

steveklabnik 4 hours ago||
Claude Code uses bun.
christkv 3 hours ago||
Yeah I get they use it but I don't understand why you would buy it. it's just the runtime for code that makes up the agent.
steveklabnik 3 hours ago||
Bun was a startup. Startups can go out of business, and then you are now scrambling to move your code to something else. They could also be bought by someone who has different priorities regarding future development than you, and that's also a risk.

The simplest solution to these problems, if you have the capital, is to buy them.

christkv 2 hours ago||
I get that but there is always node.js
steveklabnik 1 hour ago||
They aren't exactly the same thing, moving to node would be possible but bun does more than node, so you need to replace the whole thing.
christkv 58 minutes ago||
Oh for sure. I guess its just as much a Acqui-hire as well as for the tech.
up2isomorphism 6 hours ago|
I think there will be soon a wave of rewriting rust to language X coming up.
echelon 4 hours ago|
The other way around.

Rust is also one of the best languages to use with AI.

skhameneh 34 minutes ago||
I like Rust and I'm an advocate of Rust, but this really isn't true (at least it hasn't been and I doubt much has significantly changed).

The syntax complexity and the ecosystem haven't been ideal for LLM development. And there have been publications on findings of LLM efficacy with different languages. Rust is most often towards the lower end of efficiency/correctness when benchmarked.

https://arxiv.org/html/2508.09101v1

steveklabnik 25 minutes ago||
This paper uses models that are over a year old at this point. Many people didn't believe that LLMs were worth using for programming until 6 months after that, and now again this week we've had another huge leap in abilities.

This is beyond the other issues with the methodology of this study. For example, their Rust code was created by asking Deepseek to port their C++ code, not having it try and write Rust itself.

More comments...