1
Fork 0

Minimize use of GenKill.

Thanks to the previous couple of commits, many uses of the `GenKill`
trait can be replaced with a concrete type.
This commit is contained in:
Nicholas Nethercote 2024-10-10 10:14:58 +11:00
parent 13968b4a70
commit 525f655866
5 changed files with 33 additions and 34 deletions

View file

@ -427,7 +427,7 @@ impl<'a, 'tcx> Borrows<'a, 'tcx> {
/// That means they went out of a nonlexical scope /// That means they went out of a nonlexical scope
fn kill_loans_out_of_scope_at_location( fn kill_loans_out_of_scope_at_location(
&self, &self,
trans: &mut impl GenKill<BorrowIndex>, trans: &mut <Self as AnalysisDomain<'tcx>>::Domain,
location: Location, location: Location,
) { ) {
// NOTE: The state associated with a given `location` // NOTE: The state associated with a given `location`
@ -447,7 +447,11 @@ impl<'a, 'tcx> Borrows<'a, 'tcx> {
} }
/// Kill any borrows that conflict with `place`. /// Kill any borrows that conflict with `place`.
fn kill_borrows_on_place(&self, trans: &mut impl GenKill<BorrowIndex>, place: Place<'tcx>) { fn kill_borrows_on_place(
&self,
trans: &mut <Self as AnalysisDomain<'tcx>>::Domain,
place: Place<'tcx>,
) {
debug!("kill_borrows_on_place: place={:?}", place); debug!("kill_borrows_on_place: place={:?}", place);
let other_borrows_of_local = self let other_borrows_of_local = self

View file

@ -305,11 +305,11 @@ pub trait GenKillAnalysis<'tcx>: Analysis<'tcx> {
); );
/// See `Analysis::apply_switch_int_edge_effects`. /// See `Analysis::apply_switch_int_edge_effects`.
fn switch_int_edge_effects<G: GenKill<Self::Idx>>( fn switch_int_edge_effects(
&mut self, &mut self,
_block: BasicBlock, _block: BasicBlock,
_discr: &mir::Operand<'tcx>, _discr: &mir::Operand<'tcx>,
_edge_effects: &mut impl SwitchIntEdgeEffects<G>, _edge_effects: &mut impl SwitchIntEdgeEffects<Self::Domain>,
) { ) {
} }
} }

View file

