Examples of DFA
Walter Bright
newshound2 at digitalmars.com
Tue Sep 23 05:54:00 UTC 2025
This is what I am talking about:
```
@nogc void foo() { bar(); }
void bar() { abc(); }
void abc() { bar(); }
```
Both bar() and abc() are @nogc. But the forward-only checking cannot deduce it,
and the result is:
test.d(3): Error: `@nogc` function `test.foo` cannot call non- at nogc function
`test.bar`
This is the simplest version of this problem. It can be quite complex, but the
result is the same - it cannot be figured out without solving recursive data
flow equations.
Another version of the problem:
```
@nogc void foo() { bar(); }
void bar() { abc(); }
void abc();
```
The body of abc() is not available to the compiler, so the compiler cannot
deduce @nogc for abc(). So, in order to deduce attributes of abc(), the compiler
must have the source code available for it. To do a complete job, then, requires
compilation of the entire program's code base. Which will require a lot of
memory and time.
Adam, Rikki, if I'm wrong, please show me how.
More information about the Digitalmars-d
mailing list