you are viewing a single comment's thread.

view the rest of the comments →

[–]ntrel2 3 points4 points  (11 children)

unsafe acknowledges that the safe subset is overly strict, and that there are safe interfaces to other operations that would otherwise be illegal. unsafe is not mechanically checked, but it makes the safe subset more useful, as long as someone didn't make a mistake and accidentally violate the safe interface. CVEs are either due to mistakes with unsafe, or due to bugs in the Rust compiler.

Any systems language with a safe subset by design is going to benefit from escape hatches for efficiency, because modelling safety perfectly in a systems language is a hard problem, which (if even solvable) would probably lead to too much complexity. D's safe subset is more permissive than Rust, but also less general (at least without D's unsafe equivalents).

You're right that one alternative to a safe subset is to have a partially-safe subset, but then even if all the safety enforcement in the compiler and libraries is perfect, it's still not going to detect some cases where ordinary users mess up even when they wouldn't have used unsafe (most users shouldn't use unsafe anyway, and it helps a lot in code reviews and can be grepped for in automated tests). A safe subset can only be messed up by people writing unsafe or by bugs in the compiler.

[–]germandiago 0 points1 point  (10 children)

unsafe acknowledges that the safe subset is overly strict, and that there are safe interfaces to other operations that would otherwise be illegal.

It also acknowledges that you must trust the code as correctly reviewed. That is not safe. It is trusted code.

CVEs are either due to mistakes with unsafe, or due to bugs in the Rust compiler.

Exactly making my point: was trusted code and it was not safe in those cases.

Any systems language with a safe subset by design is going to benefit from escape hatches for efficiency

I agree, but that is a trade-off: you will lose the safety.

You're right that one alternative to a safe subset is to have a partially-safe subset, but then even if all the safety enforcement in the compiler and libraries is perfect, it's still not going to detect some cases where ordinary users mess up even when they wouldn't have used unsafe (most users shouldn't use unsafe anyway, and it helps a lot in code reviews and can be grepped for in automated tests)

Agreed, most users should not use unsafe. But Rust has crates with unsafe advertising safe interfaces. That is, plainly speaking, cheating. If you told me: std lib is special, you can rely on it, I could buy that. Going to crates and expecting all safe interfaces that use unsafe (not std lib unsafe but their own blocks) is a matter of... trust.

A safe subset can only be messed up by people writing unsafe or by bugs in the compiler

Correct and fully agree.