[OT] OT: Null checks.

Timon Gehr timon.gehr at gmx.ch
Wed May 7 00:16:14 UTC 2025


On 5/7/25 01:34, Walter Bright wrote:
> On 5/5/2025 8:38 PM, Timon Gehr wrote:
>> On 5/6/25 05:31, Timon Gehr wrote:
>>>
>>> I just wish everyone would refrain from actively putting invalid 
>>> instructions and segfaults into druntime in the future. They are not 
>>> _that_ useful and there are vastly more useful alternatives. x)
>>
>> And the same is true for segfault-on-null. I don't want this. If a 
>> standard null check can be implemented taking advantage of CPU 
>> features, fine. But semantics should be the same as if the compiler 
>> inserted a branch that throws an error every time a nullable pointer 
>> is dereferenced.
> 
> That's an awful lot of test and branch code being unnecessarily

I don't really care if it is necessary, it is sufficient. If there is a 
better way to get the same result I am fine with that, but for now it 
would be good to simply have a way to stop the bleeding.

> inserted 
> to test-and-throw instead of segfault-and-throw, because that's what a 
> segfault is - a thrown exception.
> ...

Clearly something distinct is happening that skips the scope cleanup.

> 
>> Even better would be the type system just ensuring nullable pointers 
>> are never dereferenced, the OP's experience report notwithstanding. 
>> But I guess this part is a pipe dream for now.
> 
> Have you tried using a template to achieve that?

No.

a) it's impossible due `.init` being forced on you even if you disable 
default construction

b) I am not going to chase down every pointer in every dependency and 
maintain my custom forks of everything including druntime and Phobos

c) build times would likely skyrocket


More information about the Digitalmars-d mailing list