nll: remove NllLivenessMap from LivenessContext

It was used in `compute_for_all_locals` to iterate only the `Local`s that need
liveness analysis (filtered through `compute`). Instead, explicitly extract that
reduced set (as `live_locals`) in `trace` and pass it to
`compute_for_all_locals`.

Change the variable type used in `compute_for_all_locals` from `LiveVar` to
`Local` and do the same for its helper functions (and the functions in
`LocalUseMap` they rely on):

* `add_defs_for`                 -> `LocalUseMap::defs`
* `compute_use_live_points_for`  -> `LocalUseMap::uses`
* `compute_drop_live_points_for` -> `LocalUseMap::drops`

Push back the use of `LiveVar` to the `LocalUseMap` (where the other
`NllLivenessMap` remains embedded) functions which internally do the
`from_local` conversion.
This commit is contained in:
Lucas Molas 2019-02-14 21:33:31 -03:00
parent a9410cd1af
commit 200bc02a5e
2 changed files with 27 additions and 32 deletions

View file

@ -73,18 +73,21 @@ impl LocalUseMap<'me> {
local_use_map
}
crate fn defs(&self, local: LiveVar) -> impl Iterator<Item = PointIndex> + '_ {
vll::iter(self.first_def_at[local], &self.appearances)
crate fn defs(&self, local: Local) -> impl Iterator<Item = PointIndex> + '_ {
let live_var = self.liveness_map.from_local(local).unwrap();
vll::iter(self.first_def_at[live_var], &self.appearances)
.map(move |aa| self.appearances[aa].point_index)
}
crate fn uses(&self, local: LiveVar) -> impl Iterator<Item = PointIndex> + '_ {
vll::iter(self.first_use_at[local], &self.appearances)
crate fn uses(&self, local: Local) -> impl Iterator<Item = PointIndex> + '_ {
let live_var = self.liveness_map.from_local(local).unwrap();
vll::iter(self.first_use_at[live_var], &self.appearances)
.map(move |aa| self.appearances[aa].point_index)
}
crate fn drops(&self, local: LiveVar) -> impl Iterator<Item = PointIndex> + '_ {
vll::iter(self.first_drop_at[local], &self.appearances)
crate fn drops(&self, local: Local) -> impl Iterator<Item = PointIndex> + '_ {
let live_var = self.liveness_map.from_local(local).unwrap();
vll::iter(self.first_drop_at[live_var], &self.appearances)
.map(move |aa| self.appearances[aa].point_index)
}
}

View file

@ -1,13 +1,12 @@
use crate::borrow_check::location::LocationTable;
use crate::borrow_check::nll::region_infer::values::{self, PointIndex, RegionValueElements};
use crate::borrow_check::nll::type_check::liveness::liveness_map::{LiveVar, NllLivenessMap};
use crate::borrow_check::nll::type_check::liveness::liveness_map::NllLivenessMap;
use crate::borrow_check::nll::type_check::liveness::local_use_map::LocalUseMap;
use crate::borrow_check::nll::type_check::NormalizeLocation;
use crate::borrow_check::nll::type_check::TypeChecker;
use crate::dataflow::move_paths::indexes::MovePathIndex;
use crate::dataflow::move_paths::MoveData;
use crate::dataflow::{FlowAtLocation, FlowsAtLocation, MaybeInitializedPlaces};
use crate::util::liveness::LiveVariableMap;
use rustc::infer::canonical::QueryRegionConstraint;
use rustc::mir::{BasicBlock, ConstraintCategory, Local, Location, Mir};
use rustc::traits::query::dropck_outlives::DropckOutlivesResult;
@ -56,12 +55,12 @@ pub(super) fn trace(
elements,
local_use_map,
move_data,
liveness_map,
drop_data: FxHashMap::default(),
location_table,
};
LivenessResults::new(cx).compute_for_all_locals();
let live_locals: Vec<Local> = liveness_map.to_local.clone().into_iter().collect();
LivenessResults::new(cx).compute_for_all_locals(live_locals);
}
/// Contextual state for the type-liveness generator.
@ -95,9 +94,6 @@ where
/// dropped.
local_use_map: &'me LocalUseMap<'me>,
/// Map tracking which variables need liveness computation.
liveness_map: &'me NllLivenessMap,
/// Maps between a MIR Location and a LocationIndex
location_table: &'me LocationTable,
}
@ -148,15 +144,12 @@ impl LivenessResults<'me, 'typeck, 'flow, 'gcx, 'tcx> {
}
}
fn compute_for_all_locals(&mut self) {
for live_local in self.cx.liveness_map.to_local.indices() {
let local = self.cx.liveness_map.from_live_var(live_local);
debug!("local={:?} live_local={:?}", local, live_local);
fn compute_for_all_locals(&mut self, live_locals: Vec<Local>) {
for local in live_locals {
self.reset_local_state();
self.add_defs_for(live_local);
self.compute_use_live_points_for(live_local);
self.compute_drop_live_points_for(live_local);
self.add_defs_for(local);
self.compute_use_live_points_for(local);
self.compute_drop_live_points_for(local);
let local_ty = self.cx.mir.local_decls[local].ty;
@ -185,8 +178,8 @@ impl LivenessResults<'me, 'typeck, 'flow, 'gcx, 'tcx> {
}
/// Adds the definitions of `local` into `self.defs`.
fn add_defs_for(&mut self, live_local: LiveVar) {
for def in self.cx.local_use_map.defs(live_local) {
fn add_defs_for(&mut self, local: Local) {
for def in self.cx.local_use_map.defs(local) {
debug!("- defined at {:?}", def);
self.defs.insert(def);
}
@ -194,14 +187,14 @@ impl LivenessResults<'me, 'typeck, 'flow, 'gcx, 'tcx> {
/// Computes all points where local is "use live" -- meaning its
/// current value may be used later (except by a drop). This is
/// done by walking backwards from each use of `live_local` until we
/// done by walking backwards from each use of `local` until we
/// find a `def` of local.
///
/// Requires `add_defs_for(live_local)` to have been executed.
fn compute_use_live_points_for(&mut self, live_local: LiveVar) {
debug!("compute_use_live_points_for(live_local={:?})", live_local);
/// Requires `add_defs_for(local)` to have been executed.
fn compute_use_live_points_for(&mut self, local: Local) {
debug!("compute_use_live_points_for(local={:?})", local);
self.stack.extend(self.cx.local_use_map.uses(live_local));
self.stack.extend(self.cx.local_use_map.uses(local));
while let Some(p) = self.stack.pop() {
if self.defs.contains(p) {
continue;
@ -224,15 +217,14 @@ impl LivenessResults<'me, 'typeck, 'flow, 'gcx, 'tcx> {
///
/// Requires `compute_use_live_points_for` and `add_defs_for` to
/// have been executed.
fn compute_drop_live_points_for(&mut self, live_local: LiveVar) {
debug!("compute_drop_live_points_for(live_local={:?})", live_local);
fn compute_drop_live_points_for(&mut self, local: Local) {
debug!("compute_drop_live_points_for(local={:?})", local);
let local = self.cx.liveness_map.from_live_var(live_local);
let mpi = self.cx.move_data.rev_lookup.find_local(local);
debug!("compute_drop_live_points_for: mpi = {:?}", mpi);
// Find the drops where `local` is initialized.
for drop_point in self.cx.local_use_map.drops(live_local) {
for drop_point in self.cx.local_use_map.drops(local) {
let location = self.cx.elements.to_location(drop_point);
debug_assert_eq!(self.cx.mir.terminator_loc(location.block), location,);