@ -270,7 +270,7 @@ impl<'tcx> HasMoveData<'tcx> for EverInitializedPlaces<'_, 'tcx> {
impl<'a, 'tcx> MaybeInitializedPlaces<'a, 'tcx> { impl<'a, 'tcx> MaybeInitializedPlaces<'a, 'tcx> {
fn update_bits( fn update_bits(
trans: &mut impl GenKill<MovePathIndex>, trans: &mut <Self as AnalysisDomain<'tcx>>::Domain,
path: MovePathIndex, path: MovePathIndex,
state: DropFlagState, state: DropFlagState,
) { ) {
@ -283,7 +283,7 @@ impl<'a, 'tcx> MaybeInitializedPlaces<'a, 'tcx> {
impl<'tcx> MaybeUninitializedPlaces<'_, 'tcx> { impl<'tcx> MaybeUninitializedPlaces<'_, 'tcx> {
fn update_bits( fn update_bits(
trans: &mut impl GenKill<MovePathIndex>, trans: &mut <Self as AnalysisDomain<'tcx>>::Domain,
path: MovePathIndex, path: MovePathIndex,
state: DropFlagState, state: DropFlagState,
) { ) {
@ -296,7 +296,7 @@ impl<'tcx> MaybeUninitializedPlaces<'_, 'tcx> {
impl<'a, 'tcx> DefinitelyInitializedPlaces<'a, 'tcx> { impl<'a, 'tcx> DefinitelyInitializedPlaces<'a, 'tcx> {
fn update_bits( fn update_bits(
trans: &mut impl GenKill<MovePathIndex>, trans: &mut <Self as AnalysisDomain<'tcx>>::Domain,
path: MovePathIndex, path: MovePathIndex,
state: DropFlagState, state: DropFlagState,
) { ) {
@ -399,11 +399,11 @@ impl<'tcx> GenKillAnalysis<'tcx> for MaybeInitializedPlaces<'_, 'tcx> {
}); });
} }
fn switch_int_edge_effects<G: GenKill<Self::Idx>>( fn switch_int_edge_effects(
&mut self, &mut self,
block: mir::BasicBlock, block: mir::BasicBlock,
discr: &mir::Operand<'tcx>, discr: &mir::Operand<'tcx>,
edge_effects: &mut impl SwitchIntEdgeEffects<G>, edge_effects: &mut impl SwitchIntEdgeEffects<Self::Domain>,
) { ) {
if !self.tcx.sess.opts.unstable_opts.precise_enum_drop_elaboration { if !self.tcx.sess.opts.unstable_opts.precise_enum_drop_elaboration {
return; return;
@ -524,11 +524,11 @@ impl<'tcx> GenKillAnalysis<'tcx> for MaybeUninitializedPlaces<'_, 'tcx> {
}); });
} }
fn switch_int_edge_effects<G: GenKill<Self::Idx>>( fn switch_int_edge_effects(
&mut self, &mut self,
block: mir::BasicBlock, block: mir::BasicBlock,
discr: &mir::Operand<'tcx>, discr: &mir::Operand<'tcx>,
edge_effects: &mut impl SwitchIntEdgeEffects<G>, edge_effects: &mut impl SwitchIntEdgeEffects<Self::Domain>,
) { ) {
if !self.tcx.sess.opts.unstable_opts.precise_enum_drop_elaboration { if !self.tcx.sess.opts.unstable_opts.precise_enum_drop_elaboration {
return; return;

View file

@ -89,12 +89,9 @@ impl<'tcx> GenKillAnalysis<'tcx> for MaybeLiveLocals {
} }
} }
pub struct TransferFunction<'a, T>(pub &'a mut T); pub struct TransferFunction<'a>(pub &'a mut BitSet<Local>);
impl<'tcx, T> Visitor<'tcx> for TransferFunction<'_, T> impl<'tcx> Visitor<'tcx> for TransferFunction<'_> {
where
T: GenKill<Local>,
{
fn visit_place(&mut self, place: &mir::Place<'tcx>, context: PlaceContext, location: Location) { fn visit_place(&mut self, place: &mir::Place<'tcx>, context: PlaceContext, location: Location) {
if let PlaceContext::MutatingUse(MutatingUseContext::Yield) = context { if let PlaceContext::MutatingUse(MutatingUseContext::Yield) = context {
// The resume place is evaluated and assigned to only after coroutine resumes, so its // The resume place is evaluated and assigned to only after coroutine resumes, so its
@ -108,10 +105,10 @@ where
MutatingUseContext::Call | MutatingUseContext::AsmOutput, MutatingUseContext::Call | MutatingUseContext::AsmOutput,
) = context ) = context
{ {
// For the associated terminators, this is only a `Def` when the terminator returns // For the associated terminators, this is only a `Def` when the terminator
// "successfully." As such, we handle this case separately in `call_return_effect` // returns "successfully." As such, we handle this case separately in
// above. However, if the place looks like `*_5`, this is still unconditionally a use of // `call_return_effect` above. However, if the place looks like `*_5`, this is
// `_5`. // still unconditionally a use of `_5`.
} else { } else {
self.0.kill(place.local); self.0.kill(place.local);
} }
@ -128,12 +125,9 @@ where
} }
} }
struct YieldResumeEffect<'a, T>(&'a mut T); struct YieldResumeEffect<'a>(&'a mut BitSet<Local>);
impl<'tcx, T> Visitor<'tcx> for YieldResumeEffect<'_, T> impl<'tcx> Visitor<'tcx> for YieldResumeEffect<'_> {
where
T: GenKill<Local>,
{
fn visit_place(&mut self, place: &mir::Place<'tcx>, context: PlaceContext, location: Location) { fn visit_place(&mut self, place: &mir::Place<'tcx>, context: PlaceContext, location: Location) {
DefUse::apply(self.0, *place, context); DefUse::apply(self.0, *place, context);
self.visit_projection(place.as_ref(), context, location); self.visit_projection(place.as_ref(), context, location);
@ -151,7 +145,7 @@ enum DefUse {
} }
impl DefUse { impl DefUse {
fn apply(trans: &mut impl GenKill<Local>, place: Place<'_>, context: PlaceContext) { fn apply(trans: &mut BitSet<Local>, place: Place<'_>, context: PlaceContext) {
match DefUse::for_place(place, context) { match DefUse::for_place(place, context) {
Some(DefUse::Def) => trans.kill(place.local), Some(DefUse::Def) => trans.kill(place.local),
Some(DefUse::Use) => trans.gen_(place.local), Some(DefUse::Use) => trans.gen_(place.local),

View file

@ -5,7 +5,7 @@ use rustc_middle::mir::visit::{NonMutatingUseContext, PlaceContext, Visitor};
use rustc_middle::mir::*; use rustc_middle::mir::*;
use super::MaybeBorrowedLocals; use super::MaybeBorrowedLocals;
use crate::{GenKill, ResultsCursor}; use crate::{AnalysisDomain, GenKill, ResultsCursor};
pub struct MaybeStorageLive<'a> { pub struct MaybeStorageLive<'a> {
always_live_locals: Cow<'a, BitSet<Local>>, always_live_locals: Cow<'a, BitSet<Local>>,
@ -330,22 +330,23 @@ impl<'tcx> crate::GenKillAnalysis<'tcx> for MaybeRequiresStorage<'_, 'tcx> {
impl<'tcx> MaybeRequiresStorage<'_, 'tcx> { impl<'tcx> MaybeRequiresStorage<'_, 'tcx> {
/// Kill locals that are fully moved and have not been borrowed. /// Kill locals that are fully moved and have not been borrowed.
fn check_for_move(&mut self, trans: &mut impl GenKill<Local>, loc: Location) { fn check_for_move(
&mut self,
trans: &mut <Self as AnalysisDomain<'tcx>>::Domain,
loc: Location,
) {
let body = self.borrowed_locals.body(); let body = self.borrowed_locals.body();
let mut visitor = MoveVisitor { trans, borrowed_locals: &mut self.borrowed_locals }; let mut visitor = MoveVisitor { trans, borrowed_locals: &mut self.borrowed_locals };
visitor.visit_location(body, loc); visitor.visit_location(body, loc);
} }
} }
struct MoveVisitor<'a, 'mir, 'tcx, T> { struct MoveVisitor<'a, 'mir, 'tcx> {
borrowed_locals: &'a mut BorrowedLocalsResults<'mir, 'tcx>, borrowed_locals: &'a mut BorrowedLocalsResults<'mir, 'tcx>,
trans: &'a mut T, trans: &'a mut BitSet<Local>,
} }
impl<'tcx, T> Visitor<'tcx> for MoveVisitor<'_, '_, 'tcx, T> impl<'tcx> Visitor<'tcx> for MoveVisitor<'_, '_, 'tcx> {
where
T: GenKill<Local>,
{
fn visit_local(&mut self, local: Local, context: PlaceContext, loc: Location) { fn visit_local(&mut self, local: Local, context: PlaceContext, loc: Location) {
if PlaceContext::NonMutatingUse(NonMutatingUseContext::Move) == context { if PlaceContext::NonMutatingUse(NonMutatingUseContext::Move) == context {
self.borrowed_locals.seek_before_primary_effect(loc); self.borrowed_locals.seek_before_primary_effect(loc);