We all get nullability wrong sometimes
Richard (Rikki) Andrew Cattermole
richard at cattermole.co.nz
Thu Jul 9 18:13:14 UTC 2026
On 10/07/2026 3:38 AM, Asadbek wrote:
> On Thursday, 9 July 2026 at 14:33:54 UTC, Richard (Rikki) Andrew
> Cattermole wrote:
>> Here is a nice little showcase of what the fast DFA engine is able to do:
>>
>> ``class IdentExpr``
>>
>> https://github.com/higgsjs/Higgs/blob/master/source/parser/ast.d#L986
>>
>> ```d
>> catchIdent = cast(IdentExpr)parseExpr(input);
>> if (catchIdent is null)
>> throw new ParseError("invalid catch identifier",
>> catchIdent.pos);
>> ```
>>
>> https://github.com/higgsjs/Higgs/blob/master/source/parser/parser.d#L462
>>
>> Anyone notice a slight problem with this code?
>>
>> While a sound static analyser would be nice, being able to catch code
>> like this does mean bugs don't sit around for 10+ years in production
>> code, just waiting to give someone a very bad day.
>>
>> https://github.com/higgsjs/Higgs/issues/219
>
> I have just checked dmd repository and it appears dmd compiler has
> custom data flow analysis optimizations. That is really great!
>
> Is DFA analysis proving that the `catchIdent` is `null` and therefore
> catching what would be a runtime error at compile time ?
I want to clarify something first up, the correct term is Abstract
Interpretation, Data Flow Analysis is an application of Abstract
Interpretation for backend optimizations.
The fast DFA engine isn't actually a DFA, since it has nothing to do
with backends, but might do optimizations via setting flags in the future.
Why did I call it DFA two years ago? That was because I didn't know that
Abstract Interpretation was the correct term, the literature tends to
confuse the two quite heavily and I don't think Walter knew of it either.
There is no point renaming it today, it would just confusing what with
LLM's all about.
To answer your question, yes the fast DFA engine there is catching that
catchIdent is null, and then erroring. Rather than letting it perform a
null dereference at runtime.
But please note that this is occurring in my PR for escape analysis that
I am currently working on.
Principles of Abstract Interpretation is the book I recommend for anyone
interested in learning more of the subject. It is written by the
original 1970's author who created the term.
https://mitpress.mit.edu/9780262044905/principles-of-abstract-interpretation/
More information about the Digitalmars-d
mailing list