Live data from Hacker News

Bun Rust rewrite: "codebase fails basic miri checks, allows for UB in safe rust"

github.com

31–40 of 366 posts

Re: Bun Rust rewrite: "codebase fails basic miri checks, allows for UB in safe rust"

#31
post #7

I thought Rust treated undefined behaviour as a compiler bug? Does anyone know what's actually happening here?

I'm sure there have been attempts at defining a language that has no UB, but afaik all meaningful languages have UB in some dark corner or enumerated explicitly. For example, Java thread execution order is UB.

Re: Bun Rust rewrite: "codebase fails basic miri checks, allows for UB in safe rust"

#32
post #27

Earlier quoted context omitted.

That kind of error was entirely avoidable. There are well-known tools in the Rust ecosystem that detect this kind of error and while the tools do not detect all instances of UB caused by mistakes in unsafe blocks, it's still considered good practice to run them.

>There are well-known tools in the Rust ecosystem that detect this kind of error Yes, tools like Miri, which this very post is about.

Indeed. My point is that just using the standard tools in the Rust ecosystem - like miri - would have trivially uncovered this error before it made it to the mainline.

Re: Bun Rust rewrite: "codebase fails basic miri checks, allows for UB in safe rust"

#33
post #24

There's a book that changed a lot of the way I think about attention and media [0]. The book isn't very good, but it flags something relevant here. There is a huge asymmetry between the reach of a big, flashy announcement (here: bun was re-written in memory-safe rust in a couple weeks), and the relatively small reach of a correction (often just a footnote on an old article, here a GH issue). This asymmetry is well un…

> a big, flashy announcement (here: bun was re-written in memory-safe rust in a couple weeks) Did they even claim it was "memory-safe"? Every discussion of this topic has had dozens of comments noting that their vibed codebase is bursting at the seams with unaudited unsafe blocks, lightly reviewed by people who seem to not only seem to not understand Rust, but who seem incensed at the idea of needing to understand an…

The author kept bragging about classes of bugs that would not happen with Rust.

Re: Bun Rust rewrite: "codebase fails basic miri checks, allows for UB in safe rust"

#34
So many people are fundamentally misunderstanding everything about this rewrite.

In fact using the word "rewrite" itself is pretty inaccurate.

As has been mentioned the goal was a port so they "could" eventually rewrite most of it to be idiomatic rust. The main benefit of this now is the compiler and being able to use these tools to fix issues that were already being hidden when it was in zig.

If you go into this codebase expecting to see idiomatic rust and get angry when it's not there, you are going in with the entirely incorrect attitude.

It's understandable how people see it as AI slop or whatever given the division among developers at the moment. But please see it for what it is instead of just jumping to conclusions.

Re: Bun Rust rewrite: "codebase fails basic miri checks, allows for UB in safe rust"

#36
post #13

This had to happen, for many reasons: - Its a throw thing at the wall and see what sticks situation - LLMs will improve* - Using LLMs in an agentic way will improve (git worktrees, sliced PRs, spec driven steps) So what happened here is a mess, but you gotta break a few eggs to make a souffle. It's a learning step and I am glad it happened, there will be so many things to debrief from this. I don't use Bun or Rust bu…

A souffle has not been made

Indeed, more of a frambled egg. Lets see what happens in two years time.

Re: Bun Rust rewrite: "codebase fails basic miri checks, allows for UB in safe rust"

#38
post #28
post #7

I thought Rust treated undefined behaviour as a compiler bug? Does anyone know what's actually happening here?

Safe Rust does. Unsafe Rust allows you to tell the compiler “hold my beer”. It’s a concession to the reality that the normal restrictions of Rust disallow some semantically valid programs that you might otherwise want to write. The safeguards work great in most cases, but in some they’re overly restrictive. In practice, the overwhelming majority of code is able to be written in safe Rust and the compiler can have you…

OK but the title says "in safe Rust". Am I misunderstanding something? All the replies here are saying how it's allowed in unsafe Rust, which is not what the title says.

Re: Bun Rust rewrite: "codebase fails basic miri checks, allows for UB in safe rust"

#39
post #25

This doesn't seem surprising, given the straight translation that they prompted. Couldn't a case be made that it's better to get Bun to the to the language with the stronger type system first and, once there, use that stronger type system as leverage for these kinds of improvements as a follow-on effort? It seems preferable to requiring perfection on the very first step.

It's not surprising that a mostly straightforward translation to (partly unsafe) Rust exhibits UB.

What is a bit disappointing is that the Rust code apparently has APIs that aren't marked unsafe but may cause UB anyway. When doing this kind of translation, I'd always err on the side of caution and start by marking all/most things unsafe. Or prompt the slopbots to do the same I guess.

Then you can go in and verify the safety of individual bits step by step.

Re: Bun Rust rewrite: "codebase fails basic miri checks, allows for UB in safe rust"

#40
post #25

This doesn't seem surprising, given the straight translation that they prompted. Couldn't a case be made that it's better to get Bun to the to the language with the stronger type system first and, once there, use that stronger type system as leverage for these kinds of improvements as a follow-on effort? It seems preferable to requiring perfection on the very first step.

Yes, and seems pretty clear you can now backpressure the rewrite with tools like miri to have Claude Code automatically improve it.
Post reply on HN