stop calling DenseLocationMap
"elements"
"Elements" are `RegionElement`s. The dense location mapping was removed from the element containers a while ago but didn't rename its use-sites. Most of the old naming only used the mapping, and are better named `location_map`.
This commit is contained in:
parent
9c87288a7d
commit
6f1c4177e7
7 changed files with 65 additions and 61 deletions
|
@ -94,7 +94,7 @@ pub(crate) fn compute_regions<'a, 'tcx>(
|
||||||
let mut all_facts =
|
let mut all_facts =
|
||||||
(polonius_input || AllFacts::enabled(infcx.tcx)).then_some(AllFacts::default());
|
(polonius_input || AllFacts::enabled(infcx.tcx)).then_some(AllFacts::default());
|
||||||
|
|
||||||
let elements = Rc::new(DenseLocationMap::new(body));
|
let location_map = Rc::new(DenseLocationMap::new(body));
|
||||||
|
|
||||||
// Run the MIR type-checker.
|
// Run the MIR type-checker.
|
||||||
let MirTypeckResults {
|
let MirTypeckResults {
|
||||||
|
@ -112,7 +112,7 @@ pub(crate) fn compute_regions<'a, 'tcx>(
|
||||||
&mut all_facts,
|
&mut all_facts,
|
||||||
flow_inits,
|
flow_inits,
|
||||||
move_data,
|
move_data,
|
||||||
Rc::clone(&elements),
|
Rc::clone(&location_map),
|
||||||
);
|
);
|
||||||
|
|
||||||
// Create the region inference context, taking ownership of the
|
// Create the region inference context, taking ownership of the
|
||||||
|
@ -137,7 +137,7 @@ pub(crate) fn compute_regions<'a, 'tcx>(
|
||||||
var_infos,
|
var_infos,
|
||||||
constraints,
|
constraints,
|
||||||
universal_region_relations,
|
universal_region_relations,
|
||||||
elements,
|
location_map,
|
||||||
);
|
);
|
||||||
|
|
||||||
// If requested for `-Zpolonius=next`, convert NLL constraints to localized outlives
|
// If requested for `-Zpolonius=next`, convert NLL constraints to localized outlives
|
||||||
|
|
|
@ -396,7 +396,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
|
||||||
var_infos: VarInfos,
|
var_infos: VarInfos,
|
||||||
constraints: MirTypeckRegionConstraints<'tcx>,
|
constraints: MirTypeckRegionConstraints<'tcx>,
|
||||||
universal_region_relations: Frozen<UniversalRegionRelations<'tcx>>,
|
universal_region_relations: Frozen<UniversalRegionRelations<'tcx>>,
|
||||||
elements: Rc<DenseLocationMap>,
|
location_map: Rc<DenseLocationMap>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let universal_regions = &universal_region_relations.universal_regions;
|
let universal_regions = &universal_region_relations.universal_regions;
|
||||||
let MirTypeckRegionConstraints {
|
let MirTypeckRegionConstraints {
|
||||||
|
@ -440,7 +440,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut scc_values =
|
let mut scc_values =
|
||||||
RegionValues::new(elements, universal_regions.len(), placeholder_indices);
|
RegionValues::new(location_map, universal_regions.len(), placeholder_indices);
|
||||||
|
|
||||||
for region in liveness_constraints.regions() {
|
for region in liveness_constraints.regions() {
|
||||||
let scc = constraint_sccs.scc(region);
|
let scc = constraint_sccs.scc(region);
|
||||||
|
|
|
@ -38,7 +38,7 @@ pub(crate) enum RegionElement {
|
||||||
/// an interval matrix storing liveness ranges for each region-vid.
|
/// an interval matrix storing liveness ranges for each region-vid.
|
||||||
pub(crate) struct LivenessValues {
|
pub(crate) struct LivenessValues {
|
||||||
/// The map from locations to points.
|
/// The map from locations to points.
|
||||||
elements: Rc<DenseLocationMap>,
|
location_map: Rc<DenseLocationMap>,
|
||||||
|
|
||||||
/// Which regions are live. This is exclusive with the fine-grained tracking in `points`, and
|
/// Which regions are live. This is exclusive with the fine-grained tracking in `points`, and
|
||||||
/// currently only used for validating promoteds (which don't care about more precise tracking).
|
/// currently only used for validating promoteds (which don't care about more precise tracking).
|
||||||
|
@ -77,11 +77,11 @@ impl LiveLoans {
|
||||||
|
|
||||||
impl LivenessValues {
|
impl LivenessValues {
|
||||||
/// Create an empty map of regions to locations where they're live.
|
/// Create an empty map of regions to locations where they're live.
|
||||||
pub(crate) fn with_specific_points(elements: Rc<DenseLocationMap>) -> Self {
|
pub(crate) fn with_specific_points(location_map: Rc<DenseLocationMap>) -> Self {
|
||||||
LivenessValues {
|
LivenessValues {
|
||||||
live_regions: None,
|
live_regions: None,
|
||||||
points: Some(SparseIntervalMatrix::new(elements.num_points())),
|
points: Some(SparseIntervalMatrix::new(location_map.num_points())),
|
||||||
elements,
|
location_map,
|
||||||
loans: None,
|
loans: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -90,11 +90,11 @@ impl LivenessValues {
|
||||||
///
|
///
|
||||||
/// Unlike `with_specific_points`, does not track exact locations where something is live, only
|
/// Unlike `with_specific_points`, does not track exact locations where something is live, only
|
||||||
/// which regions are live.
|
/// which regions are live.
|
||||||
pub(crate) fn without_specific_points(elements: Rc<DenseLocationMap>) -> Self {
|
pub(crate) fn without_specific_points(location_map: Rc<DenseLocationMap>) -> Self {
|
||||||
LivenessValues {
|
LivenessValues {
|
||||||
live_regions: Some(Default::default()),
|
live_regions: Some(Default::default()),
|
||||||
points: None,
|
points: None,
|
||||||
elements,
|
location_map,
|
||||||
loans: None,
|
loans: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -122,11 +122,11 @@ impl LivenessValues {
|
||||||
|
|
||||||
/// Records `region` as being live at the given `location`.
|
/// Records `region` as being live at the given `location`.
|
||||||
pub(crate) fn add_location(&mut self, region: RegionVid, location: Location) {
|
pub(crate) fn add_location(&mut self, region: RegionVid, location: Location) {
|
||||||
let point = self.elements.point_from_location(location);
|
let point = self.location_map.point_from_location(location);
|
||||||
debug!("LivenessValues::add_location(region={:?}, location={:?})", region, location);
|
debug!("LivenessValues::add_location(region={:?}, location={:?})", region, location);
|
||||||
if let Some(points) = &mut self.points {
|
if let Some(points) = &mut self.points {
|
||||||
points.insert(region, point);
|
points.insert(region, point);
|
||||||
} else if self.elements.point_in_range(point) {
|
} else if self.location_map.point_in_range(point) {
|
||||||
self.live_regions.as_mut().unwrap().insert(region);
|
self.live_regions.as_mut().unwrap().insert(region);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -143,7 +143,7 @@ impl LivenessValues {
|
||||||
debug!("LivenessValues::add_points(region={:?}, points={:?})", region, points);
|
debug!("LivenessValues::add_points(region={:?}, points={:?})", region, points);
|
||||||
if let Some(this) = &mut self.points {
|
if let Some(this) = &mut self.points {
|
||||||
this.union_row(region, points);
|
this.union_row(region, points);
|
||||||
} else if points.iter().any(|point| self.elements.point_in_range(point)) {
|
} else if points.iter().any(|point| self.location_map.point_in_range(point)) {
|
||||||
self.live_regions.as_mut().unwrap().insert(region);
|
self.live_regions.as_mut().unwrap().insert(region);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -170,7 +170,7 @@ impl LivenessValues {
|
||||||
|
|
||||||
/// Returns whether `region` is marked live at the given `location`.
|
/// Returns whether `region` is marked live at the given `location`.
|
||||||
pub(crate) fn is_live_at(&self, region: RegionVid, location: Location) -> bool {
|
pub(crate) fn is_live_at(&self, region: RegionVid, location: Location) -> bool {
|
||||||
let point = self.elements.point_from_location(location);
|
let point = self.location_map.point_from_location(location);
|
||||||
if let Some(points) = &self.points {
|
if let Some(points) = &self.points {
|
||||||
points.row(region).is_some_and(|r| r.contains(point))
|
points.row(region).is_some_and(|r| r.contains(point))
|
||||||
} else {
|
} else {
|
||||||
|
@ -191,25 +191,26 @@ impl LivenessValues {
|
||||||
.row(region)
|
.row(region)
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.flat_map(|set| set.iter())
|
.flat_map(|set| set.iter())
|
||||||
.take_while(|&p| self.elements.point_in_range(p))
|
.take_while(|&p| self.location_map.point_in_range(p))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// For debugging purposes, returns a pretty-printed string of the points where the `region` is
|
/// For debugging purposes, returns a pretty-printed string of the points where the `region` is
|
||||||
/// live.
|
/// live.
|
||||||
pub(crate) fn pretty_print_live_points(&self, region: RegionVid) -> String {
|
pub(crate) fn pretty_print_live_points(&self, region: RegionVid) -> String {
|
||||||
pretty_print_region_elements(
|
pretty_print_region_elements(
|
||||||
self.live_points(region).map(|p| RegionElement::Location(self.elements.to_location(p))),
|
self.live_points(region)
|
||||||
|
.map(|p| RegionElement::Location(self.location_map.to_location(p))),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub(crate) fn point_from_location(&self, location: Location) -> PointIndex {
|
pub(crate) fn point_from_location(&self, location: Location) -> PointIndex {
|
||||||
self.elements.point_from_location(location)
|
self.location_map.point_from_location(location)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub(crate) fn location_from_point(&self, point: PointIndex) -> Location {
|
pub(crate) fn location_from_point(&self, point: PointIndex) -> Location {
|
||||||
self.elements.to_location(point)
|
self.location_map.to_location(point)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// When using `-Zpolonius=next`, returns whether the `loan_idx` is live at the given `point`.
|
/// When using `-Zpolonius=next`, returns whether the `loan_idx` is live at the given `point`.
|
||||||
|
@ -272,7 +273,7 @@ impl PlaceholderIndices {
|
||||||
/// because (since it is returned) it must live for at least `'a`. But
|
/// because (since it is returned) it must live for at least `'a`. But
|
||||||
/// it would also contain various points from within the function.
|
/// it would also contain various points from within the function.
|
||||||
pub(crate) struct RegionValues<N: Idx> {
|
pub(crate) struct RegionValues<N: Idx> {
|
||||||
elements: Rc<DenseLocationMap>,
|
location_map: Rc<DenseLocationMap>,
|
||||||
placeholder_indices: PlaceholderIndices,
|
placeholder_indices: PlaceholderIndices,
|
||||||
points: SparseIntervalMatrix<N, PointIndex>,
|
points: SparseIntervalMatrix<N, PointIndex>,
|
||||||
free_regions: SparseBitMatrix<N, RegionVid>,
|
free_regions: SparseBitMatrix<N, RegionVid>,
|
||||||
|
@ -287,14 +288,14 @@ impl<N: Idx> RegionValues<N> {
|
||||||
/// Each of the regions in num_region_variables will be initialized with an
|
/// Each of the regions in num_region_variables will be initialized with an
|
||||||
/// empty set of points and no causal information.
|
/// empty set of points and no causal information.
|
||||||
pub(crate) fn new(
|
pub(crate) fn new(
|
||||||
elements: Rc<DenseLocationMap>,
|
location_map: Rc<DenseLocationMap>,
|
||||||
num_universal_regions: usize,
|
num_universal_regions: usize,
|
||||||
placeholder_indices: PlaceholderIndices,
|
placeholder_indices: PlaceholderIndices,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let num_points = elements.num_points();
|
let num_points = location_map.num_points();
|
||||||
let num_placeholders = placeholder_indices.len();
|
let num_placeholders = placeholder_indices.len();
|
||||||
Self {
|
Self {
|
||||||
elements,
|
location_map,
|
||||||
points: SparseIntervalMatrix::new(num_points),
|
points: SparseIntervalMatrix::new(num_points),
|
||||||
placeholder_indices,
|
placeholder_indices,
|
||||||
free_regions: SparseBitMatrix::new(num_universal_regions),
|
free_regions: SparseBitMatrix::new(num_universal_regions),
|
||||||
|
@ -336,7 +337,7 @@ impl<N: Idx> RegionValues<N> {
|
||||||
end: usize,
|
end: usize,
|
||||||
) -> Option<usize> {
|
) -> Option<usize> {
|
||||||
let row = self.points.row(r)?;
|
let row = self.points.row(r)?;
|
||||||
let block = self.elements.entry_point(block);
|
let block = self.location_map.entry_point(block);
|
||||||
let start = block.plus(start);
|
let start = block.plus(start);
|
||||||
let end = block.plus(end);
|
let end = block.plus(end);
|
||||||
let first_unset = row.first_unset_in(start..=end)?;
|
let first_unset = row.first_unset_in(start..=end)?;
|
||||||
|
@ -375,8 +376,8 @@ impl<N: Idx> RegionValues<N> {
|
||||||
pub(crate) fn locations_outlived_by<'a>(&'a self, r: N) -> impl Iterator<Item = Location> + 'a {
|
pub(crate) fn locations_outlived_by<'a>(&'a self, r: N) -> impl Iterator<Item = Location> + 'a {
|
||||||
self.points.row(r).into_iter().flat_map(move |set| {
|
self.points.row(r).into_iter().flat_map(move |set| {
|
||||||
set.iter()
|
set.iter()
|
||||||
.take_while(move |&p| self.elements.point_in_range(p))
|
.take_while(move |&p| self.location_map.point_in_range(p))
|
||||||
.map(move |p| self.elements.to_location(p))
|
.map(move |p| self.location_map.to_location(p))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -430,12 +431,12 @@ pub(crate) trait ToElementIndex: Debug + Copy {
|
||||||
|
|
||||||
impl ToElementIndex for Location {
|
impl ToElementIndex for Location {
|
||||||
fn add_to_row<N: Idx>(self, values: &mut RegionValues<N>, row: N) -> bool {
|
fn add_to_row<N: Idx>(self, values: &mut RegionValues<N>, row: N) -> bool {
|
||||||
let index = values.elements.point_from_location(self);
|
let index = values.location_map.point_from_location(self);
|
||||||
values.points.insert(row, index)
|
values.points.insert(row, index)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn contained_in_row<N: Idx>(self, values: &RegionValues<N>, row: N) -> bool {
|
fn contained_in_row<N: Idx>(self, values: &RegionValues<N>, row: N) -> bool {
|
||||||
let index = values.elements.point_from_location(self);
|
let index = values.location_map.point_from_location(self);
|
||||||
values.points.contains(row, index)
|
values.points.contains(row, index)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -464,14 +465,14 @@ impl ToElementIndex for ty::PlaceholderRegion {
|
||||||
|
|
||||||
/// For debugging purposes, returns a pretty-printed string of the given points.
|
/// For debugging purposes, returns a pretty-printed string of the given points.
|
||||||
pub(crate) fn pretty_print_points(
|
pub(crate) fn pretty_print_points(
|
||||||
elements: &DenseLocationMap,
|
location_map: &DenseLocationMap,
|
||||||
points: impl IntoIterator<Item = PointIndex>,
|
points: impl IntoIterator<Item = PointIndex>,
|
||||||
) -> String {
|
) -> String {
|
||||||
pretty_print_region_elements(
|
pretty_print_region_elements(
|
||||||
points
|
points
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.take_while(|&p| elements.point_in_range(p))
|
.take_while(|&p| location_map.point_in_range(p))
|
||||||
.map(|p| elements.to_location(p))
|
.map(|p| location_map.to_location(p))
|
||||||
.map(RegionElement::Location),
|
.map(RegionElement::Location),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -82,7 +82,7 @@ impl<'a> Iterator for AppearancesIter<'a> {
|
||||||
impl LocalUseMap {
|
impl LocalUseMap {
|
||||||
pub(crate) fn build(
|
pub(crate) fn build(
|
||||||
live_locals: &[Local],
|
live_locals: &[Local],
|
||||||
elements: &DenseLocationMap,
|
location_map: &DenseLocationMap,
|
||||||
body: &Body<'_>,
|
body: &Body<'_>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let nones = IndexVec::from_elem(None, &body.local_decls);
|
let nones = IndexVec::from_elem(None, &body.local_decls);
|
||||||
|
@ -101,7 +101,7 @@ impl LocalUseMap {
|
||||||
IndexVec::from_elem(false, &body.local_decls);
|
IndexVec::from_elem(false, &body.local_decls);
|
||||||
live_locals.iter().for_each(|&local| locals_with_use_data[local] = true);
|
live_locals.iter().for_each(|&local| locals_with_use_data[local] = true);
|
||||||
|
|
||||||
LocalUseMapBuild { local_use_map: &mut local_use_map, elements, locals_with_use_data }
|
LocalUseMapBuild { local_use_map: &mut local_use_map, location_map, locals_with_use_data }
|
||||||
.visit_body(body);
|
.visit_body(body);
|
||||||
|
|
||||||
local_use_map
|
local_use_map
|
||||||
|
@ -125,7 +125,7 @@ impl LocalUseMap {
|
||||||
|
|
||||||
struct LocalUseMapBuild<'me> {
|
struct LocalUseMapBuild<'me> {
|
||||||
local_use_map: &'me mut LocalUseMap,
|
local_use_map: &'me mut LocalUseMap,
|
||||||
elements: &'me DenseLocationMap,
|
location_map: &'me DenseLocationMap,
|
||||||
|
|
||||||
// Vector used in `visit_local` to signal which `Local`s do we need
|
// Vector used in `visit_local` to signal which `Local`s do we need
|
||||||
// def/use/drop information on, constructed from `live_locals` (that
|
// def/use/drop information on, constructed from `live_locals` (that
|
||||||
|
@ -147,7 +147,7 @@ impl Visitor<'_> for LocalUseMapBuild<'_> {
|
||||||
DefUse::Use => &mut self.local_use_map.first_use_at[local],
|
DefUse::Use => &mut self.local_use_map.first_use_at[local],
|
||||||
DefUse::Drop => &mut self.local_use_map.first_drop_at[local],
|
DefUse::Drop => &mut self.local_use_map.first_drop_at[local],
|
||||||
};
|
};
|
||||||
let point_index = self.elements.point_from_location(location);
|
let point_index = self.location_map.point_from_location(location);
|
||||||
let appearance_index = self
|
let appearance_index = self
|
||||||
.local_use_map
|
.local_use_map
|
||||||
.appearances
|
.appearances
|
||||||
|
|
|
@ -32,7 +32,7 @@ mod trace;
|
||||||
pub(super) fn generate<'a, 'tcx>(
|
pub(super) fn generate<'a, 'tcx>(
|
||||||
typeck: &mut TypeChecker<'_, 'tcx>,
|
typeck: &mut TypeChecker<'_, 'tcx>,
|
||||||
body: &Body<'tcx>,
|
body: &Body<'tcx>,
|
||||||
elements: &DenseLocationMap,
|
location_map: &DenseLocationMap,
|
||||||
flow_inits: ResultsCursor<'a, 'tcx, MaybeInitializedPlaces<'a, 'tcx>>,
|
flow_inits: ResultsCursor<'a, 'tcx, MaybeInitializedPlaces<'a, 'tcx>>,
|
||||||
move_data: &MoveData<'tcx>,
|
move_data: &MoveData<'tcx>,
|
||||||
) {
|
) {
|
||||||
|
@ -49,7 +49,7 @@ pub(super) fn generate<'a, 'tcx>(
|
||||||
trace::trace(
|
trace::trace(
|
||||||
typeck,
|
typeck,
|
||||||
body,
|
body,
|
||||||
elements,
|
location_map,
|
||||||
flow_inits,
|
flow_inits,
|
||||||
move_data,
|
move_data,
|
||||||
relevant_live_locals,
|
relevant_live_locals,
|
||||||
|
|
|
@ -37,13 +37,13 @@ use crate::type_check::{NormalizeLocation, TypeChecker};
|
||||||
pub(super) fn trace<'a, 'tcx>(
|
pub(super) fn trace<'a, 'tcx>(
|
||||||
typeck: &mut TypeChecker<'_, 'tcx>,
|
typeck: &mut TypeChecker<'_, 'tcx>,
|
||||||
body: &Body<'tcx>,
|
body: &Body<'tcx>,
|
||||||
elements: &DenseLocationMap,
|
location_map: &DenseLocationMap,
|
||||||
flow_inits: ResultsCursor<'a, 'tcx, MaybeInitializedPlaces<'a, 'tcx>>,
|
flow_inits: ResultsCursor<'a, 'tcx, MaybeInitializedPlaces<'a, 'tcx>>,
|
||||||
move_data: &MoveData<'tcx>,
|
move_data: &MoveData<'tcx>,
|
||||||
relevant_live_locals: Vec<Local>,
|
relevant_live_locals: Vec<Local>,
|
||||||
boring_locals: Vec<Local>,
|
boring_locals: Vec<Local>,
|
||||||
) {
|
) {
|
||||||
let local_use_map = &LocalUseMap::build(&relevant_live_locals, elements, body);
|
let local_use_map = &LocalUseMap::build(&relevant_live_locals, location_map, body);
|
||||||
|
|
||||||
// When using `-Zpolonius=next`, compute the set of loans that can reach a given region.
|
// When using `-Zpolonius=next`, compute the set of loans that can reach a given region.
|
||||||
if typeck.tcx().sess.opts.unstable_opts.polonius.is_next_enabled() {
|
if typeck.tcx().sess.opts.unstable_opts.polonius.is_next_enabled() {
|
||||||
|
@ -79,7 +79,7 @@ pub(super) fn trace<'a, 'tcx>(
|
||||||
typeck,
|
typeck,
|
||||||
body,
|
body,
|
||||||
flow_inits,
|
flow_inits,
|
||||||
elements,
|
location_map,
|
||||||
local_use_map,
|
local_use_map,
|
||||||
move_data,
|
move_data,
|
||||||
drop_data: FxIndexMap::default(),
|
drop_data: FxIndexMap::default(),
|
||||||
|
@ -100,7 +100,7 @@ struct LivenessContext<'a, 'typeck, 'b, 'tcx> {
|
||||||
typeck: &'a mut TypeChecker<'typeck, 'tcx>,
|
typeck: &'a mut TypeChecker<'typeck, 'tcx>,
|
||||||
|
|
||||||
/// Defines the `PointIndex` mapping
|
/// Defines the `PointIndex` mapping
|
||||||
elements: &'a DenseLocationMap,
|
location_map: &'a DenseLocationMap,
|
||||||
|
|
||||||
/// MIR we are analyzing.
|
/// MIR we are analyzing.
|
||||||
body: &'a Body<'tcx>,
|
body: &'a Body<'tcx>,
|
||||||
|
@ -149,7 +149,7 @@ struct LivenessResults<'a, 'typeck, 'b, 'tcx> {
|
||||||
|
|
||||||
impl<'a, 'typeck, 'b, 'tcx> LivenessResults<'a, 'typeck, 'b, 'tcx> {
|
impl<'a, 'typeck, 'b, 'tcx> LivenessResults<'a, 'typeck, 'b, 'tcx> {
|
||||||
fn new(cx: LivenessContext<'a, 'typeck, 'b, 'tcx>) -> Self {
|
fn new(cx: LivenessContext<'a, 'typeck, 'b, 'tcx>) -> Self {
|
||||||
let num_points = cx.elements.num_points();
|
let num_points = cx.location_map.num_points();
|
||||||
LivenessResults {
|
LivenessResults {
|
||||||
cx,
|
cx,
|
||||||
defs: BitSet::new_empty(num_points),
|
defs: BitSet::new_empty(num_points),
|
||||||
|
@ -240,7 +240,7 @@ impl<'a, 'typeck, 'b, 'tcx> LivenessResults<'a, 'typeck, 'b, 'tcx> {
|
||||||
.collect()
|
.collect()
|
||||||
};
|
};
|
||||||
|
|
||||||
let live_at = IntervalSet::new(self.cx.elements.num_points());
|
let live_at = IntervalSet::new(self.cx.location_map.num_points());
|
||||||
for (local, local_ty, location) in facts_to_add {
|
for (local, local_ty, location) in facts_to_add {
|
||||||
self.cx.add_drop_live_facts_for(local, local_ty, &[location], &live_at);
|
self.cx.add_drop_live_facts_for(local, local_ty, &[location], &live_at);
|
||||||
}
|
}
|
||||||
|
@ -279,7 +279,7 @@ impl<'a, 'typeck, 'b, 'tcx> LivenessResults<'a, 'typeck, 'b, 'tcx> {
|
||||||
// * Inclusively, the block start
|
// * Inclusively, the block start
|
||||||
// * Exclusively, the previous definition (if it's in this block)
|
// * Exclusively, the previous definition (if it's in this block)
|
||||||
// * Exclusively, the previous live_at setting (an optimization)
|
// * Exclusively, the previous live_at setting (an optimization)
|
||||||
let block_start = self.cx.elements.to_block_start(p);
|
let block_start = self.cx.location_map.to_block_start(p);
|
||||||
let previous_defs = self.defs.last_set_in(block_start..=p);
|
let previous_defs = self.defs.last_set_in(block_start..=p);
|
||||||
let previous_live_at = self.use_live_at.last_set_in(block_start..=p);
|
let previous_live_at = self.use_live_at.last_set_in(block_start..=p);
|
||||||
|
|
||||||
|
@ -303,12 +303,12 @@ impl<'a, 'typeck, 'b, 'tcx> LivenessResults<'a, 'typeck, 'b, 'tcx> {
|
||||||
// terminators of predecessor basic blocks. Push those onto the
|
// terminators of predecessor basic blocks. Push those onto the
|
||||||
// stack so that the next iteration(s) will process them.
|
// stack so that the next iteration(s) will process them.
|
||||||
|
|
||||||
let block = self.cx.elements.to_location(block_start).block;
|
let block = self.cx.location_map.to_location(block_start).block;
|
||||||
self.stack.extend(
|
self.stack.extend(
|
||||||
self.cx.body.basic_blocks.predecessors()[block]
|
self.cx.body.basic_blocks.predecessors()[block]
|
||||||
.iter()
|
.iter()
|
||||||
.map(|&pred_bb| self.cx.body.terminator_loc(pred_bb))
|
.map(|&pred_bb| self.cx.body.terminator_loc(pred_bb))
|
||||||
.map(|pred_loc| self.cx.elements.point_from_location(pred_loc)),
|
.map(|pred_loc| self.cx.location_map.point_from_location(pred_loc)),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -331,7 +331,7 @@ impl<'a, 'typeck, 'b, 'tcx> LivenessResults<'a, 'typeck, 'b, 'tcx> {
|
||||||
|
|
||||||
// Find the drops where `local` is initialized.
|
// Find the drops where `local` is initialized.
|
||||||
for drop_point in self.cx.local_use_map.drops(local) {
|
for drop_point in self.cx.local_use_map.drops(local) {
|
||||||
let location = self.cx.elements.to_location(drop_point);
|
let location = self.cx.location_map.to_location(drop_point);
|
||||||
debug_assert_eq!(self.cx.body.terminator_loc(location.block), location,);
|
debug_assert_eq!(self.cx.body.terminator_loc(location.block), location,);
|
||||||
|
|
||||||
if self.cx.initialized_at_terminator(location.block, mpi)
|
if self.cx.initialized_at_terminator(location.block, mpi)
|
||||||
|
@ -367,7 +367,7 @@ impl<'a, 'typeck, 'b, 'tcx> LivenessResults<'a, 'typeck, 'b, 'tcx> {
|
||||||
debug!(
|
debug!(
|
||||||
"compute_drop_live_points_for_block(mpi={:?}, term_point={:?})",
|
"compute_drop_live_points_for_block(mpi={:?}, term_point={:?})",
|
||||||
self.cx.move_data.move_paths[mpi].place,
|
self.cx.move_data.move_paths[mpi].place,
|
||||||
self.cx.elements.to_location(term_point),
|
self.cx.location_map.to_location(term_point),
|
||||||
);
|
);
|
||||||
|
|
||||||
// We are only invoked with terminators where `mpi` is
|
// We are only invoked with terminators where `mpi` is
|
||||||
|
@ -377,12 +377,15 @@ impl<'a, 'typeck, 'b, 'tcx> LivenessResults<'a, 'typeck, 'b, 'tcx> {
|
||||||
// Otherwise, scan backwards through the statements in the
|
// Otherwise, scan backwards through the statements in the
|
||||||
// block. One of them may be either a definition or use
|
// block. One of them may be either a definition or use
|
||||||
// live point.
|
// live point.
|
||||||
let term_location = self.cx.elements.to_location(term_point);
|
let term_location = self.cx.location_map.to_location(term_point);
|
||||||
debug_assert_eq!(self.cx.body.terminator_loc(term_location.block), term_location,);
|
debug_assert_eq!(self.cx.body.terminator_loc(term_location.block), term_location,);
|
||||||
let block = term_location.block;
|
let block = term_location.block;
|
||||||
let entry_point = self.cx.elements.entry_point(term_location.block);
|
let entry_point = self.cx.location_map.entry_point(term_location.block);
|
||||||
for p in (entry_point..term_point).rev() {
|
for p in (entry_point..term_point).rev() {
|
||||||
debug!("compute_drop_live_points_for_block: p = {:?}", self.cx.elements.to_location(p));
|
debug!(
|
||||||
|
"compute_drop_live_points_for_block: p = {:?}",
|
||||||
|
self.cx.location_map.to_location(p)
|
||||||
|
);
|
||||||
|
|
||||||
if self.defs.contains(p) {
|
if self.defs.contains(p) {
|
||||||
debug!("compute_drop_live_points_for_block: def site");
|
debug!("compute_drop_live_points_for_block: def site");
|
||||||
|
@ -428,7 +431,7 @@ impl<'a, 'typeck, 'b, 'tcx> LivenessResults<'a, 'typeck, 'b, 'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
let pred_term_loc = self.cx.body.terminator_loc(pred_block);
|
let pred_term_loc = self.cx.body.terminator_loc(pred_block);
|
||||||
let pred_term_point = self.cx.elements.point_from_location(pred_term_loc);
|
let pred_term_point = self.cx.location_map.point_from_location(pred_term_loc);
|
||||||
|
|
||||||
// If the terminator of this predecessor either *assigns*
|
// If the terminator of this predecessor either *assigns*
|
||||||
// our value or is a "normal use", then stop.
|
// our value or is a "normal use", then stop.
|
||||||
|
@ -523,7 +526,7 @@ impl<'tcx> LivenessContext<'_, '_, '_, 'tcx> {
|
||||||
/// points `live_at`.
|
/// points `live_at`.
|
||||||
fn add_use_live_facts_for(&mut self, value: Ty<'tcx>, live_at: &IntervalSet<PointIndex>) {
|
fn add_use_live_facts_for(&mut self, value: Ty<'tcx>, live_at: &IntervalSet<PointIndex>) {
|
||||||
debug!("add_use_live_facts_for(value={:?})", value);
|
debug!("add_use_live_facts_for(value={:?})", value);
|
||||||
Self::make_all_regions_live(self.elements, self.typeck, value, live_at);
|
Self::make_all_regions_live(self.location_map, self.typeck, value, live_at);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Some variable with type `live_ty` is "drop live" at `location`
|
/// Some variable with type `live_ty` is "drop live" at `location`
|
||||||
|
@ -547,7 +550,7 @@ impl<'tcx> LivenessContext<'_, '_, '_, 'tcx> {
|
||||||
dropped_local,
|
dropped_local,
|
||||||
dropped_ty,
|
dropped_ty,
|
||||||
drop_locations,
|
drop_locations,
|
||||||
values::pretty_print_points(self.elements, live_at.iter()),
|
values::pretty_print_points(self.location_map, live_at.iter()),
|
||||||
);
|
);
|
||||||
|
|
||||||
let drop_data = self.drop_data.entry(dropped_ty).or_insert_with({
|
let drop_data = self.drop_data.entry(dropped_ty).or_insert_with({
|
||||||
|
@ -574,7 +577,7 @@ impl<'tcx> LivenessContext<'_, '_, '_, 'tcx> {
|
||||||
// All things in the `outlives` array may be touched by
|
// All things in the `outlives` array may be touched by
|
||||||
// the destructor and must be live at this point.
|
// the destructor and must be live at this point.
|
||||||
for &kind in &drop_data.dropck_result.kinds {
|
for &kind in &drop_data.dropck_result.kinds {
|
||||||
Self::make_all_regions_live(self.elements, self.typeck, kind, live_at);
|
Self::make_all_regions_live(self.location_map, self.typeck, kind, live_at);
|
||||||
polonius::legacy::emit_drop_facts(
|
polonius::legacy::emit_drop_facts(
|
||||||
self.typeck.tcx(),
|
self.typeck.tcx(),
|
||||||
dropped_local,
|
dropped_local,
|
||||||
|
@ -586,7 +589,7 @@ impl<'tcx> LivenessContext<'_, '_, '_, 'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn make_all_regions_live(
|
fn make_all_regions_live(
|
||||||
elements: &DenseLocationMap,
|
location_map: &DenseLocationMap,
|
||||||
typeck: &mut TypeChecker<'_, 'tcx>,
|
typeck: &mut TypeChecker<'_, 'tcx>,
|
||||||
value: impl TypeVisitable<TyCtxt<'tcx>> + Relate<TyCtxt<'tcx>>,
|
value: impl TypeVisitable<TyCtxt<'tcx>> + Relate<TyCtxt<'tcx>>,
|
||||||
live_at: &IntervalSet<PointIndex>,
|
live_at: &IntervalSet<PointIndex>,
|
||||||
|
@ -594,7 +597,7 @@ impl<'tcx> LivenessContext<'_, '_, '_, 'tcx> {
|
||||||
debug!("make_all_regions_live(value={:?})", value);
|
debug!("make_all_regions_live(value={:?})", value);
|
||||||
debug!(
|
debug!(
|
||||||
"make_all_regions_live: live_at={}",
|
"make_all_regions_live: live_at={}",
|
||||||
values::pretty_print_points(elements, live_at.iter()),
|
values::pretty_print_points(location_map, live_at.iter()),
|
||||||
);
|
);
|
||||||
|
|
||||||
value.visit_with(&mut for_liveness::FreeRegionsVisitor {
|
value.visit_with(&mut for_liveness::FreeRegionsVisitor {
|
||||||
|
|
|
@ -103,7 +103,7 @@ mod relate_tys;
|
||||||
/// - `all_facts` -- when using Polonius, this is the generated set of Polonius facts
|
/// - `all_facts` -- when using Polonius, this is the generated set of Polonius facts
|
||||||
/// - `flow_inits` -- results of a maybe-init dataflow analysis
|
/// - `flow_inits` -- results of a maybe-init dataflow analysis
|
||||||
/// - `move_data` -- move-data constructed when performing the maybe-init dataflow analysis
|
/// - `move_data` -- move-data constructed when performing the maybe-init dataflow analysis
|
||||||
/// - `elements` -- MIR region map
|
/// - `location_map` -- map between MIR `Location` and `PointIndex`
|
||||||
pub(crate) fn type_check<'a, 'tcx>(
|
pub(crate) fn type_check<'a, 'tcx>(
|
||||||
infcx: &BorrowckInferCtxt<'tcx>,
|
infcx: &BorrowckInferCtxt<'tcx>,
|
||||||
body: &Body<'tcx>,
|
body: &Body<'tcx>,
|
||||||
|
@ -114,13 +114,13 @@ pub(crate) fn type_check<'a, 'tcx>(
|
||||||
all_facts: &mut Option<AllFacts>,
|
all_facts: &mut Option<AllFacts>,
|
||||||
flow_inits: ResultsCursor<'a, 'tcx, MaybeInitializedPlaces<'a, 'tcx>>,
|
flow_inits: ResultsCursor<'a, 'tcx, MaybeInitializedPlaces<'a, 'tcx>>,
|
||||||
move_data: &MoveData<'tcx>,
|
move_data: &MoveData<'tcx>,
|
||||||
elements: Rc<DenseLocationMap>,
|
location_map: Rc<DenseLocationMap>,
|
||||||
) -> MirTypeckResults<'tcx> {
|
) -> MirTypeckResults<'tcx> {
|
||||||
let implicit_region_bound = ty::Region::new_var(infcx.tcx, universal_regions.fr_fn_body);
|
let implicit_region_bound = ty::Region::new_var(infcx.tcx, universal_regions.fr_fn_body);
|
||||||
let mut constraints = MirTypeckRegionConstraints {
|
let mut constraints = MirTypeckRegionConstraints {
|
||||||
placeholder_indices: PlaceholderIndices::default(),
|
placeholder_indices: PlaceholderIndices::default(),
|
||||||
placeholder_index_to_region: IndexVec::default(),
|
placeholder_index_to_region: IndexVec::default(),
|
||||||
liveness_constraints: LivenessValues::with_specific_points(Rc::clone(&elements)),
|
liveness_constraints: LivenessValues::with_specific_points(Rc::clone(&location_map)),
|
||||||
outlives_constraints: OutlivesConstraintSet::default(),
|
outlives_constraints: OutlivesConstraintSet::default(),
|
||||||
member_constraints: MemberConstraintSet::default(),
|
member_constraints: MemberConstraintSet::default(),
|
||||||
type_tests: Vec::default(),
|
type_tests: Vec::default(),
|
||||||
|
@ -180,7 +180,7 @@ pub(crate) fn type_check<'a, 'tcx>(
|
||||||
typeck.equate_inputs_and_outputs(body, &normalized_inputs_and_output);
|
typeck.equate_inputs_and_outputs(body, &normalized_inputs_and_output);
|
||||||
typeck.check_signature_annotation(body);
|
typeck.check_signature_annotation(body);
|
||||||
|
|
||||||
liveness::generate(&mut typeck, body, &elements, flow_inits, move_data);
|
liveness::generate(&mut typeck, body, &location_map, flow_inits, move_data);
|
||||||
|
|
||||||
let opaque_type_values =
|
let opaque_type_values =
|
||||||
opaque_types::take_opaques_and_register_member_constraints(&mut typeck);
|
opaque_types::take_opaques_and_register_member_constraints(&mut typeck);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue