3 ms·
There are use cases where safety beyond memory safety is required. But there are no use cases where memory unsafety is desirable, yet alone required.
by lmm 3y ago
There are use cases where safety beyond memory safety is required. But there are no use cases where memory unsafety is desirable, yet alone required.
- quic5 3y agoThat is absolutely true. But but you can write memory-bug-free code in Zig but you cannot prevent heap allocations in most of the languages listed in the article, making it outright impossible to write certain software in them.
- grumpyprole 3y agoSure one can write memory-bug-free code in x86 assembly too. But how can you prove it? ATS is an example of a low-level systems language where you can prove it.
- ObscureScience 3y agoAs Zig promises "not hidden allocation", I assume you can build your allocator in Rust and then use it for all memory allocation in Zig.
- lmm 3y agoA function that doesn't allocate doesn't mean it's safe. (Indeed if anything the opposite is more likely - copying is safe, if slow, writing to something that was passed in tends to be what breaks).
- ArtixFox 3y agoformalized subsets of x86 assembly exist. Coq can be used as a macro assembler. tools to work with llvm ir exist, x86 can be raised up to llvm ir and proved, kinda bad way tho.
- memefrog 3y agoYou can't prove it in Rust either.
- jdrek1 3y agoWhile that is true, there might be other requirements that prevent memory safe languages from being used. For example not having a heap available instantly disqualifies most of them. Or when you have simulations running where having constant OOB and other checks would be a massive slowdown. Now obviously your code should still be memory safe (because otherwise it's not correct anyway and you should fix the code), but not at the cost of runtime checks.
- memefrog 3y ago>there are no use cases where memory unsafety is desirable, yet alone required. There are plenty of 'use cases' where Rust's guarantees (some vague but unenforceable promises around memory) are not worth the cost of using Rust (a very high cost). This is doubly true if you want to, say, not use any third-party libraries. If you use third-party libraries, you get essentially zero guarantees. And if you don't, you have to reinvent the world - and writing new data structures in Rust is a series of research projects, whereas doing so in C is trivial. There are many situations where guaranteed 'memory safety' (a Rust propaganda term for 'having the guarantees we can provide but not the ones we can't provide') is not very important.
- throwawaymaths 3y ago> But there are no use cases where memory unsafety is desirable, yet alone required. Operating system bootstraps? DMA management/volatile driver access? Doubly linked lists?