Module stable_mir::mir::visit
source · Expand description
§The Stable MIR Visitor
§Overview
We currently only support an immutable visitor.
The structure of this visitor is similar to the ones internal to rustc
,
and it follows the following conventions:
For every mir item, the trait has a visit_<item>
and a super_<item>
method.
visit_<item>
, by default, callssuper_<item>
super_<item>
, by default, destructures the<item>
and callsvisit_<sub_item>
for all sub-items that compose the original item.
In order to implement a visitor, override the visit_*
methods for the types you are
interested in analyzing, and invoke (within that method call)
self.super_*
to continue to the traverse.
Avoid calling super
methods in other circumstances.
For the most part, we do not destructure things external to the
MIR, e.g., types, spans, etc, but simply visit them and stop.
This avoids duplication with other visitors like TypeFoldable
.
§Updating
The code is written in a very deliberate style intended to minimize the chance of things being overlooked.
Use pattern matching to reference fields and ensure that all matches are exhaustive.
For this to work, ALL MATCHES MUST BE EXHAUSTIVE IN FIELDS AND VARIANTS.
That means you never write ..
to skip over fields, nor do you write _
to skip over variants in a match
.
The only place that _
is acceptable is to match a field (or
variant argument) that does not require visiting.
Structs§
- The location of a statement / terminator in the code and the CFG.
- Information about a place’s usage.
- Reference to a place used to represent a partial projection.
Traits§
Functions§
- Location of the statement at the given index for a given basic block. Assumes that
stmt_idx
andbb_idx
are valid for a given body. - Location of the terminator for a given basic block. Assumes that
bb_idx
is valid for a given body. - This function is a no-op that gets used to ensure this visitor is kept up-to-date.