1
Fork 0

Add defaults for Analysis::apply_{call_return_effect,terminator_effect}.

To avoid some low-value boilerplate code.
This commit is contained in:
Nicholas Nethercote 2024-10-10 12:06:25 +11:00
parent ba13775319
commit 33abf6a0c8
5 changed files with 11 additions and 72 deletions

View file

@ -1,9 +1,7 @@
use rustc_data_structures::fx::FxIndexMap; use rustc_data_structures::fx::FxIndexMap;
use rustc_data_structures::graph; use rustc_data_structures::graph;
use rustc_index::bit_set::BitSet; use rustc_index::bit_set::BitSet;
use rustc_middle::mir::{ use rustc_middle::mir::{self, BasicBlock, Body, Location, Place, TerminatorEdges};
self, BasicBlock, Body, CallReturnPlaces, Location, Place, TerminatorEdges,
};
use rustc_middle::ty::{RegionVid, TyCtxt}; use rustc_middle::ty::{RegionVid, TyCtxt};
use rustc_mir_dataflow::fmt::DebugWithContext; use rustc_mir_dataflow::fmt::DebugWithContext;
use rustc_mir_dataflow::impls::{EverInitializedPlaces, MaybeUninitializedPlaces}; use rustc_mir_dataflow::impls::{EverInitializedPlaces, MaybeUninitializedPlaces};
@ -595,14 +593,6 @@ impl<'tcx> rustc_mir_dataflow::Analysis<'tcx> for Borrows<'_, 'tcx> {
} }
terminator.edges() terminator.edges()
} }
fn apply_call_return_effect(
&mut self,
_trans: &mut Self::Domain,
_block: mir::BasicBlock,
_return_places: CallReturnPlaces<'_, 'tcx>,
) {
}
} }
impl<C> DebugWithContext<C> for BorrowIndex {} impl<C> DebugWithContext<C> for BorrowIndex {}

View file

@ -164,10 +164,12 @@ pub trait Analysis<'tcx> {
/// initialized here. /// initialized here.
fn apply_terminator_effect<'mir>( fn apply_terminator_effect<'mir>(
&mut self, &mut self,
state: &mut Self::Domain, _state: &mut Self::Domain,
terminator: &'mir mir::Terminator<'tcx>, terminator: &'mir mir::Terminator<'tcx>,
location: Location, _location: Location,
) -> TerminatorEdges<'mir, 'tcx>; ) -> TerminatorEdges<'mir, 'tcx> {
terminator.edges()
}
/// Updates the current dataflow state with an effect that occurs immediately *before* the /// Updates the current dataflow state with an effect that occurs immediately *before* the
/// given terminator. /// given terminator.
@ -192,10 +194,11 @@ pub trait Analysis<'tcx> {
/// edges. /// edges.
fn apply_call_return_effect( fn apply_call_return_effect(
&mut self, &mut self,
state: &mut Self::Domain, _state: &mut Self::Domain,
block: BasicBlock, _block: BasicBlock,
return_places: CallReturnPlaces<'_, 'tcx>, _return_places: CallReturnPlaces<'_, 'tcx>,
); ) {
}
/// Updates the current dataflow state with the effect of taking a particular branch in a /// Updates the current dataflow state with the effect of taking a particular branch in a
/// `SwitchInt` terminator. /// `SwitchInt` terminator.

View file

@ -208,14 +208,6 @@ impl<'tcx, D: Direction> Analysis<'tcx> for MockAnalysis<'tcx, D> {
let idx = self.effect(Effect::Before.at_index(location.statement_index)); let idx = self.effect(Effect::Before.at_index(location.statement_index));
assert!(state.insert(idx)); assert!(state.insert(idx));
} }
fn apply_call_return_effect(
&mut self,
_state: &mut Self::Domain,
_block: BasicBlock,
_return_places: CallReturnPlaces<'_, 'tcx>,
) {
}
} }
#[derive(Clone, Copy, Debug, PartialEq, Eq)] #[derive(Clone, Copy, Debug, PartialEq, Eq)]

View file

@ -51,14 +51,6 @@ impl<'tcx> Analysis<'tcx> for MaybeBorrowedLocals {
self.transfer_function(trans).visit_terminator(terminator, location); self.transfer_function(trans).visit_terminator(terminator, location);
terminator.edges() terminator.edges()
} }
fn apply_call_return_effect(
&mut self,
_trans: &mut Self::Domain,
_block: BasicBlock,
_return_places: CallReturnPlaces<'_, 'tcx>,
) {
}
} }
/// A `Visitor` that defines the transfer function for `MaybeBorrowedLocals`. /// A `Visitor` that defines the transfer function for `MaybeBorrowedLocals`.

View file

@ -50,25 +50,6 @@ impl<'a, 'tcx> Analysis<'tcx> for MaybeStorageLive<'a> {
_ => (), _ => (),
} }
} }
fn apply_terminator_effect<'mir>(
&mut self,
_trans: &mut Self::Domain,
terminator: &'mir Terminator<'tcx>,
_: Location,
) -> TerminatorEdges<'mir, 'tcx> {
// Terminators have no effect
terminator.edges()
}
fn apply_call_return_effect(
&mut self,
_trans: &mut Self::Domain,
_block: BasicBlock,
_return_places: CallReturnPlaces<'_, 'tcx>,
) {
// Nothing to do when a call returns successfully
}
} }
pub struct MaybeStorageDead<'a> { pub struct MaybeStorageDead<'a> {
@ -113,25 +94,6 @@ impl<'a, 'tcx> Analysis<'tcx> for MaybeStorageDead<'a> {
_ => (), _ => (),
} }
} }
fn apply_terminator_effect<'mir>(
&mut self,
_: &mut Self::Domain,
terminator: &'mir Terminator<'tcx>,
_: Location,
) -> TerminatorEdges<'mir, 'tcx> {
// Terminators have no effect
terminator.edges()
}
fn apply_call_return_effect(
&mut self,
_trans: &mut Self::Domain,
_block: BasicBlock,
_return_places: CallReturnPlaces<'_, 'tcx>,
) {
// Nothing to do when a call returns successfully
}
} }
type BorrowedLocalsResults<'mir, 'tcx> = ResultsCursor<'mir, 'tcx, MaybeBorrowedLocals>; type BorrowedLocalsResults<'mir, 'tcx> = ResultsCursor<'mir, 'tcx, MaybeBorrowedLocals>;