Skip to content

Commit 200bc02

Browse files
committed
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.
1 parent a9410cd commit 200bc02

File tree

2 files changed

+27
-32
lines changed

2 files changed

+27
-32
lines changed

src/librustc_mir/borrow_check/nll/type_check/liveness/local_use_map.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,18 +73,21 @@ impl LocalUseMap<'me> {
7373
local_use_map
7474
}
7575

76-
crate fn defs(&self, local: LiveVar) -> impl Iterator<Item = PointIndex> + '_ {
77-
vll::iter(self.first_def_at[local], &self.appearances)
76+
crate fn defs(&self, local: Local) -> impl Iterator<Item = PointIndex> + '_ {
77+
let live_var = self.liveness_map.from_local(local).unwrap();
78+
vll::iter(self.first_def_at[live_var], &self.appearances)
7879
.map(move |aa| self.appearances[aa].point_index)
7980
}
8081

81-
crate fn uses(&self, local: LiveVar) -> impl Iterator<Item = PointIndex> + '_ {
82-
vll::iter(self.first_use_at[local], &self.appearances)
82+
crate fn uses(&self, local: Local) -> impl Iterator<Item = PointIndex> + '_ {
83+
let live_var = self.liveness_map.from_local(local).unwrap();
84+
vll::iter(self.first_use_at[live_var], &self.appearances)
8385
.map(move |aa| self.appearances[aa].point_index)
8486
}
8587

86-
crate fn drops(&self, local: LiveVar) -> impl Iterator<Item = PointIndex> + '_ {
87-
vll::iter(self.first_drop_at[local], &self.appearances)
88+
crate fn drops(&self, local: Local) -> impl Iterator<Item = PointIndex> + '_ {
89+
let live_var = self.liveness_map.from_local(local).unwrap();
90+
vll::iter(self.first_drop_at[live_var], &self.appearances)
8891
.map(move |aa| self.appearances[aa].point_index)
8992
}
9093
}

src/librustc_mir/borrow_check/nll/type_check/liveness/trace.rs

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
use crate::borrow_check::location::LocationTable;
22
use crate::borrow_check::nll::region_infer::values::{self, PointIndex, RegionValueElements};
3-
use crate::borrow_check::nll::type_check::liveness::liveness_map::{LiveVar, NllLivenessMap};
3+
use crate::borrow_check::nll::type_check::liveness::liveness_map::NllLivenessMap;
44
use crate::borrow_check::nll::type_check::liveness::local_use_map::LocalUseMap;
55
use crate::borrow_check::nll::type_check::NormalizeLocation;
66
use crate::borrow_check::nll::type_check::TypeChecker;
77
use crate::dataflow::move_paths::indexes::MovePathIndex;
88
use crate::dataflow::move_paths::MoveData;
99
use crate::dataflow::{FlowAtLocation, FlowsAtLocation, MaybeInitializedPlaces};
10-
use crate::util::liveness::LiveVariableMap;
1110
use rustc::infer::canonical::QueryRegionConstraint;
1211
use rustc::mir::{BasicBlock, ConstraintCategory, Local, Location, Mir};
1312
use rustc::traits::query::dropck_outlives::DropckOutlivesResult;
@@ -56,12 +55,12 @@ pub(super) fn trace(
5655
elements,
5756
local_use_map,
5857
move_data,
59-
liveness_map,
6058
drop_data: FxHashMap::default(),
6159
location_table,
6260
};
6361

64-
LivenessResults::new(cx).compute_for_all_locals();
62+
let live_locals: Vec<Local> = liveness_map.to_local.clone().into_iter().collect();
63+
LivenessResults::new(cx).compute_for_all_locals(live_locals);
6564
}
6665

6766
/// Contextual state for the type-liveness generator.
@@ -95,9 +94,6 @@ where
9594
/// dropped.
9695
local_use_map: &'me LocalUseMap<'me>,
9796

