NonNull template

Richard (Rikki) Andrew Cattermole richard at cattermole.co.nz
Tue Apr 22 00:42:43 UTC 2025


On 22/04/2025 5:29 AM, Johan wrote:
> If you want to fault on null-dereference, I believe you /have/ to add a 
> null-check at every dereference at /language/ level (regardless of 
> implementation details). Perhaps it does not impact performance very 
> much (with optimizer enabled); I vaguely remember a paper from Microsoft 
> where they tried this and did not see a big perf impact (if any).

I agree with what you're saying here, but I want to refine it a little bit.

Every language dereference must have an _associated_ read barrier.

What this means is:

```d
T* ptr;
readbarrier(ptr);
ptr.field1;
ptr.field2;

ptr = ...;
readbarrier(ptr);
ptr.field3;
```

A very simple bit of object tracking when inserting the check, will 
eliminate a ton of these, tbf we should be doing that for array bounds 
checking if we are not already.

Also the fast DFA which this would be used with, would eliminate a ton 
of them, so performance should be a complete non-issue, given how ok we 
are with array bounds checks.



More information about the Digitalmars-d mailing list