Live data from Hacker News

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

github.com

21–30 of 366 posts

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

#21
post #4

That kind of error was expected. I don't see it as an issue against the rewrite. They kept the stable versions on Zig in case ppl needs stability. Eventually, the errors will get fixed.

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.

Indeed this was caught by a well-known tool, Miri, that detected this error.

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

#22
post #7

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

"unsafe" is a promise to the compiler that you're going to ensure invariants that the compiler can't check. Rust only promises to eliminate UB if the invariants are held. You can still get UB by violating that promise, as this bug demonstrates.

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

#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 any programming language in the first place.

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

#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.

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

#27
post #4

That kind of error was expected. I don't see it as an issue against the rewrite. They kept the stable versions on Zig in case ppl needs stability. Eventually, the errors will get fixed.

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.

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

#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 your back. The majority of the rest is for performance reasons, interacting with external functions like C libraries over FFI, or expressing semantics that safe Rust struggles with (e.g., circular references).

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

#29
post #7

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

"unsafe" is a promise to the compiler that you're going to ensure invariants that the compiler can't check. Rust only promises to eliminate UB if the invariants are held. You can still get UB by violating that promise, as this bug demonstrates.

But the title here says "in safe Rust", no? Is the unsafe code causing UB in safe code? I thought the unsafety couldn't "spread" like that in Rust.
Post reply on HN