3 ms·
Rust is only not memory safe in the same sense that any language with C FFI or a runtime written in C++ that isn't formally verified isn't memory safe. Which b
by Jweb_Guru 11y ago
Rust is only not memory safe in the same sense that any language with C FFI or a runtime written in C++ that isn't formally verified isn't memory safe. Which basically includes every language.
- SamReidHughes 11y agoYou said garbage collection. You can't make whatever data structures in Rust that you want, without unsafe blocks or garbage collection (or no deallocation).
- Jweb_Guru 11y agoI didn't say "you can make any data structure you want without unsafe blocks or garbage collection." I said that you can write safe Rust without mandatory garbage collection and with deallocation. You're responding to a point I didn't make. In any case, part of the point of Rust is the ability to write safe abstractions over unsafe code. Arguing that the data structures like vectors are not memory safe is identical to the argument that other languages' runtimes are not safe.
- SamReidHughes 11y ago> I didn't say "you can make any data structure you want without unsafe blocks or garbage collection." I didn't say you said that, I gave an example of a useful thing you can't do in Rust. It is very meaningful to say that Rust isn't practically memory safe if you have to resort to unsafe code a lot of the time, or pay performance costs. I'm not talking about data structures like vectors, by the way. And it's not just data structures themselves, it's what you can do with them on the outside. Obviously you can make pretty much whatever abstractions you want in Rust if you use some GC'd heap or allocate stuff in vectors and use indices instead of pointers. But if you're doing that, you're probably going to not be doing it for long, there's a reason you aren't using Java.
- Jweb_Guru 11y agoI don't disagree with you. I think Rust has a long way to go before it can practically match well-optimized C in many cases without unreasonable amounts of unsafe code (obviously, this is subjective). But it at least offers the possibility of doing so, which is much more than I can say for essentially any other language. And even in performance-critical, optimized-assembly-output code in Rust, a lot of it is safe already.
- kibwen 11y agoAt some level you have to talk to the OS to do IO and allocate memory. ATS needs escape hatches for these just as Rust does. And in languages that don't give you escape hatches, they just drop down to C to implement their garbage collector.
- SamReidHughes 11y agoOh, my bad! I didn't know I needed to talk to the OS to make a linked list.
- kibwen 11y agoYeah, you do: https://github.com/python/cpython/blob/master/Objects/listobject.c https://github.com/python/cpython/blob/master/Objects/listob... You don't need unsafe code to make any data structure in Rust. Cycles can be made just fine using std::rc::Rc. The fact that it uses `unsafe` blocks under the hood doesn't mean it's not memory-safe. You seem to be vastly misinformed about what memory safety means.
- Jweb_Guru 11y agoRc is garbage collection, so it doesn't qualify for "any data structures you want without unsafe blocks or garbage collection (or no deallocation)." You can make cycles without Rc, of course.
- kibwen 11y agoRC without cycle collection isn't garbage collection by any definition that I'm aware of. :)
- Jweb_Guru 11y agoIt certainly is. http://researcher.watson.ibm.com/researcher/files/us-bacon/Bacon04Unified.pdf http://researcher.watson.ibm.com/researcher/files/us-bacon/B... Here is a post by pcwalton on the same subject: https://news.ycombinator.com/item?id=9095314 https://news.ycombinator.com/item?id=9095314.