Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 43b69c2

Browse files
nikomatsakisDylan-DPC
authored andcommittedJul 19, 2018
make liveness generic over set of local variables
We used to hardcode that we wanted the liveness of *all* variables. This can now be configured by selecting an alternative index type V and providing a (partial) map from locals to that new type V.
1 parent 4b5f0ba commit 43b69c2

File tree

4 files changed

+170
-102
lines changed

4 files changed

+170
-102
lines changed
 

‎src/librustc_mir/borrow_check/nll/mod.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ use rustc::infer::InferCtxt;
2222
use rustc::mir::{ClosureOutlivesSubject, ClosureRegionRequirements, Mir, Local};
2323
use rustc::ty::{self, RegionKind, RegionVid};
2424
use rustc::util::nodemap::FxHashMap;
25-
use rustc_data_structures::indexed_vec::Idx;
2625
use std::collections::BTreeSet;
2726
use std::fmt::Debug;
2827
use std::env;
@@ -31,7 +30,7 @@ use std::path::PathBuf;
3130
use std::rc::Rc;
3231
use std::str::FromStr;
3332
use transform::MirSource;
34-
use util::liveness::{LivenessResults, LocalSet};
33+
use util::liveness::{IdentityMap, LivenessResults, LocalSet};
3534

3635
use self::mir_util::PassWhere;
3736
use polonius_engine::{Algorithm, Output};
@@ -104,7 +103,7 @@ pub(in borrow_check) fn compute_regions<'cx, 'gcx, 'tcx>(
104103
let elements = &Rc::new(RegionValueElements::new(mir, universal_regions.len()));
105104

106105
// Run the MIR type-checker.
107-
let liveness = &LivenessResults::compute(mir);
106+
let liveness = &LivenessResults::compute(mir, &IdentityMap::new(mir));
108107
let constraint_sets = type_check::type_check(
109108
infcx,
110109
param_env,
@@ -220,14 +219,16 @@ fn dump_mir_results<'a, 'gcx, 'tcx>(
220219
return;
221220
}
222221

