diff options
Diffstat (limited to 'src/librustc_mir/transform/rustc_peek.rs')
| -rw-r--r-- | src/librustc_mir/transform/rustc_peek.rs | 123 |
1 files changed, 64 insertions, 59 deletions
diff --git a/src/librustc_mir/transform/rustc_peek.rs b/src/librustc_mir/transform/rustc_peek.rs index 4345fc66bb9..095d8474c5d 100644 --- a/src/librustc_mir/transform/rustc_peek.rs +++ b/src/librustc_mir/transform/rustc_peek.rs @@ -1,25 +1,25 @@ -use rustc_target::spec::abi::{Abi}; +use rustc_target::spec::abi::Abi; use syntax::ast; use syntax::symbol::sym; use syntax_pos::Span; -use rustc::ty::{self, TyCtxt, Ty}; +use crate::transform::{MirPass, MirSource}; use rustc::hir::def_id::DefId; -use rustc::mir::{self, Body, BodyAndCache, Location, Local}; +use rustc::mir::{self, Body, BodyAndCache, Local, Location}; +use rustc::ty::{self, Ty, TyCtxt}; use rustc_index::bit_set::BitSet; -use crate::transform::{MirPass, MirSource}; -use crate::dataflow::{do_dataflow, DebugFormatted}; -use crate::dataflow::MoveDataParamEnv; +use crate::dataflow::move_paths::{HasMoveData, MoveData}; +use crate::dataflow::move_paths::{LookupResult, MovePathIndex}; use crate::dataflow::BitDenotation; use crate::dataflow::DataflowResults; use crate::dataflow::DataflowResultsCursor; +use crate::dataflow::IndirectlyMutableLocals; +use crate::dataflow::MoveDataParamEnv; +use crate::dataflow::{do_dataflow, DebugFormatted}; use crate::dataflow::{ - DefinitelyInitializedPlaces, MaybeInitializedPlaces, MaybeUninitializedPlaces + DefinitelyInitializedPlaces, MaybeInitializedPlaces, MaybeUninitializedPlaces, }; -use crate::dataflow::IndirectlyMutableLocals; -use crate::dataflow::move_paths::{MovePathIndex, LookupResult}; -use crate::dataflow::move_paths::{HasMoveData, MoveData}; use crate::dataflow::has_rustc_mir_with; @@ -40,22 +40,42 @@ impl<'tcx> MirPass<'tcx> for SanityCheck { let move_data = MoveData::gather_moves(body, tcx, param_env).unwrap(); let mdpe = MoveDataParamEnv { move_data: move_data, param_env: param_env }; let dead_unwinds = BitSet::new_empty(body.basic_blocks().len()); - let flow_inits = - do_dataflow(tcx, body, def_id, &attributes, &dead_unwinds, - MaybeInitializedPlaces::new(tcx, body, &mdpe), - |bd, i| DebugFormatted::new(&bd.move_data().move_paths[i])); - let flow_uninits = - do_dataflow(tcx, body, def_id, &attributes, &dead_unwinds, - MaybeUninitializedPlaces::new(tcx, body, &mdpe), - |bd, i| DebugFormatted::new(&bd.move_data().move_paths[i])); - let flow_def_inits = - do_dataflow(tcx, body, def_id, &attributes, &dead_unwinds, - DefinitelyInitializedPlaces::new(tcx, body, &mdpe), - |bd, i| DebugFormatted::new(&bd.move_data().move_paths[i])); - let flow_indirectly_mut = - do_dataflow(tcx, body, def_id, &attributes, &dead_unwinds, - IndirectlyMutableLocals::new(tcx, body, param_env), - |_, i| DebugFormatted::new(&i)); + let flow_inits = do_dataflow( + tcx, + body, + def_id, + &attributes, + &dead_unwinds, + MaybeInitializedPlaces::new(tcx, body, &mdpe), + |bd, i| DebugFormatted::new(&bd.move_data().move_paths[i]), + ); + let flow_uninits = do_dataflow( + tcx, + body, + def_id, + &attributes, + &dead_unwinds, + MaybeUninitializedPlaces::new(tcx, body, &mdpe), + |bd, i| DebugFormatted::new(&bd.move_data().move_paths[i]), + ); + let flow_def_inits = do_dataflow( + tcx, + body, + def_id, + &attributes, + &dead_unwinds, + DefinitelyInitializedPlaces::new(tcx, body, &mdpe), + |bd, i| DebugFormatted::new(&bd.move_data().move_paths[i]), + ); + let flow_indirectly_mut = do_dataflow( + tcx, + body, + def_id, + &attributes, + &dead_unwinds, + IndirectlyMutableLocals::new(tcx, body, param_env), + |_, i| DebugFormatted::new(&i), + ); if has_rustc_mir_with(&attributes, sym::rustc_peek_maybe_init).is_some() { sanity_check_via_rustc_peek(tcx, body, def_id, &attributes, &flow_inits); @@ -64,20 +84,10 @@ impl<'tcx> MirPass<'tcx> for SanityCheck { sanity_check_via_rustc_peek(tcx, body, def_id, &attributes, &flow_uninits); } if has_rustc_mir_with(&attributes, sym::rustc_peek_definite_init).is_some() { - sanity_check_via_rustc_peek( - tcx, - body, - def_id, - &attributes, - &flow_def_inits); + sanity_check_via_rustc_peek(tcx, body, def_id, &attributes, &flow_def_inits); } if has_rustc_mir_with(&attributes, sym::rustc_peek_indirectly_mutable).is_some() { - sanity_check_via_rustc_peek( - tcx, - body, - def_id, - &attributes, - &flow_indirectly_mut); + sanity_check_via_rustc_peek(tcx, body, def_id, &attributes, &flow_indirectly_mut); } if has_rustc_mir_with(&attributes, sym::stop_after_dataflow).is_some() { tcx.sess.fatal("stop_after_dataflow ended compilation"); @@ -107,18 +117,16 @@ pub fn sanity_check_via_rustc_peek<'tcx, O>( def_id: DefId, _attributes: &[ast::Attribute], results: &DataflowResults<'tcx, O>, -) where O: RustcPeekAt<'tcx> { +) where + O: RustcPeekAt<'tcx>, +{ debug!("sanity_check_via_rustc_peek def_id: {:?}", def_id); let mut cursor = DataflowResultsCursor::new(results, body); - let peek_calls = body - .basic_blocks() - .iter_enumerated() - .filter_map(|(bb, block_data)| { - PeekCall::from_terminator(tcx, block_data.terminator()) - .map(|call| (bb, block_data, call)) - }); + let peek_calls = body.basic_blocks().iter_enumerated().filter_map(|(bb, block_data)| { + PeekCall::from_terminator(tcx, block_data.terminator()).map(|call| (bb, block_data, call)) + }); for (bb, block_data, call) in peek_calls { // Look for a sequence like the following to indicate that we should be peeking at `_1`: @@ -135,14 +143,15 @@ pub fn sanity_check_via_rustc_peek<'tcx, O>( .enumerate() .filter_map(|(i, stmt)| value_assigned_to_local(stmt, call.arg).map(|rval| (i, rval))) .next() - .expect("call to rustc_peek should be preceded by \ - assignment to temporary holding its argument"); + .expect( + "call to rustc_peek should be preceded by \ + assignment to temporary holding its argument", + ); match (call.kind, peek_rval) { - | (PeekCallKind::ByRef, mir::Rvalue::Ref(_, _, place)) + (PeekCallKind::ByRef, mir::Rvalue::Ref(_, _, place)) | (PeekCallKind::ByVal, mir::Rvalue::Use(mir::Operand::Move(place))) - | (PeekCallKind::ByVal, mir::Rvalue::Use(mir::Operand::Copy(place))) - => { + | (PeekCallKind::ByVal, mir::Rvalue::Use(mir::Operand::Copy(place))) => { let loc = Location { block: bb, statement_index }; cursor.seek(loc); let state = cursor.get(); @@ -238,11 +247,7 @@ impl PeekCall { } }; - return Some(PeekCall { - arg, - kind, - span, - }); + return Some(PeekCall { arg, kind, span }); } } @@ -261,7 +266,8 @@ pub trait RustcPeekAt<'tcx>: BitDenotation<'tcx> { } impl<'tcx, O> RustcPeekAt<'tcx> for O - where O: BitDenotation<'tcx, Idx = MovePathIndex> + HasMoveData<'tcx>, +where + O: BitDenotation<'tcx, Idx = MovePathIndex> + HasMoveData<'tcx>, { fn peek_at( &self, @@ -273,8 +279,7 @@ impl<'tcx, O> RustcPeekAt<'tcx> for O match self.move_data().rev_lookup.find(place.as_ref()) { LookupResult::Exact(peek_mpi) => { let bit_state = flow_state.contains(peek_mpi); - debug!("rustc_peek({:?} = &{:?}) bit_state: {}", - call.arg, place, bit_state); + debug!("rustc_peek({:?} = &{:?}) bit_state: {}", call.arg, place, bit_state); if !bit_state { tcx.sess.span_err(call.span, "rustc_peek: bit not set"); } |
