pub struct Map<'tcx> {
locals: IndexVec<Local, Option<PlaceIndex>>,
projections: FxHashMap<(PlaceIndex, TrackElem), PlaceIndex>,
places: IndexVec<PlaceIndex, PlaceInfo<'tcx>>,
value_count: usize,
mode: PlaceCollectionMode,
inner_values: IndexVec<PlaceIndex, Range<usize>>,
inner_values_buffer: Vec<ValueIndex>,
}Expand description
Partial mapping from Place to PlaceIndex, where some places also have a ValueIndex.
This data structure essentially maintains a tree of places and their projections. Some additional bookkeeping is done, to speed up traversal over this tree:
- For iteration, every
PlaceInfocontains an intrusive linked list of its children. - To directly get the child for a specific projection, there is a
projectionsmap.
Fields§
§locals: IndexVec<Local, Option<PlaceIndex>>§projections: FxHashMap<(PlaceIndex, TrackElem), PlaceIndex>§places: IndexVec<PlaceIndex, PlaceInfo<'tcx>>§value_count: usize§mode: PlaceCollectionMode§inner_values: IndexVec<PlaceIndex, Range<usize>>§inner_values_buffer: Vec<ValueIndex>Implementations§
Source§impl<'tcx> Map<'tcx>
impl<'tcx> Map<'tcx>
Sourcepub fn new(
tcx: TyCtxt<'tcx>,
body: &Body<'tcx>,
mode: PlaceCollectionMode,
) -> Self
pub fn new( tcx: TyCtxt<'tcx>, body: &Body<'tcx>, mode: PlaceCollectionMode, ) -> Self
Returns a map that only tracks places whose type has scalar layout.
This is currently the only way to create a Map. The way in which the tracked places are
chosen is an implementation detail and may not be relied upon (other than that their type
are scalars).
Sourcefn register_locals(&mut self, tcx: TyCtxt<'tcx>, body: &Body<'tcx>)
fn register_locals(&mut self, tcx: TyCtxt<'tcx>, body: &Body<'tcx>)
Register all non-excluded places that have scalar layout.
Sourcefn collect_places(&mut self, tcx: TyCtxt<'tcx>, body: &Body<'tcx>)
fn collect_places(&mut self, tcx: TyCtxt<'tcx>, body: &Body<'tcx>)
Collect syntactic places from body, and create PlaceIndex for them.
Sourcefn propagate_assignments(&mut self, tcx: TyCtxt<'tcx>, body: &Body<'tcx>)
fn propagate_assignments(&mut self, tcx: TyCtxt<'tcx>, body: &Body<'tcx>)
Just collecting syntactic places is not enough. We may need to propagate this pattern: _1 = (const 5u32, const 13i64); _2 = _1; _3 = (_2.0 as u32);
_1.0 does not appear, but we still need to track it. This is achieved by propagating
projections from assignments. We recorded an assignment between _2 and _1, so we
want _1 and _2 to have the same sub-places.
Sourcefn create_values(
&mut self,
tcx: TyCtxt<'tcx>,
body: &Body<'tcx>,
value_limit: Option<usize>,
)
fn create_values( &mut self, tcx: TyCtxt<'tcx>, body: &Body<'tcx>, value_limit: Option<usize>, )
Create values for places whose type have scalar layout.
Sourcefn trim_useless_places(&mut self)
fn trim_useless_places(&mut self)
Trim useless places.
pub fn register_place_index( &mut self, ty: Ty<'tcx>, base: PlaceIndex, elem: TrackElem, ) -> PlaceIndex
pub fn register_place( &mut self, tcx: TyCtxt<'tcx>, body: &Body<'tcx>, place: Place<'tcx>, tail: Option<TrackElem>, ) -> Option<PlaceIndex>
fn register_place_and_discr( &mut self, tcx: TyCtxt<'tcx>, body: &Body<'tcx>, place: Place<'tcx>, ) -> Option<PlaceIndex>
pub fn register_value( &mut self, tcx: TyCtxt<'tcx>, typing_env: TypingEnv<'tcx>, place: PlaceIndex, ) -> Option<ValueIndex>
pub fn register_copy_tree( &mut self, source: PlaceIndex, target: PlaceIndex, f: &mut impl FnMut(ValueIndex, ValueIndex), )
Sourcefn cache_preorder_invoke(&mut self, root: PlaceIndex)
fn cache_preorder_invoke(&mut self, root: PlaceIndex)
Precompute the list of values inside root and store it inside
as a slice within inner_values_buffer.
Source§impl<'tcx> Map<'tcx>
impl<'tcx> Map<'tcx>
Sourcepub fn apply(&self, place: PlaceIndex, elem: TrackElem) -> Option<PlaceIndex>
pub fn apply(&self, place: PlaceIndex, elem: TrackElem) -> Option<PlaceIndex>
Applies a single projection element, yielding the corresponding child.
Sourcefn find_extra(
&self,
place: PlaceRef<'_>,
extra: impl IntoIterator<Item = TrackElem>,
) -> Option<PlaceIndex>
fn find_extra( &self, place: PlaceRef<'_>, extra: impl IntoIterator<Item = TrackElem>, ) -> Option<PlaceIndex>
Locates the given place, if it exists in the tree.
Sourcepub fn find(&self, place: PlaceRef<'_>) -> Option<PlaceIndex>
pub fn find(&self, place: PlaceRef<'_>) -> Option<PlaceIndex>
Locates the given place, if it exists in the tree.
Sourcepub fn find_discr(&self, place: PlaceRef<'_>) -> Option<PlaceIndex>
pub fn find_discr(&self, place: PlaceRef<'_>) -> Option<PlaceIndex>
Locates the given place and applies Discriminant, if it exists in the tree.
Sourcepub fn find_len(&self, place: PlaceRef<'_>) -> Option<PlaceIndex>
pub fn find_len(&self, place: PlaceRef<'_>) -> Option<PlaceIndex>
Locates the given place and applies DerefLen, if it exists in the tree.
Sourcepub fn value(&self, place: PlaceIndex) -> Option<ValueIndex>
pub fn value(&self, place: PlaceIndex) -> Option<ValueIndex>
Locates the value corresponding to the given place.
Sourcepub fn find_value(&self, place: PlaceRef<'_>) -> Option<ValueIndex>
pub fn find_value(&self, place: PlaceRef<'_>) -> Option<ValueIndex>
Locates the value corresponding to the given place.
Sourcepub fn find_discr_value(&self, place: PlaceRef<'_>) -> Option<ValueIndex>
pub fn find_discr_value(&self, place: PlaceRef<'_>) -> Option<ValueIndex>
Locates the value corresponding to the given discriminant.
Sourcepub fn find_len_value(&self, place: PlaceRef<'_>) -> Option<ValueIndex>
pub fn find_len_value(&self, place: PlaceRef<'_>) -> Option<ValueIndex>
Locates the value corresponding to the given length.
Sourcefn children(&self, parent: PlaceIndex) -> impl Iterator<Item = PlaceIndex>
fn children(&self, parent: PlaceIndex) -> impl Iterator<Item = PlaceIndex>
Iterate over all direct children.
Sourcepub fn for_each_aliasing_place(
&self,
place: PlaceRef<'_>,
tail_elem: Option<TrackElem>,
f: &mut impl FnMut(ValueIndex),
)
pub fn for_each_aliasing_place( &self, place: PlaceRef<'_>, tail_elem: Option<TrackElem>, f: &mut impl FnMut(ValueIndex), )
Invoke a function on the given place and all places that may alias it.
In particular, when the given place has a variant downcast, we invoke the function on all the other variants.
tail_elem allows to support discriminants that are not a place in MIR, but that we track
as such.
Sourcefn for_each_variant_sibling(
&self,
parent: PlaceIndex,
preserved_child: Option<PlaceIndex>,
f: &mut impl FnMut(ValueIndex),
)
fn for_each_variant_sibling( &self, parent: PlaceIndex, preserved_child: Option<PlaceIndex>, f: &mut impl FnMut(ValueIndex), )
Invoke the given function on all the descendants of the given place, except one branch.
Sourcepub fn values_inside(&self, root: PlaceIndex) -> &[ValueIndex]
pub fn values_inside(&self, root: PlaceIndex) -> &[ValueIndex]
Return the range of value indices inside this place.
Sourcefn for_each_value_inside(
&self,
root: PlaceIndex,
f: &mut impl FnMut(ValueIndex),
)
fn for_each_value_inside( &self, root: PlaceIndex, f: &mut impl FnMut(ValueIndex), )
Invoke a function on each value in the given place and all descendants.
Sourcepub fn for_each_projection_value<O>(
&self,
root: PlaceIndex,
value: O,
project: &mut impl FnMut(TrackElem, &O) -> Option<O>,
f: &mut impl FnMut(PlaceIndex, &O),
)
pub fn for_each_projection_value<O>( &self, root: PlaceIndex, value: O, project: &mut impl FnMut(TrackElem, &O) -> Option<O>, f: &mut impl FnMut(PlaceIndex, &O), )
Invoke a function on each value in the given place and all descendants.
Sourcepub fn for_each_value_pair(
&self,
target: PlaceIndex,
source: PlaceIndex,
f: &mut impl FnMut(ValueIndex, ValueIndex),
)
pub fn for_each_value_pair( &self, target: PlaceIndex, source: PlaceIndex, f: &mut impl FnMut(ValueIndex, ValueIndex), )
Recursively iterates on each value contained in target, paired with matching projection
inside source.
Trait Implementations§
Auto Trait Implementations§
impl<'tcx> DynSend for Map<'tcx>
impl<'tcx> DynSync for Map<'tcx>
impl<'tcx> Freeze for Map<'tcx>
impl<'tcx> !RefUnwindSafe for Map<'tcx>
impl<'tcx> Send for Map<'tcx>
impl<'tcx> Sync for Map<'tcx>
impl<'tcx> Unpin for Map<'tcx>
impl<'tcx> !UnwindSafe for Map<'tcx>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T, R> CollectAndApply<T, R> for T
impl<T, R> CollectAndApply<T, R> for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<P> IntoQueryParam<P> for P
impl<P> IntoQueryParam<P> for P
fn into_query_param(self) -> P
Source§impl<T> MaybeResult<T> for T
impl<T> MaybeResult<T> for T
Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<I, T, U> Upcast<I, U> for Twhere
U: UpcastFrom<I, T>,
impl<I, T, U> Upcast<I, U> for Twhere
U: UpcastFrom<I, T>,
Source§impl<I, T> UpcastFrom<I, T> for T
impl<I, T> UpcastFrom<I, T> for T
fn upcast_from(from: T, _tcx: I) -> T
Source§impl<Tcx, T> Value<Tcx> for Twhere
Tcx: DepContext,
impl<Tcx, T> Value<Tcx> for Twhere
Tcx: DepContext,
default fn from_cycle_error( tcx: Tcx, cycle_error: &CycleError, _guar: ErrorGuaranteed, ) -> T
Source§impl<T> WithSubscriber for T
impl<T> WithSubscriber for T
Source§fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
Source§fn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
impl<T> ErasedDestructor for Twhere
T: 'static,
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: 152 bytes