Skip to content

Commit 469fd77

Browse files
committed
Auto merge of rust-lang#38616 - pnkfelix:refactor-mir-dataflow-remove-ctxt, r=arielb1
Refactor mir::dataflow: remove Ctxt associated type from BitDenotation trait Refactor mir::dataflow: remove Ctxt associated type from BitDenotation trait I no longer remember why I needed this (or thought I did). The way that the `BitDenotation` is passed around in all existing use cases (and planned future ones), the thing that were in the `Ctxt` can just be part of `Self` instead. (I think ariel had been pushing me to do this back when I first put in this infrastructure; it took me a while to see how much of pain the `Ctxt` was causing.)
2 parents 17f1fba + a6fe6c9 commit 469fd77

File tree

7 files changed

+144
-135
lines changed

7 files changed

+144
-135
lines changed

src/librustc_borrowck/borrowck/mir/dataflow/graphviz.rs

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,15 @@ use std::marker::PhantomData;
2727
use std::mem;
2828
use std::path::Path;
2929

30-
use super::super::MoveDataParamEnv;
3130
use super::super::MirBorrowckCtxtPreDataflow;
3231
use super::{BitDenotation, DataflowState};
3332

3433
impl<O: BitDenotation> DataflowState<O> {
35-
fn each_bit<F>(&self, ctxt: &O::Ctxt, words: &IdxSet<O::Idx>, mut f: F)
34+
fn each_bit<F>(&self, words: &IdxSet<O::Idx>, mut f: F)
3635
where F: FnMut(O::Idx) {
3736
//! Helper for iterating over the bits in a bitvector.
3837
39-
let bits_per_block = self.operator.bits_per_block(ctxt);
38+
let bits_per_block = self.operator.bits_per_block();
4039
let usize_bits: usize = mem::size_of::<usize>() * 8;
4140

4241
for (word_index, &word) in words.words().iter().enumerate() {
@@ -65,35 +64,33 @@ impl<O: BitDenotation> DataflowState<O> {
6564
}
6665

6766
pub fn interpret_set<'c, P>(&self,
68-
ctxt: &'c O::Ctxt,
67+
o: &'c O,
6968
words: &IdxSet<O::Idx>,
7069
render_idx: &P)
7170
-> Vec<&'c Debug>
72-
where P: for <'b> Fn(&'b O::Ctxt, O::Idx) -> &'b Debug
71+
where P: Fn(&O, O::Idx) -> &Debug
7372
{
7473
let mut v = Vec::new();
75-
self.each_bit(ctxt, words, |i| {
76-
v.push(render_idx(ctxt, i));
74+
self.each_bit(words, |i| {
75+
v.push(render_idx(o, i));
7776
});
7877
v
7978
}
8079
}
8180

8281
pub trait MirWithFlowState<'tcx> {
83-
type BD: BitDenotation<Ctxt=MoveDataParamEnv<'tcx>>;
82+
type BD: BitDenotation;
8483
fn node_id(&self) -> NodeId;
8584
fn mir(&self) -> &Mir<'tcx>;
86-
fn analysis_ctxt(&self) -> &<Self::BD as BitDenotation>::Ctxt;
8785
fn flow_state(&self) -> &DataflowState<Self::BD>;
8886
}
8987

9088
impl<'a, 'tcx: 'a, BD> MirWithFlowState<'tcx> for MirBorrowckCtxtPreDataflow<'a, 'tcx, BD>
91-
where 'tcx: 'a, BD: BitDenotation<Ctxt=MoveDataParamEnv<'tcx>>
89+
where 'tcx: 'a, BD: BitDenotation
9290
{
9391
type BD = BD;
9492
fn node_id(&self) -> NodeId { self.node_id }
9593
fn mir(&self) -> &Mir<'tcx> { self.flow_state.mir() }
96-
fn analysis_ctxt(&self) -> &BD::Ctxt { &self.flow_state.ctxt }
9794
fn flow_state(&self) -> &DataflowState<Self::BD> { &self.flow_state.flow_state }
9895
}
9996

@@ -110,8 +107,8 @@ pub fn print_borrowck_graph_to<'a, 'tcx, BD, P>(
110107
path: &Path,
111108
render_idx: P)
112109
-> io::Result<()>
113-
where BD: BitDenotation<Ctxt=MoveDataParamEnv<'tcx>>,
114-
P: for <'b> Fn(&'b BD::Ctxt, BD::Idx) -> &'b Debug
110+
where BD: BitDenotation,
111+
P: Fn(&BD, BD::Idx) -> &Debug
115112
{
116113
let g = Graph { mbcx: mbcx, phantom: PhantomData, render_idx: render_idx };
117114
let mut v = Vec::new();
@@ -133,9 +130,7 @@ fn outgoing(mir: &Mir, bb: BasicBlock) -> Vec<Edge> {
133130

134131
impl<'a, 'tcx, MWF, P> dot::Labeller<'a> for Graph<'a, 'tcx, MWF, P>
135132
where MWF: MirWithFlowState<'tcx>,
136-
P: for <'b> Fn(&'b <MWF::BD as BitDenotation>::Ctxt,
137-
<MWF::BD as BitDenotation>::Idx)
138-
-> &'b Debug,
133+
P: for <'b> Fn(&'b MWF::BD, <MWF::BD as BitDenotation>::Idx) -> &'b Debug,
139134
{
140135
type Node = Node;
141136
type Edge = Edge;
@@ -227,9 +222,8 @@ impl<'a, 'tcx, MWF, P> dot::Labeller<'a> for Graph<'a, 'tcx, MWF, P>
227222
::rustc_mir::graphviz::write_node_label(
228223
*n, self.mbcx.mir(), &mut v, 4,
229224
|w| {
230-
let ctxt = self.mbcx.analysis_ctxt();
231225
let flow = self.mbcx.flow_state();
232-
let entry_interp = flow.interpret_set(ctxt,
226+
let entry_interp = flow.interpret_set(&flow.operator,
233227
flow.sets.on_entry_set_for(i),
234228
&self.render_idx);
235229
chunked_present_left(w, &entry_interp[..], chunk_size)?;
@@ -244,12 +238,11 @@ impl<'a, 'tcx, MWF, P> dot::Labeller<'a> for Graph<'a, 'tcx, MWF, P>
244238
entrybits=bits_to_string(entry.words(), bits_per_block))
245239
},
246240
|w| {
247-
let ctxt = self.mbcx.analysis_ctxt();
248241
let flow = self.mbcx.flow_state();
249242
let gen_interp =
250-
flow.interpret_set(ctxt, flow.sets.gen_set_for(i), &self.render_idx);
243+
flow.interpret_set(&flow.operator, flow.sets.gen_set_for(i), &self.render_idx);
251244
let kill_interp =
252-
flow.interpret_set(ctxt, flow.sets.kill_set_for(i), &self.render_idx);
245+
flow.interpret_set(&flow.operator, flow.sets.kill_set_for(i), &self.render_idx);
253246
chunked_present_left(w, &gen_interp[..], chunk_size)?;
254247
let bits_per_block = flow.sets.bits_per_block();
255248
{

0 commit comments

Comments
 (0)