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.analysis
Analysis engine for the fast Data Flow Analysis engine.
This module implements the mathematical core of the DFA.
It is responsible for:
- Transfer Functions: Calculating how specific operations (Assign, Math, Equal)
Authors:
License:
Source dfa/fast/analysis.d
Documentation https://dlang.org/phobos/dmd_dfa_fast_analysis.html
- struct
DFAAnalyzer; - The core analyzer that manipulates the Lattice state.This struct provides the overarching join/meet logic, while the specific merge logic is handled in DFAConsequence. It is responsible for:
- Orchestrating the convergence of scopes (calculating the final state after a block exits).
- Managing high-level state transfers between the AST walkers and the internal lattice.
- void
convergeStatementIf(DFALatticeRefcondition, DFAScopeRefscrTrue, DFAScopeRefscrFalse, boolhaveFalseBody, boolunknownBranchTaken, intpredicateNegation); - Merges the states from the True and False branches of an If statement.This handles the "Diamond" control flow pattern.
- It compares the state at the end of the "True" block vs the "False" block.
- It identifies "Gates" (variables used in the condition, e.g., if (ptr)).
- It calculates the union (Join) of the states to determine the state
Parameters:DFALatticeRef conditionThe lattice state of the condition expression. DFAScopeRef scrTrueThe final state of the True scope. DFAScopeRef scrFalseThe final state of the False scope. bool haveFalseBodyTrue if the if-statement has an else block. bool unknownBranchTakenTrue if the condition result is not statically known (Maybe). int predicateNegationState of the predicate negation (0: unknown, 1: negated, 2: not negated). - void
convergeStatementLoopyLabels(DFAScopeRefcontaining, ref Locloc); - Converges a loop or labelled block.Fast-DFA Optimization: Unlike traditional "Slow DFAs" which iterate a loop until the state settles (Fixed Point Iteration), this engine visits the loop body once. To ensure safety without iteration:
- It checks if variables modified in the loop are used inconsistently.
- If a variable is modified in a way that creates uncertainty (e.g., incrementing),
- DFALatticeRef
transferAssign(DFALatticeRefassignTo, boolconstruct, boolisBlit, DFALatticeReflr, intalteredState, ref Locloc, DFALatticeRefindexLR= DFALatticeRef.init); - Updates the state of a variable after an assignment (a = b).This moves the state from the RHS (Right Hand Side) lattice to the LHS (Left Hand Side) variable.
Logic
- Direct Assignment: a = 5 (a becomes 5).
- Pointer Assignment: *p = 5 (We don't change p, we assume memory at p changed).
- Construct: int a = 5 (Initialization).
- DFALatticeRef
transferEqual(DFALatticeReflhs, DFALatticeRefrhs, boolequalityIsTrue, EqualityArgTypeequalityType, boolisIdentity); - See Also:equalityArgTypes
Copyright © 1999-2026 by the D Language Foundation | Page generated by
Ddoc on Wed Aug 5 15:41:17 2026