Memory safe in D

Richard (Rikki) Andrew Cattermole richard at cattermole.co.nz
Wed Apr 17 14:02:19 UTC 2024


On 17/04/2024 10:15 AM, ShowMeTheWay wrote:
> Coming from C# or Java, it must feel like coming to D means going 
> backwards with regards to the compilers ability to detect simple bugs 
> like this.

What you are talking about is called type state analysis.

https://en.wikipedia.org/wiki/Typestate_analysis

To do this properly requires a verification data flow analysis.

But once you have that DFA it opens a lot of doors for memory and 
temporal safety.

Currently D is defined against type state analysis, however it doesn't 
have it as its own thing.

Pointers are defined to be guaranteed to be non-null when accessed by 
using the CPU's MMU to throw an exception if you tried to access it.

If you goto past a variable, that is a compiler error as it is not 
reachable.

My proposal has the hierarchy of:

unreachable < reachable < initialized < default < non-null < user-defined.

https://forum.dlang.org/post/ucdmmlxklanpsggqmwas@forum.dlang.org

So yes D is backwards, because its missing a whole bunch of analysis 
that you are expecting to exist.


More information about the Digitalmars-d mailing list