diff --git a/compiler/rustc_borrowck/src/dataflow.rs b/compiler/rustc_borrowck/src/dataflow.rs index 27b558be3b77f..b3d14c1beb565 100644 --- a/compiler/rustc_borrowck/src/dataflow.rs +++ b/compiler/rustc_borrowck/src/dataflow.rs @@ -121,24 +121,24 @@ rustc_index::newtype_index! { /// `BorrowIndex`, and maps each such index to a `BorrowData` /// describing the borrow. These indexes are used for representing the /// borrows in compact bitvectors. -pub struct Borrows<'a, 'tcx> { +pub struct Borrows<'mir, 'tcx> { tcx: TyCtxt<'tcx>, - body: &'a Body<'tcx>, + body: &'mir Body<'tcx>, - borrow_set: &'a BorrowSet<'tcx>, + borrow_set: &'mir BorrowSet<'tcx>, borrows_out_of_scope_at_location: FxIndexMap>, } -struct OutOfScopePrecomputer<'a, 'tcx> { +struct OutOfScopePrecomputer<'mir, 'tcx> { visited: BitSet, visit_stack: Vec, - body: &'a Body<'tcx>, - regioncx: &'a RegionInferenceContext<'tcx>, + body: &'mir Body<'tcx>, + regioncx: &'mir RegionInferenceContext<'tcx>, borrows_out_of_scope_at_location: FxIndexMap>, } -impl<'a, 'tcx> OutOfScopePrecomputer<'a, 'tcx> { - fn new(body: &'a Body<'tcx>, regioncx: &'a RegionInferenceContext<'tcx>) -> Self { +impl<'mir, 'tcx> OutOfScopePrecomputer<'mir, 'tcx> { + fn new(body: &'mir Body<'tcx>, regioncx: &'mir RegionInferenceContext<'tcx>) -> Self { OutOfScopePrecomputer { visited: BitSet::new_empty(body.basic_blocks.len()), visit_stack: vec![], @@ -241,17 +241,17 @@ pub fn calculate_borrows_out_of_scope_at_location<'tcx>( prec.borrows_out_of_scope_at_location } -struct PoloniusOutOfScopePrecomputer<'a, 'tcx> { +struct PoloniusOutOfScopePrecomputer<'mir, 'tcx> { visited: BitSet, visit_stack: Vec, - body: &'a Body<'tcx>, - regioncx: &'a RegionInferenceContext<'tcx>, + body: &'mir Body<'tcx>, + regioncx: &'mir RegionInferenceContext<'tcx>, loans_out_of_scope_at_location: FxIndexMap>, } -impl<'a, 'tcx> PoloniusOutOfScopePrecomputer<'a, 'tcx> { - fn new(body: &'a Body<'tcx>, regioncx: &'a RegionInferenceContext<'tcx>) -> Self { +impl<'mir, 'tcx> PoloniusOutOfScopePrecomputer<'mir, 'tcx> { + fn new(body: &'mir Body<'tcx>, regioncx: &'mir RegionInferenceContext<'tcx>) -> Self { Self { visited: BitSet::new_empty(body.basic_blocks.len()), visit_stack: vec![], @@ -404,12 +404,12 @@ impl<'tcx> PoloniusOutOfScopePrecomputer<'_, 'tcx> { } } -impl<'a, 'tcx> Borrows<'a, 'tcx> { +impl<'mir, 'tcx> Borrows<'mir, 'tcx> { pub fn new( tcx: TyCtxt<'tcx>, - body: &'a Body<'tcx>, - regioncx: &'a RegionInferenceContext<'tcx>, - borrow_set: &'a BorrowSet<'tcx>, + body: &'mir Body<'tcx>, + regioncx: &'mir RegionInferenceContext<'tcx>, + borrow_set: &'mir BorrowSet<'tcx>, ) -> Self { let mut borrows_out_of_scope_at_location = calculate_borrows_out_of_scope_at_location(body, regioncx, borrow_set); diff --git a/compiler/rustc_borrowck/src/lib.rs b/compiler/rustc_borrowck/src/lib.rs index 0bfd2e7e710a6..804060d00ed00 100644 --- a/compiler/rustc_borrowck/src/lib.rs +++ b/compiler/rustc_borrowck/src/lib.rs @@ -288,7 +288,7 @@ fn do_mir_borrowck<'tcx>( .into_engine(tcx, body) .pass_name("borrowck") .iterate_to_fixpoint(); - let flow_ever_inits = EverInitializedPlaces::new(tcx, body, &mdpe) + let flow_ever_inits = EverInitializedPlaces::new(body, &mdpe) .into_engine(tcx, body) .pass_name("borrowck") .iterate_to_fixpoint(); diff --git a/compiler/rustc_mir_dataflow/src/drop_flag_effects.rs b/compiler/rustc_mir_dataflow/src/drop_flag_effects.rs index 163d74cc9cfb0..de1ca8d823b3e 100644 --- a/compiler/rustc_mir_dataflow/src/drop_flag_effects.rs +++ b/compiler/rustc_mir_dataflow/src/drop_flag_effects.rs @@ -1,10 +1,8 @@ use crate::elaborate_drops::DropFlagState; use rustc_middle::mir::{self, Body, Location, Terminator, TerminatorKind}; -use rustc_middle::ty::TyCtxt; use rustc_target::abi::VariantIdx; -use super::indexes::MovePathIndex; -use super::move_paths::{InitKind, LookupResult, MoveData}; +use super::move_paths::{InitKind, LookupResult, MoveData, MovePathIndex}; use super::MoveDataParamEnv; pub fn move_path_children_matching<'tcx, F>( @@ -30,8 +28,6 @@ where } pub fn on_lookup_result_bits<'tcx, F>( - tcx: TyCtxt<'tcx>, - body: &Body<'tcx>, move_data: &MoveData<'tcx>, lookup_result: LookupResult, each_child: F, @@ -42,13 +38,11 @@ pub fn on_lookup_result_bits<'tcx, F>( LookupResult::Parent(..) => { // access to untracked value - do not touch children } - LookupResult::Exact(e) => on_all_children_bits(tcx, body, move_data, e, each_child), + LookupResult::Exact(e) => on_all_children_bits(move_data, e, each_child), } } pub fn on_all_children_bits<'tcx, F>( - tcx: TyCtxt<'tcx>, - body: &Body<'tcx>, move_data: &MoveData<'tcx>, move_path_index: MovePathIndex, mut each_child: F, @@ -56,8 +50,6 @@ pub fn on_all_children_bits<'tcx, F>( F: FnMut(MovePathIndex), { fn on_all_children_bits<'tcx, F>( - tcx: TyCtxt<'tcx>, - body: &Body<'tcx>, move_data: &MoveData<'tcx>, move_path_index: MovePathIndex, each_child: &mut F, @@ -68,15 +60,14 @@ pub fn on_all_children_bits<'tcx, F>( let mut next_child_index = move_data.move_paths[move_path_index].first_child; while let Some(child_index) = next_child_index { - on_all_children_bits(tcx, body, move_data, child_index, each_child); + on_all_children_bits(move_data, child_index, each_child); next_child_index = move_data.move_paths[child_index].next_sibling; } } - on_all_children_bits(tcx, body, move_data, move_path_index, &mut each_child); + on_all_children_bits(move_data, move_path_index, &mut each_child); } pub fn drop_flag_effects_for_function_entry<'tcx, F>( - tcx: TyCtxt<'tcx>, body: &Body<'tcx>, ctxt: &MoveDataParamEnv<'tcx>, mut callback: F, @@ -87,14 +78,13 @@ pub fn drop_flag_effects_for_function_entry<'tcx, F>( for arg in body.args_iter() { let place = mir::Place::from(arg); let lookup_result = move_data.rev_lookup.find(place.as_ref()); - on_lookup_result_bits(tcx, body, move_data, lookup_result, |mpi| { + on_lookup_result_bits(move_data, lookup_result, |mpi| { callback(mpi, DropFlagState::Present) }); } } pub fn drop_flag_effects_for_location<'tcx, F>( - tcx: TyCtxt<'tcx>, body: &Body<'tcx>, ctxt: &MoveDataParamEnv<'tcx>, loc: Location, @@ -110,7 +100,7 @@ pub fn drop_flag_effects_for_location<'tcx, F>( let path = mi.move_path_index(move_data); debug!("moving out of path {:?}", move_data.move_paths[path]); - on_all_children_bits(tcx, body, move_data, path, |mpi| callback(mpi, DropFlagState::Absent)) + on_all_children_bits(move_data, path, |mpi| callback(mpi, DropFlagState::Absent)) } // Drop does not count as a move but we should still consider the variable uninitialized. @@ -118,24 +108,17 @@ pub fn drop_flag_effects_for_location<'tcx, F>( body.stmt_at(loc).right() { if let LookupResult::Exact(mpi) = move_data.rev_lookup.find(place.as_ref()) { - on_all_children_bits(tcx, body, move_data, mpi, |mpi| { - callback(mpi, DropFlagState::Absent) - }) + on_all_children_bits(move_data, mpi, |mpi| callback(mpi, DropFlagState::Absent)) } } debug!("drop_flag_effects: assignment for location({:?})", loc); - for_location_inits(tcx, body, move_data, loc, |mpi| callback(mpi, DropFlagState::Present)); + for_location_inits(move_data, loc, |mpi| callback(mpi, DropFlagState::Present)); } -pub fn for_location_inits<'tcx, F>( - tcx: TyCtxt<'tcx>, - body: &Body<'tcx>, - move_data: &MoveData<'tcx>, - loc: Location, - mut callback: F, -) where +fn for_location_inits<'tcx, F>(move_data: &MoveData<'tcx>, loc: Location, mut callback: F) +where F: FnMut(MovePathIndex), { for ii in &move_data.init_loc_map[loc] { @@ -144,7 +127,7 @@ pub fn for_location_inits<'tcx, F>( InitKind::Deep => { let path = init.path; - on_all_children_bits(tcx, body, move_data, path, &mut callback) + on_all_children_bits(move_data, path, &mut callback) } InitKind::Shallow => { let mpi = init.path; @@ -161,8 +144,6 @@ pub fn for_location_inits<'tcx, F>( /// NOTE: If there are no move paths corresponding to an inactive variant, /// `handle_inactive_variant` will not be called for that variant. pub(crate) fn on_all_inactive_variants<'tcx>( - tcx: TyCtxt<'tcx>, - body: &mir::Body<'tcx>, move_data: &MoveData<'tcx>, enum_place: mir::Place<'tcx>, active_variant: VariantIdx, @@ -185,9 +166,7 @@ pub(crate) fn on_all_inactive_variants<'tcx>( }; if variant_idx != active_variant { - on_all_children_bits(tcx, body, move_data, variant_mpi, |mpi| { - handle_inactive_variant(mpi) - }); + on_all_children_bits(move_data, variant_mpi, |mpi| handle_inactive_variant(mpi)); } } } diff --git a/compiler/rustc_mir_dataflow/src/framework/cursor.rs b/compiler/rustc_mir_dataflow/src/framework/cursor.rs index c978bddfef540..c9bce80853db9 100644 --- a/compiler/rustc_mir_dataflow/src/framework/cursor.rs +++ b/compiler/rustc_mir_dataflow/src/framework/cursor.rs @@ -147,7 +147,7 @@ where } /// Returns the underlying `Results`. - pub fn results(&mut self) -> &Results<'tcx, A, R::EntrySets> { + pub fn results(&self) -> &Results<'tcx, A, R::EntrySets> { self.results.borrow() } @@ -166,11 +166,6 @@ where &mut self.results.borrow_mut().analysis } - /// Returns both the dataflow state at the current location and the `Analysis`. - pub fn get_with_analysis(&mut self) -> (&A::Domain, &mut A) { - (&self.state, &mut self.results.borrow_mut().analysis) - } - /// Resets the cursor to hold the entry set for the given basic block. /// /// For forward dataflow analyses, this is the dataflow state prior to the first statement. diff --git a/compiler/rustc_mir_dataflow/src/framework/direction.rs b/compiler/rustc_mir_dataflow/src/framework/direction.rs index 04c9f7a016cc8..08b7b1a26193b 100644 --- a/compiler/rustc_mir_dataflow/src/framework/direction.rs +++ b/compiler/rustc_mir_dataflow/src/framework/direction.rs @@ -287,12 +287,12 @@ impl Direction for Backward { } } -struct BackwardSwitchIntEdgeEffectsApplier<'a, 'tcx, D, F> { - body: &'a mir::Body<'tcx>, +struct BackwardSwitchIntEdgeEffectsApplier<'mir, 'tcx, D, F> { + body: &'mir mir::Body<'tcx>, pred: BasicBlock, - exit_state: &'a mut D, + exit_state: &'mir mut D, bb: BasicBlock, - propagate: &'a mut F, + propagate: &'mir mut F, effects_applied: bool, } @@ -523,9 +523,9 @@ impl Direction for Forward { } } -struct ForwardSwitchIntEdgeEffectsApplier<'a, D, F> { - exit_state: &'a mut D, - targets: &'a SwitchTargets, +struct ForwardSwitchIntEdgeEffectsApplier<'mir, D, F> { + exit_state: &'mir mut D, + targets: &'mir SwitchTargets, propagate: F, effects_applied: bool, diff --git a/compiler/rustc_mir_dataflow/src/framework/engine.rs b/compiler/rustc_mir_dataflow/src/framework/engine.rs index 204e854235fdf..ed82b1e8cdcf4 100644 --- a/compiler/rustc_mir_dataflow/src/framework/engine.rs +++ b/compiler/rustc_mir_dataflow/src/framework/engine.rs @@ -128,12 +128,12 @@ where } /// A solver for dataflow problems. -pub struct Engine<'a, 'tcx, A> +pub struct Engine<'mir, 'tcx, A> where A: Analysis<'tcx>, { tcx: TyCtxt<'tcx>, - body: &'a mir::Body<'tcx>, + body: &'mir mir::Body<'tcx>, entry_sets: IndexVec, pass_name: Option<&'static str>, analysis: A, @@ -147,14 +147,14 @@ where apply_statement_trans_for_block: Option>, } -impl<'a, 'tcx, A, D, T> Engine<'a, 'tcx, A> +impl<'mir, 'tcx, A, D, T> Engine<'mir, 'tcx, A> where A: GenKillAnalysis<'tcx, Idx = T, Domain = D>, D: Clone + JoinSemiLattice + GenKill + BitSetExt, T: Idx, { /// Creates a new `Engine` to solve a gen-kill dataflow problem. - pub fn new_gen_kill(tcx: TyCtxt<'tcx>, body: &'a mir::Body<'tcx>, mut analysis: A) -> Self { + pub fn new_gen_kill(tcx: TyCtxt<'tcx>, body: &'mir mir::Body<'tcx>, mut analysis: A) -> Self { // If there are no back-edges in the control-flow graph, we only ever need to apply the // transfer function for each block exactly once (assuming that we process blocks in RPO). // @@ -186,7 +186,7 @@ where } } -impl<'a, 'tcx, A, D> Engine<'a, 'tcx, A> +impl<'mir, 'tcx, A, D> Engine<'mir, 'tcx, A> where A: Analysis<'tcx, Domain = D>, D: Clone + JoinSemiLattice, @@ -196,13 +196,13 @@ where /// /// Gen-kill problems should use `new_gen_kill`, which will coalesce transfer functions for /// better performance. - pub fn new_generic(tcx: TyCtxt<'tcx>, body: &'a mir::Body<'tcx>, analysis: A) -> Self { + pub fn new_generic(tcx: TyCtxt<'tcx>, body: &'mir mir::Body<'tcx>, analysis: A) -> Self { Self::new(tcx, body, analysis, None) } fn new( tcx: TyCtxt<'tcx>, - body: &'a mir::Body<'tcx>, + body: &'mir mir::Body<'tcx>, analysis: A, apply_statement_trans_for_block: Option>, ) -> Self { @@ -239,7 +239,6 @@ where tcx, apply_statement_trans_for_block, pass_name, - .. } = self; let mut dirty_queue: WorkQueue = WorkQueue::with_none(body.basic_blocks.len()); diff --git a/compiler/rustc_mir_dataflow/src/framework/graphviz.rs b/compiler/rustc_mir_dataflow/src/framework/graphviz.rs index c12ccba1e5c6d..832d1cba9a73b 100644 --- a/compiler/rustc_mir_dataflow/src/framework/graphviz.rs +++ b/compiler/rustc_mir_dataflow/src/framework/graphviz.rs @@ -15,7 +15,7 @@ use super::fmt::{DebugDiffWithAdapter, DebugWithAdapter, DebugWithContext}; use super::{Analysis, CallReturnPlaces, Direction, Results, ResultsRefCursor, ResultsVisitor}; #[derive(Clone, Copy, Debug, PartialEq, Eq)] -pub enum OutputStyle { +pub(crate) enum OutputStyle { AfterOnly, BeforeAndAfter, } @@ -29,7 +29,7 @@ impl OutputStyle { } } -pub struct Formatter<'res, 'mir, 'tcx, A> +pub(crate) struct Formatter<'res, 'mir, 'tcx, A> where A: Analysis<'tcx>, { @@ -43,7 +43,7 @@ impl<'res, 'mir, 'tcx, A> Formatter<'res, 'mir, 'tcx, A> where A: Analysis<'tcx>, { - pub fn new( + pub(crate) fn new( body: &'mir Body<'tcx>, results: &'res mut Results<'tcx, A>, style: OutputStyle, @@ -55,7 +55,7 @@ where /// A pair of a basic block and an index into that basic blocks `successors`. #[derive(Copy, Clone, PartialEq, Eq, Debug)] -pub struct CfgEdge { +pub(crate) struct CfgEdge { source: BasicBlock, index: usize, } diff --git a/compiler/rustc_mir_dataflow/src/framework/mod.rs b/compiler/rustc_mir_dataflow/src/framework/mod.rs index 5020a1cf0b27c..a5ae1edf221cb 100644 --- a/compiler/rustc_mir_dataflow/src/framework/mod.rs +++ b/compiler/rustc_mir_dataflow/src/framework/mod.rs @@ -45,7 +45,7 @@ pub mod graphviz; pub mod lattice; mod visitor; -pub use self::cursor::{AnalysisResults, ResultsClonedCursor, ResultsCursor, ResultsRefCursor}; +pub use self::cursor::{ResultsClonedCursor, ResultsCursor, ResultsRefCursor}; pub use self::direction::{Backward, Direction, Forward}; pub use self::engine::{Engine, EntrySets, Results, ResultsCloned}; pub use self::lattice::{JoinSemiLattice, MaybeReachable}; diff --git a/compiler/rustc_mir_dataflow/src/impls/initialized.rs b/compiler/rustc_mir_dataflow/src/impls/initialized.rs index 61be100d70e9b..b050e963d8ece 100644 --- a/compiler/rustc_mir_dataflow/src/impls/initialized.rs +++ b/compiler/rustc_mir_dataflow/src/impls/initialized.rs @@ -72,7 +72,7 @@ impl<'a, 'tcx> MaybeInitializedPlaces<'a, 'tcx> { ) -> bool { if let LookupResult::Exact(path) = self.move_data().rev_lookup.find(place.as_ref()) { let mut maybe_live = false; - on_all_children_bits(self.tcx, self.body, self.move_data(), path, |child| { + on_all_children_bits(self.move_data(), path, |child| { maybe_live |= state.contains(child); }); !maybe_live @@ -203,14 +203,13 @@ impl<'a, 'tcx> HasMoveData<'tcx> for MaybeUninitializedPlaces<'a, 'tcx> { /// this data and `MaybeInitializedPlaces` yields the set of places /// that would require a dynamic drop-flag at that statement. pub struct DefinitelyInitializedPlaces<'a, 'tcx> { - tcx: TyCtxt<'tcx>, body: &'a Body<'tcx>, mdpe: &'a MoveDataParamEnv<'tcx>, } impl<'a, 'tcx> DefinitelyInitializedPlaces<'a, 'tcx> { - pub fn new(tcx: TyCtxt<'tcx>, body: &'a Body<'tcx>, mdpe: &'a MoveDataParamEnv<'tcx>) -> Self { - DefinitelyInitializedPlaces { tcx, body, mdpe } + pub fn new(body: &'a Body<'tcx>, mdpe: &'a MoveDataParamEnv<'tcx>) -> Self { + DefinitelyInitializedPlaces { body, mdpe } } } @@ -250,15 +249,13 @@ impl<'a, 'tcx> HasMoveData<'tcx> for DefinitelyInitializedPlaces<'a, 'tcx> { /// } /// ``` pub struct EverInitializedPlaces<'a, 'tcx> { - #[allow(dead_code)] - tcx: TyCtxt<'tcx>, body: &'a Body<'tcx>, mdpe: &'a MoveDataParamEnv<'tcx>, } impl<'a, 'tcx> EverInitializedPlaces<'a, 'tcx> { - pub fn new(tcx: TyCtxt<'tcx>, body: &'a Body<'tcx>, mdpe: &'a MoveDataParamEnv<'tcx>) -> Self { - EverInitializedPlaces { tcx, body, mdpe } + pub fn new(body: &'a Body<'tcx>, mdpe: &'a MoveDataParamEnv<'tcx>) -> Self { + EverInitializedPlaces { body, mdpe } } } @@ -319,7 +316,7 @@ impl<'tcx> AnalysisDomain<'tcx> for MaybeInitializedPlaces<'_, 'tcx> { fn initialize_start_block(&self, _: &mir::Body<'tcx>, state: &mut Self::Domain) { *state = MaybeReachable::Reachable(ChunkedBitSet::new_empty(self.move_data().move_paths.len())); - drop_flag_effects_for_function_entry(self.tcx, self.body, self.mdpe, |path, s| { + drop_flag_effects_for_function_entry(self.body, self.mdpe, |path, s| { assert!(s == DropFlagState::Present); state.gen(path); }); @@ -339,7 +336,7 @@ impl<'tcx> GenKillAnalysis<'tcx> for MaybeInitializedPlaces<'_, 'tcx> { statement: &mir::Statement<'tcx>, location: Location, ) { - drop_flag_effects_for_location(self.tcx, self.body, self.mdpe, location, |path, s| { + drop_flag_effects_for_location(self.body, self.mdpe, location, |path, s| { Self::update_bits(trans, path, s) }); @@ -351,7 +348,7 @@ impl<'tcx> GenKillAnalysis<'tcx> for MaybeInitializedPlaces<'_, 'tcx> { | mir::Rvalue::AddressOf(_, place) = rvalue && let LookupResult::Exact(mpi) = self.move_data().rev_lookup.find(place.as_ref()) { - on_all_children_bits(self.tcx, self.body, self.move_data(), mpi, |child| { + on_all_children_bits(self.move_data(), mpi, |child| { trans.gen(child); }) } @@ -371,7 +368,7 @@ impl<'tcx> GenKillAnalysis<'tcx> for MaybeInitializedPlaces<'_, 'tcx> { { edges = TerminatorEdges::Single(target); } - drop_flag_effects_for_location(self.tcx, self.body, self.mdpe, location, |path, s| { + drop_flag_effects_for_location(self.body, self.mdpe, location, |path, s| { Self::update_bits(state, path, s) }); edges @@ -387,8 +384,6 @@ impl<'tcx> GenKillAnalysis<'tcx> for MaybeInitializedPlaces<'_, 'tcx> { // when a call returns successfully, that means we need to set // the bits for that dest_place to 1 (initialized). on_lookup_result_bits( - self.tcx, - self.body, self.move_data(), self.move_data().rev_lookup.find(place.as_ref()), |mpi| { @@ -432,8 +427,6 @@ impl<'tcx> GenKillAnalysis<'tcx> for MaybeInitializedPlaces<'_, 'tcx> { // Kill all move paths that correspond to variants we know to be inactive along this // particular outgoing edge of a `SwitchInt`. drop_flag_effects::on_all_inactive_variants( - self.tcx, - self.body, self.move_data(), enum_place, variant, @@ -458,7 +451,7 @@ impl<'tcx> AnalysisDomain<'tcx> for MaybeUninitializedPlaces<'_, 'tcx> { // set all bits to 1 (uninit) before gathering counter-evidence state.insert_all(); - drop_flag_effects_for_function_entry(self.tcx, self.body, self.mdpe, |path, s| { + drop_flag_effects_for_function_entry(self.body, self.mdpe, |path, s| { assert!(s == DropFlagState::Present); state.remove(path); }); @@ -478,7 +471,7 @@ impl<'tcx> GenKillAnalysis<'tcx> for MaybeUninitializedPlaces<'_, 'tcx> { _statement: &mir::Statement<'tcx>, location: Location, ) { - drop_flag_effects_for_location(self.tcx, self.body, self.mdpe, location, |path, s| { + drop_flag_effects_for_location(self.body, self.mdpe, location, |path, s| { Self::update_bits(trans, path, s) }); @@ -492,7 +485,7 @@ impl<'tcx> GenKillAnalysis<'tcx> for MaybeUninitializedPlaces<'_, 'tcx> { terminator: &'mir mir::Terminator<'tcx>, location: Location, ) -> TerminatorEdges<'mir, 'tcx> { - drop_flag_effects_for_location(self.tcx, self.body, self.mdpe, location, |path, s| { + drop_flag_effects_for_location(self.body, self.mdpe, location, |path, s| { Self::update_bits(trans, path, s) }); if self.skip_unreachable_unwind.contains(location.block) { @@ -514,8 +507,6 @@ impl<'tcx> GenKillAnalysis<'tcx> for MaybeUninitializedPlaces<'_, 'tcx> { // when a call returns successfully, that means we need to set // the bits for that dest_place to 0 (initialized). on_lookup_result_bits( - self.tcx, - self.body, self.move_data(), self.move_data().rev_lookup.find(place.as_ref()), |mpi| { @@ -563,8 +554,6 @@ impl<'tcx> GenKillAnalysis<'tcx> for MaybeUninitializedPlaces<'_, 'tcx> { // Mark all move paths that correspond to variants other than this one as maybe // uninitialized (in reality, they are *definitely* uninitialized). drop_flag_effects::on_all_inactive_variants( - self.tcx, - self.body, self.move_data(), enum_place, variant, @@ -589,7 +578,7 @@ impl<'a, 'tcx> AnalysisDomain<'tcx> for DefinitelyInitializedPlaces<'a, 'tcx> { fn initialize_start_block(&self, _: &mir::Body<'tcx>, state: &mut Self::Domain) { state.0.clear(); - drop_flag_effects_for_function_entry(self.tcx, self.body, self.mdpe, |path, s| { + drop_flag_effects_for_function_entry(self.body, self.mdpe, |path, s| { assert!(s == DropFlagState::Present); state.0.insert(path); }); @@ -609,7 +598,7 @@ impl<'tcx> GenKillAnalysis<'tcx> for DefinitelyInitializedPlaces<'_, 'tcx> { _statement: &mir::Statement<'tcx>, location: Location, ) { - drop_flag_effects_for_location(self.tcx, self.body, self.mdpe, location, |path, s| { + drop_flag_effects_for_location(self.body, self.mdpe, location, |path, s| { Self::update_bits(trans, path, s) }) } @@ -620,7 +609,7 @@ impl<'tcx> GenKillAnalysis<'tcx> for DefinitelyInitializedPlaces<'_, 'tcx> { terminator: &'mir mir::Terminator<'tcx>, location: Location, ) -> TerminatorEdges<'mir, 'tcx> { - drop_flag_effects_for_location(self.tcx, self.body, self.mdpe, location, |path, s| { + drop_flag_effects_for_location(self.body, self.mdpe, location, |path, s| { Self::update_bits(trans, path, s) }); terminator.edges() @@ -636,8 +625,6 @@ impl<'tcx> GenKillAnalysis<'tcx> for DefinitelyInitializedPlaces<'_, 'tcx> { // when a call returns successfully, that means we need to set // the bits for that dest_place to 1 (initialized). on_lookup_result_bits( - self.tcx, - self.body, self.move_data(), self.move_data().rev_lookup.find(place.as_ref()), |mpi| { diff --git a/compiler/rustc_mir_dataflow/src/impls/liveness.rs b/compiler/rustc_mir_dataflow/src/impls/liveness.rs index bdfb6a6ff6b1a..c3fdca1641ab5 100644 --- a/compiler/rustc_mir_dataflow/src/impls/liveness.rs +++ b/compiler/rustc_mir_dataflow/src/impls/liveness.rs @@ -23,7 +23,6 @@ use crate::{Analysis, AnalysisDomain, Backward, GenKill, GenKillAnalysis}; /// [`MaybeBorrowedLocals`]: super::MaybeBorrowedLocals /// [flow-test]: https://github.com/rust-lang/rust/blob/a08c47310c7d49cbdc5d7afb38408ba519967ecd/src/test/ui/mir-dataflow/liveness-ptr.rs /// [liveness]: https://en.wikipedia.org/wiki/Live_variable_analysis -#[derive(Clone, Copy)] pub struct MaybeLiveLocals; impl<'tcx> AnalysisDomain<'tcx> for MaybeLiveLocals { diff --git a/compiler/rustc_mir_dataflow/src/lib.rs b/compiler/rustc_mir_dataflow/src/lib.rs index eea0e030e7d3a..cd3378375d810 100644 --- a/compiler/rustc_mir_dataflow/src/lib.rs +++ b/compiler/rustc_mir_dataflow/src/lib.rs @@ -4,7 +4,6 @@ #![feature(let_chains)] #![feature(min_specialization)] #![feature(stmt_expr_attributes)] -#![feature(trusted_step)] #![recursion_limit = "256"] #![deny(rustc::untranslatable_diagnostic)] #![deny(rustc::diagnostic_outside_of_impl)] @@ -14,24 +13,19 @@ extern crate tracing; #[macro_use] extern crate rustc_middle; -use rustc_ast::MetaItem; use rustc_errors::{DiagnosticMessage, SubdiagnosticMessage}; use rustc_fluent_macro::fluent_messages; -use rustc_hir::def_id::DefId; -use rustc_middle::ty::{self, TyCtxt}; -use rustc_span::symbol::{sym, Symbol}; +use rustc_middle::ty; pub use self::drop_flag_effects::{ drop_flag_effects_for_function_entry, drop_flag_effects_for_location, move_path_children_matching, on_all_children_bits, on_lookup_result_bits, }; pub use self::framework::{ - fmt, graphviz, lattice, visit_results, Analysis, AnalysisDomain, AnalysisResults, Backward, - CloneAnalysis, Direction, Engine, Forward, GenKill, GenKillAnalysis, JoinSemiLattice, - MaybeReachable, Results, ResultsCloned, ResultsClonedCursor, ResultsCursor, ResultsRefCursor, - ResultsVisitable, ResultsVisitor, SwitchIntEdgeEffects, + fmt, lattice, visit_results, Analysis, AnalysisDomain, Direction, GenKill, GenKillAnalysis, + JoinSemiLattice, MaybeReachable, Results, ResultsCursor, ResultsVisitable, ResultsVisitor, }; - +use self::framework::{Backward, CloneAnalysis, ResultsClonedCursor, SwitchIntEdgeEffects}; use self::move_paths::MoveData; pub mod debuginfo; @@ -48,24 +42,7 @@ pub mod value_analysis; fluent_messages! { "../messages.ftl" } -pub(crate) mod indexes { - pub(crate) use super::move_paths::MovePathIndex; -} - pub struct MoveDataParamEnv<'tcx> { pub move_data: MoveData<'tcx>, pub param_env: ty::ParamEnv<'tcx>, } - -pub fn has_rustc_mir_with(tcx: TyCtxt<'_>, def_id: DefId, name: Symbol) -> Option { - for attr in tcx.get_attrs(def_id, sym::rustc_mir) { - let items = attr.meta_item_list(); - for item in items.iter().flat_map(|l| l.iter()) { - match item.meta_item() { - Some(mi) if mi.has_name(name) => return Some(mi.clone()), - _ => continue, - } - } - } - None -} diff --git a/compiler/rustc_mir_dataflow/src/rustc_peek.rs b/compiler/rustc_mir_dataflow/src/rustc_peek.rs index f9468c8e8ccb4..448128b6993fc 100644 --- a/compiler/rustc_mir_dataflow/src/rustc_peek.rs +++ b/compiler/rustc_mir_dataflow/src/rustc_peek.rs @@ -1,11 +1,3 @@ -use rustc_span::symbol::sym; -use rustc_span::Span; - -use rustc_index::bit_set::ChunkedBitSet; -use rustc_middle::mir::MirPass; -use rustc_middle::mir::{self, Body, Local, Location}; -use rustc_middle::ty::{self, Ty, TyCtxt}; - use crate::errors::{ PeekArgumentNotALocal, PeekArgumentUntracked, PeekBitNotSet, PeekMustBeNotTemporary, PeekMustBePlaceOrRefPlace, StopAfterDataFlowEndedCompilation, @@ -18,13 +10,33 @@ use crate::move_paths::{HasMoveData, MoveData}; use crate::move_paths::{LookupResult, MovePathIndex}; use crate::MoveDataParamEnv; use crate::{Analysis, JoinSemiLattice, ResultsCursor}; +use rustc_ast::MetaItem; +use rustc_hir::def_id::DefId; +use rustc_index::bit_set::ChunkedBitSet; +use rustc_middle::mir::MirPass; +use rustc_middle::mir::{self, Body, Local, Location}; +use rustc_middle::ty::{self, Ty, TyCtxt}; +use rustc_span::symbol::{sym, Symbol}; +use rustc_span::Span; pub struct SanityCheck; +fn has_rustc_mir_with(tcx: TyCtxt<'_>, def_id: DefId, name: Symbol) -> Option { + for attr in tcx.get_attrs(def_id, sym::rustc_mir) { + let items = attr.meta_item_list(); + for item in items.iter().flat_map(|l| l.iter()) { + match item.meta_item() { + Some(mi) if mi.has_name(name) => return Some(mi.clone()), + _ => continue, + } + } + } + None +} + // FIXME: This should be a `MirLint`, but it needs to be moved back to `rustc_mir_transform` first. impl<'tcx> MirPass<'tcx> for SanityCheck { fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { - use crate::has_rustc_mir_with; let def_id = body.source.def_id(); if !tcx.has_attr(def_id, sym::rustc_mir) { debug!("skipping rustc_peek::SanityCheck on {}", tcx.def_path_str(def_id)); @@ -54,7 +66,7 @@ impl<'tcx> MirPass<'tcx> for SanityCheck { } if has_rustc_mir_with(tcx, def_id, sym::rustc_peek_definite_init).is_some() { - let flow_def_inits = DefinitelyInitializedPlaces::new(tcx, body, &mdpe) + let flow_def_inits = DefinitelyInitializedPlaces::new(body, &mdpe) .into_engine(tcx, body) .iterate_to_fixpoint(); @@ -89,10 +101,8 @@ impl<'tcx> MirPass<'tcx> for SanityCheck { /// (If there are any calls to `rustc_peek` that do not match the /// expression form above, then that emits an error as well, but those /// errors are not intended to be used for unit tests.) -pub fn sanity_check_via_rustc_peek<'tcx, A>( - tcx: TyCtxt<'tcx>, - mut cursor: ResultsCursor<'_, 'tcx, A>, -) where +fn sanity_check_via_rustc_peek<'tcx, A>(tcx: TyCtxt<'tcx>, mut cursor: ResultsCursor<'_, 'tcx, A>) +where A: RustcPeekAt<'tcx>, { let def_id = cursor.body().source.def_id(); @@ -129,7 +139,8 @@ pub fn sanity_check_via_rustc_peek<'tcx, A>( ) => { let loc = Location { block: bb, statement_index }; cursor.seek_before_primary_effect(loc); - let (state, analysis) = cursor.get_with_analysis(); + let state = cursor.get(); + let analysis = cursor.analysis(); analysis.peek_at(tcx, *place, state, call); } @@ -173,7 +184,7 @@ impl PeekCallKind { } #[derive(Clone, Copy, Debug)] -pub struct PeekCall { +struct PeekCall { arg: Local, kind: PeekCallKind, span: Span, @@ -221,7 +232,7 @@ impl PeekCall { } } -pub trait RustcPeekAt<'tcx>: Analysis<'tcx> { +trait RustcPeekAt<'tcx>: Analysis<'tcx> { fn peek_at( &self, tcx: TyCtxt<'tcx>, diff --git a/compiler/rustc_mir_dataflow/src/un_derefer.rs b/compiler/rustc_mir_dataflow/src/un_derefer.rs index 874d50ffd0e21..b803ecc575ee0 100644 --- a/compiler/rustc_mir_dataflow/src/un_derefer.rs +++ b/compiler/rustc_mir_dataflow/src/un_derefer.rs @@ -3,13 +3,13 @@ use rustc_middle::mir::*; /// Used for reverting changes made by `DerefSeparator` #[derive(Default, Debug)] -pub struct UnDerefer<'tcx> { +pub(crate) struct UnDerefer<'tcx> { deref_chains: FxHashMap>>, } impl<'tcx> UnDerefer<'tcx> { #[inline] - pub fn insert(&mut self, local: Local, reffed: PlaceRef<'tcx>) { + pub(crate) fn insert(&mut self, local: Local, reffed: PlaceRef<'tcx>) { let mut chain = self.deref_chains.remove(&reffed.local).unwrap_or_default(); chain.push(reffed); self.deref_chains.insert(local, chain); @@ -17,7 +17,7 @@ impl<'tcx> UnDerefer<'tcx> { /// Returns the chain of places behind `DerefTemp` locals #[inline] - pub fn deref_chain(&self, local: Local) -> &[PlaceRef<'tcx>] { + pub(crate) fn deref_chain(&self, local: Local) -> &[PlaceRef<'tcx>] { self.deref_chains.get(&local).map(Vec::as_slice).unwrap_or_default() } @@ -25,7 +25,7 @@ impl<'tcx> UnDerefer<'tcx> { /// /// See [`PlaceRef::iter_projections`] #[inline] - pub fn iter_projections( + pub(crate) fn iter_projections( &self, place: PlaceRef<'tcx>, ) -> impl Iterator, PlaceElem<'tcx>)> + '_ { diff --git a/compiler/rustc_mir_dataflow/src/value_analysis.rs b/compiler/rustc_mir_dataflow/src/value_analysis.rs index 025d2ddfd4ff7..9dcd5f22a2d8d 100644 --- a/compiler/rustc_mir_dataflow/src/value_analysis.rs +++ b/compiler/rustc_mir_dataflow/src/value_analysis.rs @@ -332,8 +332,6 @@ pub struct ValueAnalysisWrapper(pub T); impl<'tcx, T: ValueAnalysis<'tcx>> AnalysisDomain<'tcx> for ValueAnalysisWrapper { type Domain = State; - type Direction = crate::Forward; - const NAME: &'static str = T::NAME; fn bottom_value(&self, _body: &Body<'tcx>) -> Self::Domain { @@ -476,26 +474,10 @@ impl State { } } - pub fn is_reachable(&self) -> bool { + fn is_reachable(&self) -> bool { matches!(&self.0, StateData::Reachable(_)) } - pub fn mark_unreachable(&mut self) { - self.0 = StateData::Unreachable; - } - - pub fn flood_all(&mut self) - where - V: HasTop, - { - self.flood_all_with(V::TOP) - } - - pub fn flood_all_with(&mut self, value: V) { - let StateData::Reachable(values) = &mut self.0 else { return }; - values.raw.fill(value); - } - /// Assign `value` to all places that are contained in `place` or may alias one. pub fn flood_with(&mut self, place: PlaceRef<'_>, map: &Map, value: V) { self.flood_with_tail_elem(place, None, map, value) @@ -510,7 +492,7 @@ impl State { } /// Assign `value` to the discriminant of `place` and all places that may alias it. - pub fn flood_discr_with(&mut self, place: PlaceRef<'_>, map: &Map, value: V) { + fn flood_discr_with(&mut self, place: PlaceRef<'_>, map: &Map, value: V) { self.flood_with_tail_elem(place, Some(TrackElem::Discriminant), map, value) } @@ -546,7 +528,7 @@ impl State { /// This does nothing if the place is not tracked. /// /// The target place must have been flooded before calling this method. - pub fn insert_idx(&mut self, target: PlaceIndex, result: ValueOrPlace, map: &Map) { + fn insert_idx(&mut self, target: PlaceIndex, result: ValueOrPlace, map: &Map) { match result { ValueOrPlace::Value(value) => self.insert_value_idx(target, value, map), ValueOrPlace::Place(source) => self.insert_place_idx(target, source, map), @@ -910,18 +892,13 @@ impl Map { self.inner_values[root] = start..end; } - /// Returns the number of tracked places, i.e., those for which a value can be stored. - pub fn tracked_places(&self) -> usize { - self.value_count - } - /// Applies a single projection element, yielding the corresponding child. pub fn apply(&self, place: PlaceIndex, elem: TrackElem) -> Option { self.projections.get(&(place, elem)).copied() } /// Locates the given place, if it exists in the tree. - pub fn find_extra( + fn find_extra( &self, place: PlaceRef<'_>, extra: impl IntoIterator, @@ -954,7 +931,7 @@ impl Map { } /// Iterate over all direct children. - pub fn children(&self, parent: PlaceIndex) -> impl Iterator + '_ { + fn children(&self, parent: PlaceIndex) -> impl Iterator + '_ { Children::new(self, parent) } diff --git a/compiler/rustc_mir_transform/src/coroutine.rs b/compiler/rustc_mir_transform/src/coroutine.rs index 42540911785b8..df9c84c35ac90 100644 --- a/compiler/rustc_mir_transform/src/coroutine.rs +++ b/compiler/rustc_mir_transform/src/coroutine.rs @@ -667,36 +667,34 @@ fn locals_live_across_suspend_points<'tcx>( always_live_locals: &BitSet, movable: bool, ) -> LivenessInfo { - let body_ref: &Body<'_> = body; - // Calculate when MIR locals have live storage. This gives us an upper bound of their // lifetimes. let mut storage_live = MaybeStorageLive::new(std::borrow::Cow::Borrowed(always_live_locals)) - .into_engine(tcx, body_ref) + .into_engine(tcx, body) .iterate_to_fixpoint() - .into_results_cursor(body_ref); + .into_results_cursor(body); // Calculate the MIR locals which have been previously // borrowed (even if they are still active). let borrowed_locals_results = - MaybeBorrowedLocals.into_engine(tcx, body_ref).pass_name("coroutine").iterate_to_fixpoint(); + MaybeBorrowedLocals.into_engine(tcx, body).pass_name("coroutine").iterate_to_fixpoint(); - let mut borrowed_locals_cursor = borrowed_locals_results.cloned_results_cursor(body_ref); + let mut borrowed_locals_cursor = borrowed_locals_results.cloned_results_cursor(body); // Calculate the MIR locals that we actually need to keep storage around // for. let mut requires_storage_results = MaybeRequiresStorage::new(borrowed_locals_results.cloned_results_cursor(body)) - .into_engine(tcx, body_ref) + .into_engine(tcx, body) .iterate_to_fixpoint(); - let mut requires_storage_cursor = requires_storage_results.as_results_cursor(body_ref); + let mut requires_storage_cursor = requires_storage_results.as_results_cursor(body); // Calculate the liveness of MIR locals ignoring borrows. let mut liveness = MaybeLiveLocals - .into_engine(tcx, body_ref) + .into_engine(tcx, body) .pass_name("coroutine") .iterate_to_fixpoint() - .into_results_cursor(body_ref); + .into_results_cursor(body); let mut storage_liveness_map = IndexVec::from_elem(None, &body.basic_blocks); let mut live_locals_at_suspension_points = Vec::new(); @@ -762,7 +760,7 @@ fn locals_live_across_suspend_points<'tcx>( .collect(); let storage_conflicts = compute_storage_conflicts( - body_ref, + body, &saved_locals, always_live_locals.clone(), requires_storage_results, diff --git a/compiler/rustc_mir_transform/src/elaborate_drops.rs b/compiler/rustc_mir_transform/src/elaborate_drops.rs index d4e40a1b57cab..83517aef7e2f5 100644 --- a/compiler/rustc_mir_transform/src/elaborate_drops.rs +++ b/compiler/rustc_mir_transform/src/elaborate_drops.rs @@ -172,19 +172,13 @@ impl<'a, 'tcx> DropElaborator<'a, 'tcx> for Elaborator<'a, '_, 'tcx> { let mut some_live = false; let mut some_dead = false; let mut children_count = 0; - on_all_children_bits( - self.tcx(), - self.body(), - self.ctxt.move_data(), - path, - |child| { - let (live, dead) = self.ctxt.init_data.maybe_live_dead(child); - debug!("elaborate_drop: state({:?}) = {:?}", child, (live, dead)); - some_live |= live; - some_dead |= dead; - children_count += 1; - }, - ); + on_all_children_bits(self.ctxt.move_data(), path, |child| { + let (live, dead) = self.ctxt.init_data.maybe_live_dead(child); + debug!("elaborate_drop: state({:?}) = {:?}", child, (live, dead)); + some_live |= live; + some_dead |= dead; + children_count += 1; + }); ((some_live, some_dead), children_count != 1) } }; @@ -202,13 +196,9 @@ impl<'a, 'tcx> DropElaborator<'a, 'tcx> for Elaborator<'a, '_, 'tcx> { self.ctxt.set_drop_flag(loc, path, DropFlagState::Absent); } DropFlagMode::Deep => { - on_all_children_bits( - self.tcx(), - self.body(), - self.ctxt.move_data(), - path, - |child| self.ctxt.set_drop_flag(loc, child, DropFlagState::Absent), - ); + on_all_children_bits(self.ctxt.move_data(), path, |child| { + self.ctxt.set_drop_flag(loc, child, DropFlagState::Absent) + }); } } } @@ -268,10 +258,9 @@ impl<'b, 'tcx> ElaborateDropsCtxt<'b, 'tcx> { } fn create_drop_flag(&mut self, index: MovePathIndex, span: Span) { - let tcx = self.tcx; let patch = &mut self.patch; debug!("create_drop_flag({:?})", self.body.span); - self.drop_flags[index].get_or_insert_with(|| patch.new_temp(tcx.types.bool, span)); + self.drop_flags[index].get_or_insert_with(|| patch.new_temp(self.tcx.types.bool, span)); } fn drop_flag(&mut self, index: MovePathIndex) -> Option> { @@ -304,7 +293,7 @@ impl<'b, 'tcx> ElaborateDropsCtxt<'b, 'tcx> { match path { LookupResult::Exact(path) => { self.init_data.seek_before(self.body.terminator_loc(bb)); - on_all_children_bits(self.tcx, self.body, self.move_data(), path, |child| { + on_all_children_bits(self.move_data(), path, |child| { let (maybe_live, maybe_dead) = self.init_data.maybe_live_dead(child); debug!( "collect_drop_flags: collecting {:?} from {:?}@{:?} - {:?}", @@ -444,7 +433,7 @@ impl<'b, 'tcx> ElaborateDropsCtxt<'b, 'tcx> { let loc = Location { block: tgt, statement_index: 0 }; let path = self.move_data().rev_lookup.find(destination.as_ref()); - on_lookup_result_bits(self.tcx, self.body, self.move_data(), path, |child| { + on_lookup_result_bits(self.move_data(), path, |child| { self.set_drop_flag(loc, child, DropFlagState::Present) }); } @@ -453,14 +442,9 @@ impl<'b, 'tcx> ElaborateDropsCtxt<'b, 'tcx> { fn drop_flags_for_args(&mut self) { let loc = Location::START; - rustc_mir_dataflow::drop_flag_effects_for_function_entry( - self.tcx, - self.body, - self.env, - |path, ds| { - self.set_drop_flag(loc, path, ds); - }, - ) + rustc_mir_dataflow::drop_flag_effects_for_function_entry(self.body, self.env, |path, ds| { + self.set_drop_flag(loc, path, ds); + }) } fn drop_flags_for_locs(&mut self) { @@ -492,7 +476,6 @@ impl<'b, 'tcx> ElaborateDropsCtxt<'b, 'tcx> { } let loc = Location { block: bb, statement_index: i }; rustc_mir_dataflow::drop_flag_effects_for_location( - self.tcx, self.body, self.env, loc, @@ -515,7 +498,7 @@ impl<'b, 'tcx> ElaborateDropsCtxt<'b, 'tcx> { let loc = Location { block: bb, statement_index: data.statements.len() }; let path = self.move_data().rev_lookup.find(destination.as_ref()); - on_lookup_result_bits(self.tcx, self.body, self.move_data(), path, |child| { + on_lookup_result_bits(self.move_data(), path, |child| { self.set_drop_flag(loc, child, DropFlagState::Present) }); }