Comment by gcr
8 days ago
It’s my understanding that bun was ported to unsafe rust, so even these gains would require additional effort on the team’s part, right?
8 days ago
It’s my understanding that bun was ported to unsafe rust, so even these gains would require additional effort on the team’s part, right?
Unsafe Rust doesn't automagically disable typesystem (& borrow checker, but lifetime are a sort of types).
Once raw pointer is turned into a T, &T or &mut T, the borrow checker is on.
True, but unsafe let's you conjure up any lifetime you want, or any lifetime necessary to satisfy the lifetime requirements in safe code. If you generously sprinkle pointer dereferences in unsafe code, you effectively disable the protection provided by the borrow checker – including in safe code – until you've checked and verified the correctness of all unsafe blocks.
> True, but unsafe let's you conjure up any lifetime you want
The only thing unsafe does is let you have an unbounded lifetime. As I said, it doesn't check those:
https://doc.rust-lang.org/nomicon/unbounded-lifetimes.html
> if you generously sprinkle pointer dereferences in unsafe code, you effectively disable the protection provided by the borrow checker
You don't disable anything. You wrote a "trust me compiler" block, and compiler trusted you.
Rust won't ever protect from all possible problems, just the ones the compiler handles.
13 replies →
Yeah but if you have tried writing unsafe Rust, you notice that you are obligating yourself to write code that is much stricter than C.
E.g. in C you can write code and say "don't call it outside the situation that this function was written for" and then blame [0] future users of the API.
In Rust you need to actually make sure that your code works, i.e. your safe interface is not unsafe.
[0] The blame game is not a technical solution to a technical problem...
Borrow-checking the dereference of a stale pointer won't be worth much, though.
Sure; but I bet raw pointers are used very infrequently in the new codebase. The code was ported from zig to rust. I bet a lot of pointers became rust references in the process.
2 replies →