1 day ago
A DFA that only works with a forward pass will generate a lot of complaints as people get baffled by the situations where it fails.

The forward pass attribute inference D has generates complaints and bug reports when it fails, because it does not handle cycles.
1 day ago
On 9/13/2025 8:42 PM, Richard (Rikki) Andrew Cattermole wrote:
> The linked code is not static if, its a regular if.

I know. I was trying to clarify the difference between regular if and static if.
1 day ago
On 15/09/2025 7:55 AM, Walter Bright wrote:
> A DFA that only works with a forward pass will generate a lot of complaints as people get baffled by the situations where it fails.
> 
> The forward pass attribute inference D has generates complaints and bug reports when it fails, because it does not handle cycles.

Oh I see where you're thinking.

Okay, consider the following reports, does any report (or lack thereof) suggest people are going to be baffled by it?

Relevant files (start.d for reports source code, out.txt for full log):

https://gist.github.com/rikkimax/652f96a33934bd8ae0a68fb849821385#file-start-d

```
start.d
testdfa\start.d(236): Error: Variable `ptr` was required to be non-null and has become null
    foreach (i; 0 .. 2)
    ^
testdfa\start.d(257): Error: Variable `ptr` was required to be non-null and has become null
    foreach (i; 0 .. 2)
    ^
testdfa\start.d(308): Error: Dereference on null variable `ptr`
        int v = *ptr; // error
                ^
testdfa\start.d(330): Error: Dereference on null variable `ptr`
        int v = *ptr; // error
                ^
testdfa\start.d(613): Error: Assert can be proven to be false
    assert(val); // Error: val is 0
           ^
testdfa\start.d(619): Error: Assert can be proven to be false
    assert(stack.length == 1); // Error: stack is null
                        ^
testdfa\start.d(673): Error: Dereference on null variable `ptr`
        return *ptr; // error could be null
               ^
testdfa\start.d(703): Error: Assert can be proven to be false
        assert(ptr !is null); // error
                   ^
extracted.d
```

Worth looking at extracted.d and the full log.
20 hours ago
On 14/09/2025 7:58 AM, kdevel wrote:
> On Saturday, 13 September 2025 at 15:43:27 UTC, Richard (Rikki) Andrew Cattermole wrote:
>> [...]
>>> I thought that the intent of the original code
>>>
>>> ```d
>>> int* ptr;
>>>
>>> void func(bool b, scope int* p) @safe {
>>>    assert(!b);
>>>
>>>    if (b) {
>>>      ptr = p; // Error: scope variable `p` assigned to global variable `ptr`
>>>    }
>>> }
>>> ```
>>>
>>> was to show that there is some code-block
>>>
>>> ```d
>>>      ptr = p; // Error: scope variable `p` assigned to global variable `ptr`
>>> ```
>>>
>>> which is never executed regardless of the value of `b`.
>>
>> Half right.
>>
>> There is a code block that will never be executed, it is because of variable b's state is known to prevent that code block from execution.
> 
> Then it is dead code that should be manually removed? Isn't that the problem here? The compiler correctly complains about invalid code, this is not a false positive, even if that code is never executed.
> 
> If I want code not to be executed I comment it out or delete it.

In practice, when this is applied people don't complain about it.

https://github.com/dlang/dmd/issues/21859

Compiles with full D, but not -betterC (which does the extra check without the culling which is a bug).

```d
void func() nothrow {
    if (0) {
     	 throw new Exception("");  // Error: cannot use `throw` statements with -betterC
    }
}
```

When both DFA and Control Flow graph (CFG) processing is working correctly its a well loved compiler feature. You don't know its there unless something has gone wrong like in the above code.

When I learned how nothrow inference worked I was really impressed with how it was applying CFG analysis. I did not expect the frontend to be doing it.

6 hours ago

I wasn't entirely sure which post to respond to because I needed Rikki's examples, but this response is for Walter.

On Monday, 15 September 2025 at 01:26:31 UTC, Richard (Rikki) Andrew Cattermole wrote:

>
start.d
testdfa\start.d(236): Error: Variable `ptr` was required to be non-null and has become null
    foreach (i; 0 .. 2)
    ^
testdfa\start.d(330): Error: Dereference on null variable `ptr`
        int v = *ptr; // error
                ^
extracted.d

C# has both of the above errors (as warnings) enabled by default.

Walter, the twin assertions that the above errors will be confusing to programmer, and that they will slow down the compiler are entirely false. Millions of programmers every day see messages very similar to those in C# compiler outputs they will know exactly what is meant.

Furthermore, C# is renowned for it's speed. I just built a 250kLOC project in less than one second.

Here is examples of C#'s DFA in action:

Main.xaml.cs(530,22,530,24): warning CS0168: The variable 'ex' is declared but never used

Customers.cs(26,37,26,53): warning CS0649: Field 'Customers.customersService' is never assigned to, and will always have its default value null

DataUploadController.cs(41,46,41,54): warning CS0169: The field 'DataUploadController.resolver' is never used

The VB.NET compiler also has DFA and is equally as fast (they share codebases):

WorkOrderDirectory.vb(26,13): warning BC42024: Unused local variable: 'J'.

The above are all real world examples from the code base that I just rebuilt.

There is no rule that states that DFA must be slow as there exist examples disproving the assertion.

1 2 3
Next ›   Last »