Examples of DFA
Richard (Rikki) Andrew Cattermole
richard at cattermole.co.nz
Tue Sep 23 20:11:55 UTC 2025
On 24/09/2025 5:54 AM, Walter Bright wrote:
> On 9/23/2025 2:43 AM, Richard (Rikki) Andrew Cattermole wrote:
>> Instead of writing ``@nogc``, we write ``@nogc iff(foo, bar, abc)``.
>>
>> From there its a simple dependency resolver either during the
>> compilation of the three functions or on usage.
>
> It's not so simple when there is recursion in the flow graph.
For @nogc and pure, it is that simple.
Other attributes can't be solved with this solution. They are too
complex, or effect the calling convention of the function.
I don't have a generalized solution.
>> This is the basis for my solution to a problem Adam has proposed for
>> PhobosV3, which essentially is the desire to whitelist attributes. Use
>> ``@localnogc`` & if the function calls are all ``@nogc``, therefore
>> the function is allowed to be ``@nogc``.
>
> I am reluctant to try to fix this issue with even more attributes.
If you don't, you're limited to a single compilation.
Which may be fine for a single module, but might not be cross-module.
>> Am I right to assume that the reason you haven't presented this
>> solution, is because you want attributes to be finalized when bar&abc
>> complete?
>
> I showed the solution to illustrate the requirement for iteration and
> convergence to resolve cycles in the flow graph. A DFA that cannot deal
> with recursion is just going to leave people frustrated, as the current
> @nogc inference engine does.
Indeed. I'd call it an all right example, a better example might be:
```d
void* global;
void thing(T)(scope void* u, T* v) {
global = v;
thing(null, u);
}
```
You can't solve for this without applying outputs into inputs.
Therefore no shortcuts.
More information about the Digitalmars-d
mailing list