r/ProgrammingLanguages • • Dec 31 '25

Memory Safety Is ...

https://matklad.github.io/2025/12/30/memory-safety-is.html
37 Upvotes

78 comments sorted by

View all comments

Show parent comment

1

u/reflexive-polytope Jan 03 '26

My point is that, as a language user, I'm concerned with the correctness of the program I'm actually writing, rather than with weaker properties of every program you could conceivably write.

The mechanisms by which specific language designs enforce type safety or memory safety (or don't) are interesting insofar as they simplify the reasoning by which I can establish that the program I'm writing is correct.

For example, a language that requires the array indexing operation arr[idx] to be equipped with a (possibly inferred) proof that idx is a valid index is more useful than a language that inserts a runtime bounds check. As far as I'm concerned, trapping the error at runtime is the same as not trapping at all - the program is equally wrong in both cases.

1

u/koflerdavid Jan 03 '26 edited Jan 03 '26

Such strong formalisms exist, but they are usually quite unergonomic. In fact so unergonomic that the industry has resigned to reduce the blast radius of violations that are too difficult to detect at compile time and sometimes uses static analysis tools where it is not too inconvenient to do so. Trapping at runtime is accepted as a lesser evil since violating memory safety and type safety can have catastrophic and difficult to investigate side effects. Rust's type system is a good progress since it makes it so much easier to write safe native code.

The situation looks a bit better for functional languages with dependent type systems. Among other things, they specifically allow to encode the length of an array in its type, and indexing is only possible if you provide a proof that the index is within the array's bounds. Doing these things is simpler with immutable data since then one doesn't have to take time into account, since modifying a data structure will invalidate any proof derived previously.