How do you know? "anything else" seems fairly definite to me, as does "absolutely zero":
I don't know enough about how the out-of-memory situations would be triggered and caught to actually know whether this is a fundamental problem or not, so my reaction comes from ignorance, but basically the rule has to be that there are absolutely zero run-time "panic()" calls. Unsafe code has to either be caught at compile time, or it has to be handled dynamically as just a regular error.
I'm not sure I can follow the discussion, but why not just use get() (which returns None on out-of-bounds) instead of directly indexing the slice when the index is not guaranteed to be valid?!
How is this even an argument? In C, malloc/new can be configured to return an error. Memory managers need to function in low memory environments. In C, accessing invalid memory (out of bounds) is an access violation structured exception. Can't Rust panic be configured to behave similarly?
I think the parent comments accept that memory allocations must not panic, but they think panics are still fine in other situations, whereas my reading of what Linus says is that Rust panics are never acceptable.
In C, accessing invalid memory (out of bounds) is an access violation structured exception.
That depends on the C runtime. The kernel doesn't have exceptions.
Can't Rust panic be configured to behave similarly?
Rust panics can be caught in separate thread, or using catch_unwind (similar to exceptions). That won't be applicable for the kernel though.
Rust 1.0 couldn't return errors for memory allocations, but work has been done to address that. The default is still to panic, and it sounds like the linux patch still had some oom panics, but I haven't looked into that.
Other than memory allocations, Rust panics in other situations too, so they will needed to be avoided. e.g. slice indexing (but you can use get instead of the [] index notation) and RefCell (has try_ accessors instead).
8
u/phoil Apr 15 '21
How do you know? "anything else" seems fairly definite to me, as does "absolutely zero":