222+
let map = &IdentityMap::new(mir);
223+
223224
let regular_liveness_per_location: FxHashMap<_, _> = mir
224225
.basic_blocks()
225226
.indices()
226227
.flat_map(|bb| {
227228
let mut results = vec![];
228229
liveness
229230
.regular
230-
.simulate_block(&mir, bb, |location, local_set| {
231+
.simulate_block(&mir, bb, map, |location, local_set| {
231232
results.push((location, local_set.clone()));
232233
});
233234
results
@@ -241,7 +242,7 @@ fn dump_mir_results<'a, 'gcx, 'tcx>(
241242
let mut results = vec![];
242243
liveness
243244
.drop
244-
.simulate_block(&mir, bb, |location, local_set| {
245+
.simulate_block(&mir, bb, map, |location, local_set| {
245246
results.push((location, local_set.clone()));
246247
});
247248
results

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,8 @@ use rustc::traits::query::type_op::outlives::DropckOutlives;
2020
use rustc::traits::query::type_op::TypeOp;
2121
use rustc::ty::{Ty, TypeFoldable};
2222
use rustc_data_structures::fx::FxHashMap;
23-
use rustc_data_structures::indexed_vec::Idx;
2423
use std::rc::Rc;
25-
use util::liveness::{LivenessResults, LiveVariableMap};
24+
use util::liveness::{IdentityMap, LivenessResults};
2625

2726
use super::TypeChecker;
2827

@@ -48,6 +47,7 @@ pub(super) fn generate<'gcx, 'tcx>(
4847
flow_inits,
4948
move_data,
5049
drop_data: FxHashMap(),
50+
map: &IdentityMap::new(mir),
5151
};
5252

5353
for bb in mir.basic_blocks().indices() {
@@ -61,22 +61,22 @@ where
6161
'flow: 'gen,
6262
'tcx: 'typeck + 'flow,
6363
'gcx: 'tcx,
64-
V: 'gen,
6564
{
6665
cx: &'gen mut TypeChecker<'typeck, 'gcx, 'tcx>,
6766
mir: &'gen Mir<'tcx>,
6867
liveness: &'gen LivenessResults<Local>,
6968
flow_inits: &'gen mut FlowAtLocation<MaybeInitializedPlaces<'flow, 'gcx, 'tcx>>,
7069
move_data: &'gen MoveData<'tcx>,
7170
drop_data: FxHashMap<Ty<'tcx>, DropData<'tcx>>,
71+
map: &'gen IdentityMap<'gen, 'tcx>,
7272
}
7373

7474
struct DropData<'tcx> {
7575
dropck_result: DropckOutlivesResult<'tcx>,
7676
region_constraint_data: Option<Rc<Vec<QueryRegionConstraint<'tcx>>>>,
7777
}
7878

79-
impl<'gen, 'typeck, 'flow, 'gcx, 'tcx, V:LiveVariableMap> TypeLivenessGenerator<'gen, 'typeck, 'flow, 'gcx, 'tcx, V> {
79+
impl<'gen, 'typeck, 'flow, 'gcx, 'tcx> TypeLivenessGenerator<'gen, 'typeck, 'flow, 'gcx, 'tcx> {
8080
/// Liveness constraints:
8181
///
8282
/// > If a variable V is live at point P, then all regions R in the type of V
@@ -86,17 +86,17 @@ impl<'gen, 'typeck, 'flow, 'gcx, 'tcx, V:LiveVariableMap> TypeLivenessGenerator<
8686

8787
self.liveness
8888
.regular
89-
.simulate_block(self.mir, bb, |location, live_locals| {
89+
.simulate_block(self.mir, bb, self.map, |location, live_locals| {
9090
for live_local in live_locals.iter() {
9191
let live_local_ty = self.mir.local_decls[live_local].ty;
9292
Self::push_type_live_constraint(&mut self.cx, live_local_ty, location);
9393
}
9494
});
9595

96-
let mut all_live_locals: Vec<(Location, Vec<V::LiveVar>)> = vec![];
96+
let mut all_live_locals: Vec<(Location, Vec<Local>)> = vec![];
9797
self.liveness
9898
.drop
99-
.simulate_block(self.mir, bb, |location, live_locals| {
99+
.simulate_block(self.mir, bb, self.map, |location, live_locals| {
100100
all_live_locals.push((location, live_locals.iter().collect()));
101101
});
102102
debug!(

‎src/librustc_mir/transform/generator.rs

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ use rustc::mir::visit::{PlaceContext, Visitor, MutVisitor};
6666
use rustc::ty::{self, TyCtxt, AdtDef, Ty};
6767
use rustc::ty::subst::Substs;
6868
use util::dump_mir;
69-
use util::liveness::{self, LivenessMode};
69+
use util::liveness::{self, IdentityMap, LivenessMode};
7070
use rustc_data_structures::indexed_vec::Idx;
7171
use rustc_data_structures::indexed_set::IdxSetBuf;
7272
use std::collections::HashMap;
@@ -334,7 +334,7 @@ impl<'tcx> Visitor<'tcx> for StorageIgnored {
334334

335335
struct BorrowedLocals(liveness::LocalSet<Local>);
336336

337-
fn mark_as_borrowed<'tcx, V: Idx>(place: &Place<'tcx>, locals: &mut BorrowedLocals) {
337+
fn mark_as_borrowed<'tcx>(place: &Place<'tcx>, locals: &mut BorrowedLocals) {
338338
match *place {
339339
Place::Local(l) => { locals.0.add(&l); },
340340
Place::Static(..) => (),
@@ -397,11 +397,22 @@ fn locals_live_across_suspend_points<'a, 'tcx,>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
397397

398398
// Calculate the liveness of MIR locals ignoring borrows.
399399
let mut set = liveness::LocalSet::new_empty(mir.local_decls.len());
400-
let mut liveness = liveness::liveness_of_locals(mir, LivenessMode {
401-
include_regular_use: true,
402-
include_drops: true,
403-
});
404-
liveness::dump_mir(tcx, "generator_liveness", source, mir, &liveness);
400+
let mut liveness = liveness::liveness_of_locals(
401+
mir,
402+
LivenessMode {
403+
include_regular_use: true,
404+
include_drops: true,
405+
},
406+
&IdentityMap::new(mir),
407+
);
408+
liveness::dump_mir(
409+
tcx,
410+
"generator_liveness",
411+
source,
412+
mir,
413+
&IdentityMap::new(mir),
414+
&liveness,
415+
);
405416

406417
let mut storage_liveness_map = HashMap::new();
407418

‎src/librustc_mir/util/liveness.rs

Lines changed: 139 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -33,46 +33,63 @@
3333
//! generator yield points, all pre-existing references are invalidated, so this
3434
//! doesn't matter).
3535
36-
use rustc::mir::*;
36+
use rustc::mir::visit::MirVisitable;
3737
use rustc::mir::visit::{PlaceContext, Visitor};
38-
use rustc_data_structures::indexed_vec::{Idx, IndexVec};
38+
use rustc::mir::Local;
39+
use rustc::mir::*;
40+
use rustc::ty::item_path;
41+
use rustc::ty::TyCtxt;
3942
use rustc_data_structures::indexed_set::IdxSetBuf;
43+
use rustc_data_structures::indexed_vec::{Idx, IndexVec};
4044
use rustc_data_structures::work_queue::WorkQueue;
41-
use util::pretty::{dump_enabled, write_basic_block, write_mir_intro};
42-
use rustc::ty::item_path;
43-
use rustc::mir::Local;
44-
use rustc::mir::visit::MirVisitable;
45-
use std::path::{Path, PathBuf};
4645
use std::fs;
47-
use rustc::ty::TyCtxt;
4846
use std::io::{self, Write};
47+
use std::path::{Path, PathBuf};
4948
use transform::MirSource;
49+
use util::pretty::{dump_enabled, write_basic_block, write_mir_intro};
5050

51-
pub type LocalSet<V: LiveVariableMap> = IdxSetBuf<V::LiveVar>;
51+
pub type LocalSet<V> = IdxSetBuf<V>;
5252

5353
/// This gives the result of the liveness analysis at the boundary of
5454
/// basic blocks. You can use `simulate_block` to obtain the
5555
/// intra-block results.
56-
pub struct LivenessResult<V: LiveVariableMap> {
56+
///
57+
/// The `V` type defines the set of variables that we computed
58+
/// liveness for. This is often `Local`, in which case we computed
59+
/// liveness for all variables -- but it can also be some other type,
60+
/// which indicates a subset of the variables within the graph.
61+
pub struct LivenessResult<V: Idx> {
5762
/// Liveness mode in use when these results were computed.
5863
pub mode: LivenessMode,
5964

6065
/// Live variables on exit to each basic block. This is equal to
6166
/// the union of the `ins` for each successor.
62-
pub outs: IndexVec<BasicBlock, LocalSet<V::LiveVar>>,
67+
pub outs: IndexVec<BasicBlock, LocalSet<V>>,
6368
}
6469

65-
pub(crate) trait LiveVariableMap {
70+
/// Defines the mapping to/from the MIR local variables (`Local`) to
71+
/// the "live variable indices" we are using in a particular
72+
/// computation.
73+
pub trait LiveVariableMap {
6674
type LiveVar;
6775

6876
fn from_local(&self, local: Local) -> Option<Self::LiveVar>;
6977
fn from_live_var(&self, local: Self::LiveVar) -> Local;
78+
fn num_variables(&self) -> usize;
7079
}
7180

72-
#[derive(Eq, PartialEq, Clone)]
73-
struct IdentityMap;
81+
#[derive(Debug)]
82+
pub struct IdentityMap<'a, 'tcx: 'a> {
83+
mir: &'a Mir<'tcx>,
84+
}
7485

75-
impl LiveVariableMap for IdentityMap {
86+
impl<'a, 'tcx> IdentityMap<'a, 'tcx> {
87+
pub fn new(mir: &'a Mir<'tcx>) -> Self {
88+
Self { mir }
89+
}
90+
}
91+
92+
impl<'a, 'tcx> LiveVariableMap for IdentityMap<'a, 'tcx> {
7693
type LiveVar = Local;
7794

7895
fn from_local(&self, local: Local) -> Option<Self::LiveVar> {
@@ -82,6 +99,10 @@ impl LiveVariableMap for IdentityMap {
8299
fn from_live_var(&self, local: Self::LiveVar) -> Local {
83100
local
84101
}
102+
103+
fn num_variables(&self) -> usize {
104+
self.mir.local_decls.len()
105+
}
85106
}
86107

87108
#[derive(Copy, Clone, Debug)]
@@ -103,7 +124,7 @@ pub struct LivenessMode {
103124
}
104125

105126
/// A combination of liveness results, used in NLL.
106-
pub struct LivenessResults<V> {
127+
pub struct LivenessResults<V: Idx> {
107128
/// Liveness results where a regular use makes a variable X live,
108129
/// but not a drop.
109130
pub regular: LivenessResult<V>,
@@ -113,15 +134,19 @@ pub struct LivenessResults<V> {
113134
pub drop: LivenessResult<V>,
114135
}
115136

116-
impl<V, M: LiveVariableMap<LiveVar = V>> LivenessResults<V> {
117-
pub fn compute<'tcx>(mir: &Mir<'tcx>, map: &M) -> LivenessResults<V> {
137+
impl<V: Idx> LivenessResults<V> {
138+
pub fn compute<'tcx>(
139+
mir: &Mir<'tcx>,
140+
map: &impl LiveVariableMap<LiveVar = V>,
141+
) -> LivenessResults<V> {
118142
LivenessResults {
119143
regular: liveness_of_locals(
120144
&mir,
121145
LivenessMode {
122146
include_regular_use: true,
123147
include_drops: false,
124148
},
149+
map,
125150
),
126151

127152
drop: liveness_of_locals(
@@ -130,6 +155,7 @@ impl<V, M: LiveVariableMap<LiveVar = V>> LivenessResults<V> {
130155
include_regular_use: false,
131156
include_drops: true,
132157
},
158+
map,
133159
),
134160
}
135161
}
@@ -138,14 +164,21 @@ impl<V, M: LiveVariableMap<LiveVar = V>> LivenessResults<V> {
138164
/// Compute which local variables are live within the given function
139165
/// `mir`. The liveness mode `mode` determines what sorts of uses are
140166
/// considered to make a variable live (e.g., do drops count?).
141-
pub fn liveness_of_locals<'tcx, V>(mir: &Mir<'tcx>, mode: LivenessMode) -> LivenessResult<V> {
142-
let locals = mir.local_decls.len();
143-
let def_use: IndexVec<_, _> = mir.basic_blocks()
167+
pub fn liveness_of_locals<'tcx, V: Idx>(
168+
mir: &Mir<'tcx>,
169+
mode: LivenessMode,
170+
map: &impl LiveVariableMap<LiveVar = V>,
171+
) -> LivenessResult<V> {
172+
let locals = map.num_variables();
173+
174+
let def_use: IndexVec<_, DefsUses<V>> = mir
175+
.basic_blocks()
144176
.iter()
145-
.map(|b| block(mode, b, locals))
177+
.map(|b| block(mode, map, b, locals))
146178
.collect();
147179

148-
let mut outs: IndexVec<_, _> = mir.basic_blocks()
180+
let mut outs: IndexVec<_, LocalSet<V>> = mir
181+
.basic_blocks()
149182
.indices()
150183
.map(|_| LocalSet::new_empty(locals))
151184
.collect();
@@ -179,14 +212,18 @@ pub fn liveness_of_locals<'tcx, V>(mir: &Mir<'tcx>, mode: LivenessMode) -> Liven
179212
LivenessResult { mode, outs }
180213
}
181214

182-
impl<V: LiveVariableMap> LivenessResult<V>
183-
{
215+
impl<V: Idx> LivenessResult<V> {
184216
/// Walks backwards through the statements/terminator in the given
185217
/// basic block `block`. At each point within `block`, invokes
186218
/// the callback `op` with the current location and the set of
187219
/// variables that are live on entry to that location.
188-
pub fn simulate_block<'tcx, OP>(&self, mir: &Mir<'tcx>, block: BasicBlock, mut callback: OP)
189-
where
220+
pub fn simulate_block<'tcx, OP>(
221+
&self,
222+
mir: &Mir<'tcx>,
223+
block: BasicBlock,
224+
map: &impl LiveVariableMap<LiveVar = V>,
225+
mut callback: OP,
226+
) where
190227
OP: FnMut(Location, &LocalSet<V>),
191228
{
192229
let data = &mir[block];
@@ -206,16 +243,20 @@ impl<V: LiveVariableMap> LivenessResult<V>
206243
let locals = mir.local_decls.len();
207244
let mut visitor = DefsUsesVisitor {
208245
mode: self.mode,
246+
map,
209247
defs_uses: DefsUses {
210248
defs: LocalSet::new_empty(locals),
211249
uses: LocalSet::new_empty(locals),
212-
map: &IdentityMap {},
213250
},
214251
};
215252
// Visit the various parts of the basic block in reverse. If we go
216253
// forward, the logic in `add_def` and `add_use` would be wrong.
217-
visitor.update_bits_and_do_callback(terminator_location, &data.terminator, &mut bits,
218-
&mut callback);
254+
visitor.update_bits_and_do_callback(
255+
terminator_location,
256+
&data.terminator,
257+
&mut bits,
258+
&mut callback,
259+
);
219260

220261
// Compute liveness before each statement (in rev order) and invoke callback.
221262
for statement in data.statements.iter().rev() {
@@ -225,8 +266,12 @@ impl<V: LiveVariableMap> LivenessResult<V>
225266
statement_index,
226267
};
227268
visitor.defs_uses.clear();
228-
visitor.update_bits_and_do_callback(statement_location, statement, &mut bits,
229-
&mut callback);
269+
visitor.update_bits_and_do_callback(
270+
statement_location,
271+
statement,
272+
&mut bits,
273+
&mut callback,
274+
);
230275
}
231276
}
232277
}
@@ -306,30 +351,33 @@ pub fn categorize<'tcx>(context: PlaceContext<'tcx>, mode: LivenessMode) -> Opti
306351
}
307352
}
308353

309-
struct DefsUsesVisitor<'lv> {
354+
struct DefsUsesVisitor<'lv, V, M>
355+
where
356+
V: Idx,
357+
M: LiveVariableMap<LiveVar = V> + 'lv,
358+
{
310359
mode: LivenessMode,
311-
defs_uses: DefsUses<'lv>,
360+
map: &'lv M,
361+
defs_uses: DefsUses<V>,
312362
}
313363

314364
#[derive(Eq, PartialEq, Clone)]
315-
struct DefsUses<'lv>
316-
{
317-
defs: LocalSet<Local>,
318-
uses: LocalSet<Local>,
319-
map: &'lv dyn LiveVariableMap<LiveVar=Local>,
365+
struct DefsUses<V: Idx> {
366+
defs: LocalSet<V>,
367+
uses: LocalSet<V>,
320368
}
321369

322-
impl<'lv> DefsUses<'lv> {
370+
impl<V: Idx> DefsUses<V> {
323371
fn clear(&mut self) {
324372
self.uses.clear();
325373
self.defs.clear();
326374
}
327375

328-
fn apply(&self, bits: &mut LocalSet<Local>) -> bool {
376+
fn apply(&self, bits: &mut LocalSet<V>) -> bool {
329377
bits.subtract(&self.defs) | bits.union(&self.uses)
330378
}
331379

332-
fn add_def(&mut self, index: Local) {
380+
fn add_def(&mut self, index: V) {
333381
// If it was used already in the block, remove that use
334382
// now that we found a definition.
335383
//
@@ -339,13 +387,11 @@ impl<'lv> DefsUses<'lv> {
339387
// X = 5
340388
// // Defs = {}, Uses = {X}
341389
// use(X)
342-
if let Some(v_index) = self.map.from_local(index) {
343-
self.uses.remove(&v_index);
344-
self.defs.add(&v_index);
345-
}
390+
self.uses.remove(&index);
391+
self.defs.add(&index);
346392
}
347393

348-
fn add_use(&mut self, index: Local) {
394+
fn add_use(&mut self, index: V) {
349395
// Inverse of above.
350396
//
351397
// Example:
@@ -356,53 +402,62 @@ impl<'lv> DefsUses<'lv> {
356402
// X = 5
357403
// // Defs = {}, Uses = {X}
358404
// use(X)
359-
if let Some(v_index) = self.map.from_local(index) {
360-
self.defs.remove(&v_index);
361-
self.uses.add(&v_index);
362-
}
405+
self.defs.remove(&index);
406+
self.uses.add(&index);
363407
}
364408
}
365409

366-
impl<'lv> DefsUsesVisitor<'lv>
410+
impl<'lv, V, M> DefsUsesVisitor<'lv, V, M>
411+
where
412+
V: Idx,
413+
M: LiveVariableMap<LiveVar = V>,
367414
{
368415
/// Update `bits` with the effects of `value` and call `callback`. We
369416
/// should always visit in reverse order. This method assumes that we have
370417
/// not visited anything before; if you have, clear `bits` first.
371-
fn update_bits_and_do_callback<'tcx, OP>(&mut self, location: Location,
372-
value: &impl MirVisitable<'tcx>, bits: &mut LocalSet<Local>,
373-
callback: &mut OP)
374-
where
375-
OP: FnMut(Location, &LocalSet<Local>),
418+
fn update_bits_and_do_callback<'tcx, OP>(
419+
&mut self,
420+
location: Location,
421+
value: &impl MirVisitable<'tcx>,
422+
bits: &mut LocalSet<V>,
423+
callback: &mut OP,
424+
) where
425+
OP: FnMut(Location, &LocalSet<V>),
376426
{
377427
value.apply(location, self);
378428
self.defs_uses.apply(bits);
379429
callback(location, bits);
380430
}
381431
}
382432

383-
impl<'tcx, 'lv> Visitor<'tcx> for DefsUsesVisitor<'lv> {
433+
impl<'tcx, 'lv, V, M> Visitor<'tcx> for DefsUsesVisitor<'lv, V, M>
434+
where
435+
V: Idx,
436+
M: LiveVariableMap<LiveVar = V>,
437+
{
384438
fn visit_local(&mut self, &local: &Local, context: PlaceContext<'tcx>, _: Location) {
385-
match categorize(context, self.mode) {
386-
Some(DefUse::Def) => {
387-
self.defs_uses.add_def(local);
439+
if let Some(v_index) = self.map.from_local(local) {
440+
match categorize(context, self.mode) {
441+
Some(DefUse::Def) => self.defs_uses.add_def(v_index),
442+
Some(DefUse::Use) => self.defs_uses.add_use(v_index),
443+
None => (),
388444
}
389-
390-
Some(DefUse::Use) => {
391-
self.defs_uses.add_use(local);
392-
}
393-
394-
None => {}
395445
}
396446
}
397447
}
398448

399-
fn block<'tcx, 'lv>(mode: LivenessMode, b: &BasicBlockData<'tcx>, locals: usize) -> DefsUses<'lv> {
449+
fn block<'tcx, V: Idx>(
450+
mode: LivenessMode,
451+
map: &impl LiveVariableMap<LiveVar = V>,
452+
b: &BasicBlockData<'tcx>,
453+
locals: usize,
454+
) -> DefsUses<V> {
400455
let mut visitor = DefsUsesVisitor {
401456
mode,
457+
map,
402458
defs_uses: DefsUses {
403459
defs: LocalSet::new_empty(locals),
404460
uses: LocalSet::new_empty(locals),
405-
map: &IdentityMap {},
406461
},
407462
};
408463

@@ -421,13 +476,13 @@ fn block<'tcx, 'lv>(mode: LivenessMode, b: &BasicBlockData<'tcx>, locals: usize)
421476
visitor.defs_uses
422477
}
423478

424-
pub fn dump_mir<'a, 'tcx, V: LiveVariableMap>(
479+
pub fn dump_mir<'a, 'tcx, V: Idx>(
425480
tcx: TyCtxt<'a, 'tcx, 'tcx>,
426481
pass_name: &str,
427482
source: MirSource,
428483
mir: &Mir<'tcx>,
429-
result: &LivenessResult<Local>,
430-
map: &impl LiveVariableMap<LiveVar = V>
484+
map: &impl LiveVariableMap<LiveVar = V>,
485+
result: &LivenessResult<V>,
431486
) {
432487
if !dump_enabled(tcx, pass_name, source) {
433488
return;
@@ -436,16 +491,17 @@ pub fn dump_mir<'a, 'tcx, V: LiveVariableMap>(
436491
// see notes on #41697 below
437492
tcx.item_path_str(source.def_id)
438493
});
439-
dump_matched_mir_node(tcx, pass_name, &node_path, source, mir, result);
494+
dump_matched_mir_node(tcx, pass_name, &node_path, source, mir, map, result);
440495
}
441496

442-
fn dump_matched_mir_node<'a, 'tcx, V: LiveVariableMap>(
497+
fn dump_matched_mir_node<'a, 'tcx, V: Idx>(
443498
tcx: TyCtxt<'a, 'tcx, 'tcx>,
444499
pass_name: &str,
445500
node_path: &str,
446501
source: MirSource,
447502
mir: &Mir<'tcx>,
448-
result: &LivenessResult<V::LiveVar>,
503+
map: &dyn LiveVariableMap<LiveVar = V>,
504+
result: &LivenessResult<V>,
449505
) {
450506
let mut file_path = PathBuf::new();
451507
file_path.push(Path::new(&tcx.sess.opts.debugging_opts.dump_mir_dir));
@@ -457,25 +513,25 @@ fn dump_matched_mir_node<'a, 'tcx, V: LiveVariableMap>(
457513
writeln!(file, "// source = {:?}", source)?;
458514
writeln!(file, "// pass_name = {}", pass_name)?;
459515
writeln!(file, "")?;
460-
write_mir_fn(tcx, source, mir, &mut file, result)?;
516+
write_mir_fn(tcx, source, mir, map, &mut file, result)?;
461517
Ok(())
462518
});
463519
}
464520

465-
pub fn write_mir_fn<'a, 'tcx, V: LiveVariableMap>(
521+
pub fn write_mir_fn<'a, 'tcx, V: Idx>(
466522
tcx: TyCtxt<'a, 'tcx, 'tcx>,
467523
src: MirSource,
468524
mir: &Mir<'tcx>,
525+
map: &dyn LiveVariableMap<LiveVar = V>,
469526
w: &mut dyn Write,
470-
result: &LivenessResult<V::LiveVar>,
527+
result: &LivenessResult<V>,
471528
) -> io::Result<()> {
472529
write_mir_intro(tcx, src, mir, w)?;
473530
for block in mir.basic_blocks().indices() {
474-
let print = |w: &mut dyn Write, prefix, result: &IndexVec<BasicBlock, LocalSet<Local>>| {
475-
let live: Vec<String> = mir.local_decls
476-
.indices()
477-
.filter(|i| result[block].contains(i))
478-
.map(|i| format!("{:?}", i))
531+
let print = |w: &mut dyn Write, prefix, result: &IndexVec<BasicBlock, LocalSet<V>>| {
532+
let live: Vec<String> = result[block].iter()
533+
.map(|v| map.from_live_var(v))
534+
.map(|local| format!("{:?}", local))
479535
.collect();
480536
writeln!(w, "{} {{{}}}", prefix, live.join(", "))
481537
};

0 commit comments

Comments
 (0)
Please sign in to comment.