98-
/// Map tracking which variables need liveness computation.
99-
liveness_map: &'me NllLivenessMap,
100-
10197
/// Maps between a MIR Location and a LocationIndex
10298
location_table: &'me LocationTable,
10399
}
@@ -148,15 +144,12 @@ impl LivenessResults<'me, 'typeck, 'flow, 'gcx, 'tcx> {
148144
}
149145
}
150146

151-
fn compute_for_all_locals(&mut self) {
152-
for live_local in self.cx.liveness_map.to_local.indices() {
153-
let local = self.cx.liveness_map.from_live_var(live_local);
154-
debug!("local={:?} live_local={:?}", local, live_local);
155-
147+
fn compute_for_all_locals(&mut self, live_locals: Vec<Local>) {
148+
for local in live_locals {
156149
self.reset_local_state();
157-
self.add_defs_for(live_local);
158-
self.compute_use_live_points_for(live_local);
159-
self.compute_drop_live_points_for(live_local);
150+
self.add_defs_for(local);
151+
self.compute_use_live_points_for(local);
152+
self.compute_drop_live_points_for(local);
160153

161154
let local_ty = self.cx.mir.local_decls[local].ty;
162155

@@ -185,23 +178,23 @@ impl LivenessResults<'me, 'typeck, 'flow, 'gcx, 'tcx> {
185178
}
186179

187180
/// Adds the definitions of `local` into `self.defs`.
188-
fn add_defs_for(&mut self, live_local: LiveVar) {
189-
for def in self.cx.local_use_map.defs(live_local) {
181+
fn add_defs_for(&mut self, local: Local) {
182+
for def in self.cx.local_use_map.defs(local) {
190183
debug!("- defined at {:?}", def);
191184
self.defs.insert(def);
192185
}
193186
}
194187

195188
/// Computes all points where local is "use live" -- meaning its
196189
/// current value may be used later (except by a drop). This is
197-
/// done by walking backwards from each use of `live_local` until we
190+
/// done by walking backwards from each use of `local` until we
198191
/// find a `def` of local.
199192
///
200-
/// Requires `add_defs_for(live_local)` to have been executed.
201-
fn compute_use_live_points_for(&mut self, live_local: LiveVar) {
202-
debug!("compute_use_live_points_for(live_local={:?})", live_local);
193+
/// Requires `add_defs_for(local)` to have been executed.
194+
fn compute_use_live_points_for(&mut self, local: Local) {
195+
debug!("compute_use_live_points_for(local={:?})", local);
203196

204-
self.stack.extend(self.cx.local_use_map.uses(live_local));
197+
self.stack.extend(self.cx.local_use_map.uses(local));
205198
while let Some(p) = self.stack.pop() {
206199
if self.defs.contains(p) {
207200
continue;
@@ -224,15 +217,14 @@ impl LivenessResults<'me, 'typeck, 'flow, 'gcx, 'tcx> {
224217
///
225218
/// Requires `compute_use_live_points_for` and `add_defs_for` to
226219
/// have been executed.
227-
fn compute_drop_live_points_for(&mut self, live_local: LiveVar) {
228-
debug!("compute_drop_live_points_for(live_local={:?})", live_local);
220+
fn compute_drop_live_points_for(&mut self, local: Local) {
221+
debug!("compute_drop_live_points_for(local={:?})", local);
229222

230-
let local = self.cx.liveness_map.from_live_var(live_local);
231223
let mpi = self.cx.move_data.rev_lookup.find_local(local);
232224
debug!("compute_drop_live_points_for: mpi = {:?}", mpi);
233225

234226
// Find the drops where `local` is initialized.
235-
for drop_point in self.cx.local_use_map.drops(live_local) {
227+
for drop_point in self.cx.local_use_map.drops(local) {
236228
let location = self.cx.elements.to_location(drop_point);
237229
debug_assert_eq!(self.cx.mir.terminator_loc(location.block), location,);
238230

0 commit comments

Comments
 (0)