Type state analysis
Walter Bright
newshound2 at digitalmars.com
Fri Mar 29 17:10:54 UTC 2024
The @live functions do type state analysis - data flow analysis is used to
determine if a variable is 'live' or not.
It is indeed costly to do dfa in the front end, that's one reason why it's
restricted to @live functions.
The dfa could be extended for null checking, but in practice, null checking is
not that effective:
```
class C { void xx(); }
struct S { C c; }
C mars(C c) { return null; }
void phobos(ref S s)
{
C c;
c.xx(); // detected
mars(c).xx(); // needs whole program DFA to detect
s.c.xx(); // cannot be detected
}
```
This is why @live functions won't work without scope, ref, and return
annotations on the functions it interfaces with. @live functions, like Rust,
also severely limit the kinds of data structures possible.
Other type state analysis currently done in D is:
1. Value Range Propagation
2. whether a field is initialized or not in a constructor is tracked
More information about the dip.ideas
mailing list