Skip to content

Commit

Permalink
Minimize use of GenKill.
Browse files Browse the repository at this point in the history
Thanks to the previous couple of commits, many uses of the `GenKill`
trait can be replaced with a concrete type.
  • Loading branch information
nnethercote committed Oct 10, 2024
1 parent c41bf5f commit 83e2947
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 34 deletions.
8 changes: 6 additions & 2 deletions compiler/rustc_borrowck/src/dataflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_mir_dataflow/src/framework/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>,
) {
}
}
Expand Down
14 changes: 7 additions & 7 deletions compiler/rustc_mir_dataflow/src/impls/initialized.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
) {
Expand All @@ -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,
) {
Expand All @@ -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,
) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
24 changes: 9 additions & 15 deletions compiler/rustc_mir_dataflow/src/impls/liveness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
}
Expand All @@ -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);
Expand All @@ -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),
Expand Down
17 changes: 9 additions & 8 deletions compiler/rustc_mir_dataflow/src/impls/storage_liveness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>>,
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 83e2947

Please sign in to comment.