Struct rustc_typeck::check::generator_interior::drop_ranges::DropRangesBuilder
source · [−]struct DropRangesBuilder {
nodes: IndexVec<PostOrderId, NodeInfo>,
tracked_value_map: FxHashMap<TrackedValue, TrackedValueIndex>,
deferred_edges: Vec<(PostOrderId, HirId)>,
post_order_map: HirIdMap<PostOrderId>,
}Expand description
Tracks information needed to compute drop ranges.
Fields
nodes: IndexVec<PostOrderId, NodeInfo>The core of DropRangesBuilder is a set of nodes, which each represent one expression. We primarily refer to them by their index in a post-order traversal of the HIR tree, since this is what generator_interior uses to talk about yield positions.
This IndexVec keeps the relevant details for each node. See the NodeInfo struct for more details, but this information includes things such as the set of control-flow successors, which variables are dropped or reinitialized, and whether each variable has been inferred to be known-dropped or potentially reintiialized at each point.
tracked_value_map: FxHashMap<TrackedValue, TrackedValueIndex>We refer to values whose drop state we are tracking by the HirId of where they are defined. Within a NodeInfo, however, we store the drop-state in a bit vector indexed by a HirIdIndex (see NodeInfo::drop_state). The hir_id_map field stores the mapping from HirIds to the HirIdIndex that is used to represent that value in bitvector.
deferred_edges: Vec<(PostOrderId, HirId)>When building the control flow graph, we don’t always know the post-order index of the target node at the point we encounter it. For example, this happens with break and continue. In those cases, we store a pair of the PostOrderId of the source and the HirId of the target. Once we have gathered all of these edges, we make a pass over the set of deferred edges (see process_deferred_edges in cfg_build.rs), look up the PostOrderId for the target (since now the post-order index for all nodes is known), and add missing control flow edges.
post_order_map: HirIdMap<PostOrderId>This maps HirIds of expressions to their post-order index. It is used in process_deferred_edges to correctly add back-edges.
Implementations
sourceimpl DropRangesBuilder
impl DropRangesBuilder
fn new(
tracked_values: impl Iterator<Item = TrackedValue>,
hir: Map<'_>,
num_exprs: usize
) -> Self
fn tracked_value_index(&self, tracked_value: TrackedValue) -> TrackedValueIndex
sourcefn add_node_mapping(&mut self, node_hir_id: HirId, post_order_id: PostOrderId)
fn add_node_mapping(&mut self, node_hir_id: HirId, post_order_id: PostOrderId)
Adds an entry in the mapping from HirIds to PostOrderIds
Needed so that add_control_edge_hir_id can work.
sourcefn add_control_edge_hir_id(&mut self, from: PostOrderId, to: HirId)
fn add_control_edge_hir_id(&mut self, from: PostOrderId, to: HirId)
Like add_control_edge, but uses a hir_id as the target.
This can be used for branches where we do not know the PostOrderId of the target yet,
such as when handling break or continue.
fn drop_at(&mut self, value: TrackedValue, location: PostOrderId)
fn reinit_at(&mut self, value: TrackedValue, location: PostOrderId)
sourcefn process_deferred_edges(&mut self)
fn process_deferred_edges(&mut self)
Looks up PostOrderId for any control edges added by HirId and adds a proper edge for them.
Should be called after visiting the HIR but before solving the control flow, otherwise some edges will be missed.
sourceimpl DropRangesBuilder
impl DropRangesBuilder
pub fn propagate_to_fixpoint(&mut self)
fn compute_predecessors(&self) -> IndexVec<PostOrderId, Vec<PostOrderId>>
sourceimpl DropRangesBuilder
impl DropRangesBuilder
DropRanges keeps track of what values are definitely dropped at each point in the code.
Values of interest are defined by the hir_id of their place. Locations in code are identified by their index in the post-order traversal. At its core, DropRanges maps (hir_id, post_order_id) -> bool, where a true value indicates that the value is definitely dropped at the point of the node identified by post_order_id.
sourcefn num_values(&self) -> usize
fn num_values(&self) -> usize
Returns the number of values (hir_ids) that are tracked
fn node_mut(&mut self, id: PostOrderId) -> &mut NodeInfo
fn add_control_edge(&mut self, from: PostOrderId, to: PostOrderId)
Trait Implementations
sourceimpl Debug for DropRangesBuilder
impl Debug for DropRangesBuilder
sourceimpl<'a> GraphWalk<'a> for DropRangesBuilder
impl<'a> GraphWalk<'a> for DropRangesBuilder
type Node = PostOrderId
type Edge = (PostOrderId, PostOrderId)
sourceimpl<'a> Labeller<'a> for DropRangesBuilder
impl<'a> Labeller<'a> for DropRangesBuilder
type Node = PostOrderId
type Edge = (PostOrderId, PostOrderId)
sourcefn node_id(&'a self, n: &Self::Node) -> Id<'a>
fn node_id(&'a self, n: &Self::Node) -> Id<'a>
Maps n to a unique identifier with respect to self. The
implementor is responsible for ensuring that the returned name
is a valid DOT identifier. Read more
sourcefn node_label(&'a self, n: &Self::Node) -> LabelText<'a>
fn node_label(&'a self, n: &Self::Node) -> LabelText<'a>
Maps n to a label that will be used in the rendered output.
The label need not be unique, and may be the empty string; the
default is just the output from node_id. Read more
sourcefn node_shape(&'a self, _node: &Self::Node) -> Option<LabelText<'a>>
fn node_shape(&'a self, _node: &Self::Node) -> Option<LabelText<'a>>
Maps n to one of the graphviz shape names. If None
is returned, no shape attribute is specified. Read more
sourcefn edge_label(&'a self, _e: &Self::Edge) -> LabelText<'a>
fn edge_label(&'a self, _e: &Self::Edge) -> LabelText<'a>
Maps e to a label that will be used in the rendered output.
The label need not be unique, and may be the empty string; the
default is in fact the empty string. Read more
sourcefn node_style(&'a self, _n: &Self::Node) -> Style
fn node_style(&'a self, _n: &Self::Node) -> Style
Maps n to a style that will be used in the rendered output.
sourcefn edge_style(&'a self, _e: &Self::Edge) -> Style
fn edge_style(&'a self, _e: &Self::Edge) -> Style
Maps e to a style that will be used in the rendered output.
Auto Trait Implementations
impl RefUnwindSafe for DropRangesBuilder
impl Send for DropRangesBuilder
impl Sync for DropRangesBuilder
impl Unpin for DropRangesBuilder
impl UnwindSafe for DropRangesBuilder
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<'a, T> Captures<'a> for T where
T: ?Sized,
Layout
Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference’s “Type Layout” chapter for details on type layout guarantees.
Size: 112 bytes