Skip to content

Commit 525f655

Browse files
committed
Minimize use of GenKill.
Thanks to the previous couple of commits, many uses of the `GenKill` trait can be replaced with a concrete type.
1 parent 13968b4 commit 525f655

File tree

5 files changed

+33
-34
lines changed

5 files changed

+33
-34
lines changed

compiler/rustc_borrowck/src/dataflow.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ impl<'a, 'tcx> Borrows<'a, 'tcx> {
427427
/// That means they went out of a nonlexical scope
428428
fn kill_loans_out_of_scope_at_location(
429429
&self,
430-
trans: &mut impl GenKill<BorrowIndex>,
430+
trans: &mut <Self as AnalysisDomain<'tcx>>::Domain,
431431
location: Location,
432432
) {
433433
// NOTE: The state associated with a given `location`
@@ -447,7 +447,11 @@ impl<'a, 'tcx> Borrows<'a, 'tcx> {
447447
}
448448

449449
/// Kill any borrows that conflict with `place`.
450-
fn kill_borrows_on_place(&self, trans: &mut impl GenKill<BorrowIndex>, place: Place<'tcx>) {
450+
fn kill_borrows_on_place(
451+
&self,
452+
trans: &mut <Self as AnalysisDomain<'tcx>>::Domain,
453+
place: Place<'tcx>,
454+
) {
451455
debug!("kill_borrows_on_place: place={:?}", place);
452456

453457
let other_borrows_of_local = self

compiler/rustc_mir_dataflow/src/framework/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -305,11 +305,11 @@ pub trait GenKillAnalysis<'tcx>: Analysis<'tcx> {
305305
);
306306

307307
/// See `Analysis::apply_switch_int_edge_effects`.
308-
fn switch_int_edge_effects<G: GenKill<Self::Idx>>(
308+
fn switch_int_edge_effects(
309309
&mut self,
310310
_block: BasicBlock,
311311
_discr: &mir::Operand<'tcx>,
312-
_edge_effects: &mut impl SwitchIntEdgeEffects<G>,
312+
_edge_effects: &mut impl SwitchIntEdgeEffects<Self::Domain>,
313313
) {
314314
}
315315
}

compiler/rustc_mir_dataflow/src/impls/initialized.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ impl<'tcx> HasMoveData<'tcx> for EverInitializedPlaces<'_, 'tcx> {
270270

271271
impl<'a, 'tcx> MaybeInitializedPlaces<'a, 'tcx> {
272272
fn update_bits(
273-
trans: &mut impl GenKill<MovePathIndex>,
273+
trans: &mut <Self as AnalysisDomain<'tcx>>::Domain,
274274
path: MovePathIndex,
275275
state: DropFlagState,
276276
) {
@@ -283,7 +283,7 @@ impl<'a, 'tcx> MaybeInitializedPlaces<'a, 'tcx> {
283283

284284
impl<'tcx> MaybeUninitializedPlaces<'_, 'tcx> {
285285
fn update_bits(
286-
trans: &mut impl GenKill<MovePathIndex>,
286+
trans: &mut <Self as AnalysisDomain<'tcx>>::Domain,
287287
path: MovePathIndex,
288288
state: DropFlagState,
289289
) {
@@ -296,7 +296,7 @@ impl<'tcx> MaybeUninitializedPlaces<'_, 'tcx> {
296296

297297
impl<'a, 'tcx> DefinitelyInitializedPlaces<'a, 'tcx> {
298298
fn update_bits(
299-
trans: &mut impl GenKill<MovePathIndex>,
299+
trans: &mut <Self as AnalysisDomain<'tcx>>::Domain,
300300
path: MovePathIndex,
301301
state: DropFlagState,
302302
) {
@@ -399,11 +399,11 @@ impl<'tcx> GenKillAnalysis<'tcx> for MaybeInitializedPlaces<'_, 'tcx> {
399399
});
400400
}
401401

402-
fn switch_int_edge_effects<G: GenKill<Self::Idx>>(
402+
fn switch_int_edge_effects(
403403
&mut self,
404404
block: mir::BasicBlock,
405405
discr: &mir::Operand<'tcx>,
406-
edge_effects: &mut impl SwitchIntEdgeEffects<G>,
406+
edge_effects: &mut impl SwitchIntEdgeEffects<Self::Domain>,
407407
) {
408408
if !self.tcx.sess.opts.unstable_opts.precise_enum_drop_elaboration {
409409
return;
@@ -524,11 +524,11 @@ impl<'tcx> GenKillAnalysis<'tcx> for MaybeUninitializedPlaces<'_, 'tcx> {
524524
});
525525
}
526526

527-
fn switch_int_edge_effects<G: GenKill<Self::Idx>>(
527+
fn switch_int_edge_effects(
528528
&mut self,
529529
block: mir::BasicBlock,
530530
discr: &mir::Operand<'tcx>,
531-
edge_effects: &mut impl SwitchIntEdgeEffects<G>,
531+
edge_effects: &mut impl SwitchIntEdgeEffects<Self::Domain>,
532532
) {
533533
if !self.tcx.sess.opts.unstable_opts.precise_enum_drop_elaboration {
534534
return;

compiler/rustc_mir_dataflow/src/impls/liveness.rs

+9-15
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,9 @@ impl<'tcx> GenKillAnalysis<'tcx> for MaybeLiveLocals {
8989
}
9090
}
9191

92-
pub struct TransferFunction<'a, T>(pub &'a mut T);
92+
pub struct TransferFunction<'a>(pub &'a mut BitSet<Local>);
9393

94-
impl<'tcx, T> Visitor<'tcx> for TransferFunction<'_, T>
95-
where
96-
T: GenKill<Local>,
97-
{
94+
impl<'tcx> Visitor<'tcx> for TransferFunction<'_> {
9895
fn visit_place(&mut self, place: &mir::Place<'tcx>, context: PlaceContext, location: Location) {
9996
if let PlaceContext::MutatingUse(MutatingUseContext::Yield) = context {
10097
// The resume place is evaluated and assigned to only after coroutine resumes, so its
@@ -108,10 +105,10 @@ where
108105
MutatingUseContext::Call | MutatingUseContext::AsmOutput,
109106
) = context
110107
{
111-
// For the associated terminators, this is only a `Def` when the terminator returns
112-
// "successfully." As such, we handle this case separately in `call_return_effect`
113-
// above. However, if the place looks like `*_5`, this is still unconditionally a use of
114-
// `_5`.
108+
// For the associated terminators, this is only a `Def` when the terminator
109+
// returns "successfully." As such, we handle this case separately in
110+
// `call_return_effect` above. However, if the place looks like `*_5`, this is
111+
// still unconditionally a use of `_5`.
115112
} else {
116113
self.0.kill(place.local);
117114
}
@@ -128,12 +125,9 @@ where
128125
}
129126
}
130127

131-
struct YieldResumeEffect<'a, T>(&'a mut T);
128+
struct YieldResumeEffect<'a>(&'a mut BitSet<Local>);
132129

133-
impl<'tcx, T> Visitor<'tcx> for YieldResumeEffect<'_, T>
134-
where
135-
T: GenKill<Local>,
136-
{
130+
impl<'tcx> Visitor<'tcx> for YieldResumeEffect<'_> {
137131
fn visit_place(&mut self, place: &mir::Place<'tcx>, context: PlaceContext, location: Location) {
138132
DefUse::apply(self.0, *place, context);
139133
self.visit_projection(place.as_ref(), context, location);
@@ -151,7 +145,7 @@ enum DefUse {
151145
}
152146

153147
impl DefUse {
154-
fn apply(trans: &mut impl GenKill<Local>, place: Place<'_>, context: PlaceContext) {
148+
fn apply(trans: &mut BitSet<Local>, place: Place<'_>, context: PlaceContext) {
155149
match DefUse::for_place(place, context) {
156150
Some(DefUse::Def) => trans.kill(place.local),
157151
Some(DefUse::Use) => trans.gen_(place.local),

compiler/rustc_mir_dataflow/src/impls/storage_liveness.rs

+9-8
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use rustc_middle::mir::visit::{NonMutatingUseContext, PlaceContext, Visitor};
55
use rustc_middle::mir::*;
66

77
use super::MaybeBorrowedLocals;
8-
use crate::{GenKill, ResultsCursor};
8+
use crate::{AnalysisDomain, GenKill, ResultsCursor};
99

1010
pub struct MaybeStorageLive<'a> {
1111
always_live_locals: Cow<'a, BitSet<Local>>,
@@ -330,22 +330,23 @@ impl<'tcx> crate::GenKillAnalysis<'tcx> for MaybeRequiresStorage<'_, 'tcx> {
330330

331331
impl<'tcx> MaybeRequiresStorage<'_, 'tcx> {
332332
/// Kill locals that are fully moved and have not been borrowed.
333-
fn check_for_move(&mut self, trans: &mut impl GenKill<Local>, loc: Location) {
333+
fn check_for_move(
334+
&mut self,
335+
trans: &mut <Self as AnalysisDomain<'tcx>>::Domain,
336+
loc: Location,
337+
) {
334338
let body = self.borrowed_locals.body();
335339
let mut visitor = MoveVisitor { trans, borrowed_locals: &mut self.borrowed_locals };
336340
visitor.visit_location(body, loc);
337341
}
338342
}
339343

340-
struct MoveVisitor<'a, 'mir, 'tcx, T> {
344+
struct MoveVisitor<'a, 'mir, 'tcx> {
341345
borrowed_locals: &'a mut BorrowedLocalsResults<'mir, 'tcx>,
342-
trans: &'a mut T,
346+
trans: &'a mut BitSet<Local>,
343347
}
344348

345-
impl<'tcx, T> Visitor<'tcx> for MoveVisitor<'_, '_, 'tcx, T>
346-
where
347-
T: GenKill<Local>,
348-
{
349+
impl<'tcx> Visitor<'tcx> for MoveVisitor<'_, '_, 'tcx> {
349350
fn visit_local(&mut self, local: Local, context: PlaceContext, loc: Location) {
350351
if PlaceContext::NonMutatingUse(NonMutatingUseContext::Move) == context {
351352
self.borrowed_locals.seek_before_primary_effect(loc);

0 commit comments

Comments
 (0)