← Back to context

Comment by pron

15 hours ago

> Java and Rust have actually very similar memory safety profiles

They really don't. Look at how many basic data structures (in the standard library or outside it) require unsafe features in Java vs Rust.

> Zig has an identical memory safety profile to C

It really doesn't. Zig gives you the same spatial memory safety as Rust and very much not like C (and violations of spatial memory safety are a bigger cause of vulnerabilities than violations of temporal memory safety).

> Look at how many basic data structures (in the standard library or outside it) require unsafe features in Java vs Rust.

This is a fundamental misunderstanding of how "unsafe" code relates to a platform's trusted computing base. Rust could move all of those unsafe data structures out of the standard library and into the compiler itself, thereby reducing the amount of occurrences of the string "unsafe" in the source, code, but this would do nothing to reduce the size of the trusted computing base that Rust presents. In fact, it would decrease our confidence in that code, because Rust libraries have a robust ecosystem of tools for validating their correctness, unlike whatever bespoke IR the Rust compiler itself is emitting. Java's own data structures are implemented with the support of an extensive runtime written in C++, which forms their own trusted computing base that every user of Java relies upon, and demands just as much careful auditing as any data structure in the Rust standard library.

  • The point is not that those specific implementations use unsafe Rust but to illustrate that to write even basic data structures you need unsafe Rust.

    • That's just false. You can use `Arc` or even one of the safe GC crates available, and get semantics like Java with no `unsafe`.