mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-21 22:34:05 +00:00
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:
parent
13968b4a70
commit
525f655866
@ -427,7 +427,7 @@ impl<'a, 'tcx> Borrows<'a, 'tcx> {
|
||||
/// That means they went out of a nonlexical scope
|
||||
fn kill_loans_out_of_scope_at_location(
|
||||
&self,
|
||||
trans: &mut impl GenKill<BorrowIndex>,
|
||||
trans: &mut <Self as AnalysisDomain<'tcx>>::Domain,
|
||||
location: 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`.
|
||||
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);
|
||||
|
||||
let other_borrows_of_local = self
|
||||
|
@ -305,11 +305,11 @@ pub trait GenKillAnalysis<'tcx>: Analysis<'tcx> {
|
||||
);
|
||||
|
||||
/// See `Analysis::apply_switch_int_edge_effects`.
|
||||
fn switch_int_edge_effects<G: GenKill<Self::Idx>>(
|
||||
fn switch_int_edge_effects(
|
||||
&mut self,
|
||||
_block: BasicBlock,
|
||||
_discr: &mir::Operand<'tcx>,
|
||||
_edge_effects: &mut impl SwitchIntEdgeEffects<G>,
|
||||
_edge_effects: &mut impl SwitchIntEdgeEffects<Self::Domain>,
|
||||
) {
|
||||
}
|
||||
}
|
||||
|
@ -270,7 +270,7 @@ impl<'tcx> HasMoveData<'tcx> for EverInitializedPlaces<'_, 'tcx> {
|
||||
|
||||
impl<'a, 'tcx> MaybeInitializedPlaces<'a, 'tcx> {
|
||||
fn update_bits(
|
||||
trans: &mut impl GenKill<MovePathIndex>,
|
||||
trans: &mut <Self as AnalysisDomain<'tcx>>::Domain,
|
||||
path: MovePathIndex,
|
||||
state: DropFlagState,
|
||||
) {
|
||||
@ -283,7 +283,7 @@ impl<'a, 'tcx> MaybeInitializedPlaces<'a, 'tcx> {
|
||||
|
||||
impl<'tcx> MaybeUninitializedPlaces<'_, 'tcx> {
|
||||
fn update_bits(
|
||||
trans: &mut impl GenKill<MovePathIndex>,
|
||||
trans: &mut <Self as AnalysisDomain<'tcx>>::Domain,
|
||||
path: MovePathIndex,
|
||||
state: DropFlagState,
|
||||
) {
|
||||
@ -296,7 +296,7 @@ impl<'tcx> MaybeUninitializedPlaces<'_, 'tcx> {
|
||||
|
||||
impl<'a, 'tcx> DefinitelyInitializedPlaces<'a, 'tcx> {
|
||||
fn update_bits(
|
||||
trans: &mut impl GenKill<MovePathIndex>,
|
||||
trans: &mut <Self as AnalysisDomain<'tcx>>::Domain,
|
||||
path: MovePathIndex,
|
||||
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,
|
||||
block: mir::BasicBlock,
|
||||
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 {
|
||||
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,
|
||||
block: mir::BasicBlock,
|
||||
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 {
|
||||
return;
|
||||
|
@ -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>
|
||||
where
|
||||
T: GenKill<Local>,
|
||||
{
|
||||
impl<'tcx> Visitor<'tcx> for TransferFunction<'_> {
|
||||
fn visit_place(&mut self, place: &mir::Place<'tcx>, context: PlaceContext, location: Location) {
|
||||
if let PlaceContext::MutatingUse(MutatingUseContext::Yield) = context {
|
||||
// The resume place is evaluated and assigned to only after coroutine resumes, so its
|
||||
@ -108,10 +105,10 @@ where
|
||||
MutatingUseContext::Call | MutatingUseContext::AsmOutput,
|
||||
) = context
|
||||
{
|
||||
// For the associated terminators, this is only a `Def` when the terminator returns
|
||||
// "successfully." As such, we handle this case separately in `call_return_effect`
|
||||
// above. However, if the place looks like `*_5`, this is still unconditionally a use of
|
||||
// `_5`.
|
||||
// For the associated terminators, this is only a `Def` when the terminator
|
||||
// returns "successfully." As such, we handle this case separately in
|
||||
// `call_return_effect` above. However, if the place looks like `*_5`, this is
|
||||
// still unconditionally a use of `_5`.
|
||||
} else {
|
||||
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>
|
||||
where
|
||||
T: GenKill<Local>,
|
||||
{
|
||||
impl<'tcx> Visitor<'tcx> for YieldResumeEffect<'_> {
|
||||
fn visit_place(&mut self, place: &mir::Place<'tcx>, context: PlaceContext, location: Location) {
|
||||
DefUse::apply(self.0, *place, context);
|
||||
self.visit_projection(place.as_ref(), context, location);
|
||||
@ -151,7 +145,7 @@ enum 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) {
|
||||
Some(DefUse::Def) => trans.kill(place.local),
|
||||
Some(DefUse::Use) => trans.gen_(place.local),
|
||||
|
@ -5,7 +5,7 @@ use rustc_middle::mir::visit::{NonMutatingUseContext, PlaceContext, Visitor};
|
||||
use rustc_middle::mir::*;
|
||||
|
||||
use super::MaybeBorrowedLocals;
|
||||
use crate::{GenKill, ResultsCursor};
|
||||
use crate::{AnalysisDomain, GenKill, ResultsCursor};
|
||||
|
||||
pub struct MaybeStorageLive<'a> {
|
||||
always_live_locals: Cow<'a, BitSet<Local>>,
|
||||
@ -330,22 +330,23 @@ impl<'tcx> crate::GenKillAnalysis<'tcx> for MaybeRequiresStorage<'_, 'tcx> {
|
||||
|
||||
impl<'tcx> MaybeRequiresStorage<'_, 'tcx> {
|
||||
/// 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 mut visitor = MoveVisitor { trans, borrowed_locals: &mut self.borrowed_locals };
|
||||
visitor.visit_location(body, loc);
|
||||
}
|
||||
}
|
||||
|
||||
struct MoveVisitor<'a, 'mir, 'tcx, T> {
|
||||
struct MoveVisitor<'a, '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>
|
||||
where
|
||||
T: GenKill<Local>,
|
||||
{
|
||||
impl<'tcx> Visitor<'tcx> for MoveVisitor<'_, '_, 'tcx> {
|
||||
fn visit_local(&mut self, local: Local, context: PlaceContext, loc: Location) {
|
||||
if PlaceContext::NonMutatingUse(NonMutatingUseContext::Move) == context {
|
||||
self.borrowed_locals.seek_before_primary_effect(loc);
|
||||
|
Loading…
Reference in New Issue
Block a user