Report a bug
If you spot a problem with this page, click here to create a Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using a local clone.

dmd.dfa.fast.structure

Structure and representation of the fast Data Flow Analysis engine.
struct DFACommon;
The central context for a DFA run.
This structure manages the memory allocator, holds references to global variables (like return values), and tracks the current scope being analyzed.
Performance Note: It uses a custom DFAAllocator (bump-pointer allocator) to avoid the overhead of the GC or standard malloc for the thousands of tiny nodes created during analysis.
struct DFAVar;
Represents the identity of a variable being tracked.
This does NOT store the current value of the variable (that changes depending on where you are in the code). Instead, it stores immutable properties like:
  • Is it a boolean? (isBoolean)
  • Can it be null? (isNullable)
  • Is it a reference to another variable? (base1, indexVar)
Think of this as the "Key" in a map, where the "Value" is the DFALattice.
void walkRoots(scope void delegate(DFAVar* var) del);
Finds the root variables for this one, where base1 is null
void walkToRoot(scope void delegate(DFAVar* var) del);
Walk all variables that end up at a root
void visitFirstBase(scope void delegate(DFAVar* var) del);
Visit the base1 and base2 if present
void visitIfReferenceToAnotherVar(scope void delegate(DFAVar* var) del);
If this variable is a reference to another variable, visit the base variable.
void visitReferenceToAnotherVar(scope void delegate(DFAVar* var) hasIndirection, scope void delegate(DFAVar* var) noIndirection = null);
If this variable is a reference to another, takes into account dereferencing.
void visitIfReadOfReferenceToAnotherVar(scope void delegate(DFAVar* var) resolvedIndirection);
If this variable is a reference to another, takes into account dereferencing.
struct DFAScope;
Represents a specific region of code execution (a scope).
As the DFA walks through the code, it pushes and pops scopes. Each scope holds a table (buckets) of the current state of variables within that block.
When the analysis branches (e.g., inside an if), a new child scope is created to track the state changes specific to that branch.
struct DFALattice;
The collection of values and facts known about a variable.
A DFALattice contains one or more DFAConsequence nodes. Each DFAConsequence represents the state of a variable at the current point in time.
void walkMaybeTops(scope bool delegate(DFAConsequence*) del);
DFAConsequence.maybeTopSeen will be set on the DFAConsequence if it was visited
void cleanupConstant(DFAVar* contextVar);
Remove constant if not context
struct DFAConsequence;
A specific fact known about a variable at the current point in time.
Examples of consequences:
  • "This variable is definitely not null" (nullable == NonNull)
  • "This variable is True" (truthiness == True)
  • "This variable has the integer value 5" (pa - Point Analysis)