logoalt Hacker News

Philip-J-Frytoday at 1:55 PM5 repliesview on HN

The port was line for line and full of unsafe code. It didn't prevent any bugs. They're not using Rust for its strengths.


Replies

skeledrewtoday at 2:29 PM

You should give the article[0] a read.

"A large percentage of bugs from that list are use-after-free, double-free, and "forgot to free" in an error path. In safe Rust, these are compiler errors and RAII-like automatic cleanup with Drop. Compiler errors are a better feedback loop than a style guide."

"At the time of writing, about 4% of Bun's Rust code sits inside an unsafe block (~13,000 unsafe keywords across ~27,000 lines / ~780,000 lines), and 78% of those blocks are a single line — a pointer that came from C++, or one call into a C library. I expect this number to go down over time as we refactor from a faithful Zig port (which had no greppable unsafe keyword) to idiomatic Rust, but we are going to continue using C & C++ libraries like JavaScriptCore so it will always have more unsafe than pure Rust projects."

[0] https://bun.com/blog/bun-in-rust

show 1 reply
atombendertoday at 3:01 PM

The original Zig code is metaphorically one big unsafe block. Even if the Rust port is made up of 3% unsafe blocks, that still means 97% of the original Zig code has been made safe (in the Rust sense).

show 2 replies
samwillistoday at 2:36 PM

They have made it very clear that the mechanical translation is the starting point, and are refactoring to remove as many unsafe declarations as possible.

insanitybittoday at 2:53 PM

They turned every hidden memory safety bug into a grep'able memory safety bug. That's step 1 and a massive win.

neuronexmachinatoday at 2:47 PM

That may have been the case for the initial iteration a few months ago, but is it still true?