Why static analysis is the way to go

Walter Bright newshound2 at digitalmars.com
Sat May 30 18:48:08 UTC 2026


On 5/29/2026 8:02 PM, Richard (Rikki) Andrew Cattermole wrote:
> Dmd is inherently first come first served. Ordering matters.
> 
> Swap the order of two declarations and errors can appear and disappear as 
> information is acquired.

Of course. For recursive data structures, the path you take determines the 
result. That's why the DMD optimizer uses DFA to solve the data flow equations 
iteratively. Most of the time, it converges on the solution in only one pass 
through the equations.

The same is true for the front end, which does only one pass. Most of the time, 
it gets it right. When it doesn't get it right, it takes the conservative path 
which does not violate the typing system constraints.

> We've mostly tuned the language to not exhibit these problems by simply being 
> eager, and then you get cyclic and other awful errors.

Yes, you can get cyclic errors like:
```c
struct S
{
     int x = X;
     static if (X)
         enum X = 0;
     else
         enum X = 1;
}
```
Some of these the compiler can diagnose. But in general, coding such things is a 
bad idea.



More information about the Digitalmars-d mailing list