MIR Definitions
Here we describe definitions of MIR concepts that are relevant to the PCG.
It's possible that these definitions will become outdated as the MIR is not stable. If there is any discrepency between the descriptions here and those from official Rust sources (e.g. the dev guide), this page should be updated accordingly.
MIR Dataflow Analysis
At a high level, a MIR dataflow analysis is defined by the following elements:
- A domain
- A join operation
- An empty state
- A transfer function
Performing the dataflow analysis on a MIR body computes a value of type for every location in . The analysis is performed (conceptually) as follows1:
- The analysis defines a map that maps locations in to elements of .
- Each location in is initialized to
- The operation analyze(b) updates as follows:
- For
- The analysis defines a worklist
- While is not empty:
- Pop from
- Perform
- Let be the entry of the last location in in
- For each successor of :
- Let
- Let
- If :
- Add to
- is the result
I'm not sure of the order things are popped from . Any ordering should yield the same but some blocks may be analyzed more frequently than necessary. We should check the rustc implementation.
-
The current analysis implementation (defined in the rust compiler) is more efficient than what we describe because it tracks state per basic block rather than per-location, as the states for any location in a block can be computed by repeated application of the transfer function to the entry state. ↩