Skip to content

Commit 3594ff1

Browse files
Enable custom rustc_peek behavior
1 parent dee972a commit 3594ff1

File tree

1 file changed

+40
-18
lines changed

1 file changed

+40
-18
lines changed

src/librustc_mir/transform/rustc_peek.rs

Lines changed: 40 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,8 @@ pub fn sanity_check_via_rustc_peek<'tcx, O>(
8888
def_id: DefId,
8989
_attributes: &[ast::Attribute],
9090
results: &DataflowResults<'tcx, O>,
91-
) where
92-
O: BitDenotation<'tcx, Idx = MovePathIndex> + HasMoveData<'tcx>,
93-
{
91+
) where O: RustcPeekAt<'tcx> {
9492
debug!("sanity_check_via_rustc_peek def_id: {:?}", def_id);
95-
let move_data = results.operator().move_data();
9693

9794
let peek_calls = body
9895
.basic_blocks()
@@ -121,19 +118,7 @@ pub fn sanity_check_via_rustc_peek<'tcx, O>(
121118
let loc = Location { block: bb, statement_index };
122119
let flow_state = dataflow::state_for_location(loc, results.operator(), results, body);
123120

124-
match move_data.rev_lookup.find(peeking_at_place) {
125-
LookupResult::Exact(peek_mpi) => {
126-
let bit_state = flow_state.contains(peek_mpi);
127-
debug!("rustc_peek({:?} = &{:?}) bit_state: {}",
128-
call.arg, peeking_at_place, bit_state);
129-
if !bit_state {
130-
tcx.sess.span_err(call.span, "rustc_peek: bit not set");
131-
}
132-
}
133-
LookupResult::Parent(..) => {
134-
tcx.sess.span_err(call.span, "rustc_peek: argument untracked");
135-
}
136-
}
121+
results.operator().peek_at(tcx, peeking_at_place, &flow_state, call);
137122
} else {
138123
let msg = "rustc_peek: argument expression \
139124
must be immediate borrow of form `&expr`";
@@ -159,7 +144,8 @@ fn value_assigned_to_local<'a, 'tcx>(
159144
None
160145
}
161146

162-
struct PeekCall {
147+
#[derive(Clone, Copy, Debug)]
148+
pub struct PeekCall {
163149
arg: Local,
164150
span: Span,
165151
}
@@ -203,3 +189,39 @@ impl PeekCall {
203189
None
204190
}
205191
}
192+
193+
pub trait RustcPeekAt<'tcx>: BitDenotation<'tcx> {
194+
fn peek_at(
195+
&self,
196+
tcx: TyCtxt<'tcx>,
197+
place: &mir::Place<'tcx>,
198+
flow_state: &BitSet<Self::Idx>,
199+
call: PeekCall,
200+
);
201+
}
202+
203+
impl<'tcx, O> RustcPeekAt<'tcx> for O
204+
where O: BitDenotation<'tcx, Idx = MovePathIndex> + HasMoveData<'tcx>,
205+
{
206+
fn peek_at(
207+
&self,
208+
tcx: TyCtxt<'tcx>,
209+
place: &mir::Place<'tcx>,
210+
flow_state: &BitSet<Self::Idx>,
211+
call: PeekCall,
212+
) {
213+
match self.move_data().rev_lookup.find(place) {
214+
LookupResult::Exact(peek_mpi) => {
215+
let bit_state = flow_state.contains(peek_mpi);
216+
debug!("rustc_peek({:?} = &{:?}) bit_state: {}",
217+
call.arg, place, bit_state);
218+
if !bit_state {
219+
tcx.sess.span_err(call.span, "rustc_peek: bit not set");
220+
}
221+
}
222+
LookupResult::Parent(..) => {
223+
tcx.sess.span_err(call.span, "rustc_peek: argument untracked");
224+
}
225+
}
226+
}
227+
}

0 commit comments

Comments
 (0)