Live data from Hacker News

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

github.com

41–50 of 366 posts

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

#41
post #29

Earlier quoted context omitted.

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

UB != unsafe

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

#42
post #29

Earlier quoted context omitted.

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

Unsafe code can break certain invariants of Rust, as `unsafe` is just a compiler "hold my beer" flag, which is why you're meant to do safety checks in your safe interface around unsafe code. If the unsafe code is wrapped in a way that does no guarding (or does something stupid in general), it is technically marked safe (because you said "rustc, hold my beer" as `unsafe` is also a contract) despite actually being unsafe

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

#43
post #29

Earlier quoted context omitted.

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

That is not Rusts guarantee. The guarantee is that safe rust cannot in itself introduce UB - UB can only ever be introduced in unsafe blocks, but it can then materialize in safe code.

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

#44
post #29

Earlier quoted context omitted.

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

If you use unsafe improperly, it is possible to encounter UB in "safe" code which relies on the unsafe code being correct.

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

#46

This Bun rewrite feels like a potential Mythos marketing stunt.

[flagged]

I'm not sure that HN is that influential that buying up a few accounts would matter. To what end?

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

#47

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 cod…

> As has been mentioned the goal was a port so they "could" eventually rewrite most of it to be idiomatic rust.

They may have said that, but quite clearly the value they actually get out of it is getting the headline "AI reimplements complex, broadly used software in 2 weeks, but makes it way better because it's rust now" in front of a million people's eyes, only 1% of whom will ever find out it was mostly fluff

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

#49
post #29

Earlier quoted context omitted.

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.

That is not Rusts guarantee. The guarantee is that safe rust cannot in itself introduce UB - UB can only ever be introduced in unsafe blocks, but it can then materialize in safe code.

Ah OK, that makes sense, thanks.

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

#50

Maybe they want a quick switchover and the UB is replicating existing problems so it is net neutral for the codebase (but positive future coz developers can do future work on rust without synchronizing two codebase? ).

If that was true, then I would expect followups to reduce UB and unsafe in general, or at least requiring a lifetime for caller-owned memory. But I think their true strategy is to have AI produce "fixes" like these which will end up infecting the entire codebase: https://github.com/oven-sh/bun/pull/30728

So this is a clear case where the LLM generated Rust port introduced a bug:

> The Zig original is a packed struct with the same shape; it "worked" only because Zig has no reference aliasing or provenance rules to violate. The Rust port inherited the shape without rethinking the API surface.

Post reply on HN