Skip to content

Commit a68e2c7

Browse files
committed
Clean up extra lifetime, add assertions
1 parent d8ed2e7 commit a68e2c7

File tree

3 files changed

+26
-25
lines changed

3 files changed

+26
-25
lines changed

src/librustc_mir/dataflow/impls/storage_liveness.rs

+16-12
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ impl<'a, 'tcx> BitDenotation<'tcx> for MaybeStorageLive<'a, 'tcx> {
3333
}
3434

3535
fn start_block_effect(&self, _on_entry: &mut BitSet<Local>) {
36-
// Nothing is live on function entry
36+
// Nothing is live on function entry (generators only have a self
37+
// argument, and we don't care about that)
38+
assert_eq!(1, self.body.arg_count);
3739
}
3840

3941
fn statement_effect(&self,
@@ -72,16 +74,16 @@ impl<'a, 'tcx> BottomValue for MaybeStorageLive<'a, 'tcx> {
7274

7375
/// Dataflow analysis that determines whether each local requires storage at a
7476
/// given location; i.e. whether its storage can go away without being observed.
75-
pub struct RequiresStorage<'mir, 'tcx, 'b> {
77+
pub struct RequiresStorage<'mir, 'tcx> {
7678
body: &'mir Body<'tcx>,
7779
borrowed_locals:
78-
RefCell<DataflowResultsRefCursor<'mir, 'tcx, 'b, HaveBeenBorrowedLocals<'mir, 'tcx>>>,
80+
RefCell<DataflowResultsRefCursor<'mir, 'tcx, HaveBeenBorrowedLocals<'mir, 'tcx>>>,
7981
}
8082

81-
impl<'mir, 'tcx: 'mir, 'b> RequiresStorage<'mir, 'tcx, 'b> {
83+
impl<'mir, 'tcx: 'mir> RequiresStorage<'mir, 'tcx> {
8284
pub fn new(
8385
body: &'mir Body<'tcx>,
84-
borrowed_locals: &'b DataflowResults<'tcx, HaveBeenBorrowedLocals<'mir, 'tcx>>,
86+
borrowed_locals: &'mir DataflowResults<'tcx, HaveBeenBorrowedLocals<'mir, 'tcx>>,
8587
) -> Self {
8688
RequiresStorage {
8789
body,
@@ -94,15 +96,17 @@ impl<'mir, 'tcx: 'mir, 'b> RequiresStorage<'mir, 'tcx, 'b> {
9496
}
9597
}
9698

97-
impl<'mir, 'tcx, 'b> BitDenotation<'tcx> for RequiresStorage<'mir, 'tcx, 'b> {
99+
impl<'mir, 'tcx> BitDenotation<'tcx> for RequiresStorage<'mir, 'tcx> {
98100
type Idx = Local;
99101
fn name() -> &'static str { "requires_storage" }
100102
fn bits_per_block(&self) -> usize {
101103
self.body.local_decls.len()
102104
}
103105

104106
fn start_block_effect(&self, _sets: &mut BitSet<Local>) {
105-
// Nothing is live on function entry
107+
// Nothing is live on function entry (generators only have a self
108+
// argument, and we don't care about that)
109+
assert_eq!(1, self.body.arg_count);
106110
}
107111

108112
fn statement_effect(&self,
@@ -146,7 +150,7 @@ impl<'mir, 'tcx, 'b> BitDenotation<'tcx> for RequiresStorage<'mir, 'tcx, 'b> {
146150
}
147151
}
148152

149-
impl<'mir, 'tcx, 'b> RequiresStorage<'mir, 'tcx, 'b> {
153+
impl<'mir, 'tcx> RequiresStorage<'mir, 'tcx> {
150154
/// Kill locals that are fully moved and have not been borrowed.
151155
fn check_for_move(&self, sets: &mut GenKillSet<Local>, loc: Location) {
152156
let mut visitor = MoveVisitor {
@@ -165,18 +169,18 @@ impl<'mir, 'tcx, 'b> RequiresStorage<'mir, 'tcx, 'b> {
165169
}
166170
}
167171

168-
impl<'mir, 'tcx, 'b> BottomValue for RequiresStorage<'mir, 'tcx, 'b> {
172+
impl<'mir, 'tcx> BottomValue for RequiresStorage<'mir, 'tcx> {
169173
/// bottom = dead
170174
const BOTTOM_VALUE: bool = false;
171175
}
172176

173-
struct MoveVisitor<'a, 'b, 'mir, 'tcx> {
177+
struct MoveVisitor<'a, 'mir, 'tcx> {
174178
borrowed_locals:
175-
&'a RefCell<DataflowResultsRefCursor<'mir, 'tcx, 'b, HaveBeenBorrowedLocals<'mir, 'tcx>>>,
179+
&'a RefCell<DataflowResultsRefCursor<'mir, 'tcx, HaveBeenBorrowedLocals<'mir, 'tcx>>>,
176180
sets: &'a mut GenKillSet<Local>,
177181
}
178182

179-
impl<'a, 'b, 'mir: 'a, 'tcx> Visitor<'tcx> for MoveVisitor<'a, 'b, 'mir, 'tcx> {
183+
impl<'a, 'mir: 'a, 'tcx> Visitor<'tcx> for MoveVisitor<'a, 'mir, 'tcx> {
180184
fn visit_local(&mut self, local: &Local, context: PlaceContext, loc: Location) {
181185
if PlaceContext::NonMutatingUse(NonMutatingUseContext::Move) == context {
182186
let mut borrowed_locals = self.borrowed_locals.borrow_mut();

src/librustc_mir/dataflow/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -359,8 +359,8 @@ where
359359
body: &'mir Body<'tcx>,
360360
}
361361

362-
pub type DataflowResultsRefCursor<'mir, 'tcx, 'flow, BD> =
363-
DataflowResultsCursor<'mir, 'tcx, BD, &'flow DataflowResults<'tcx, BD>>;
362+
pub type DataflowResultsRefCursor<'mir, 'tcx, BD> =
363+
DataflowResultsCursor<'mir, 'tcx, BD, &'mir DataflowResults<'tcx, BD>>;
364364

365365
impl<'mir, 'tcx, BD, DR> DataflowResultsCursor<'mir, 'tcx, BD, DR>
366366
where

src/librustc_mir/transform/generator.rs

+8-11
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ use rustc_data_structures::indexed_vec::{Idx, IndexVec};
6262
use rustc_data_structures::bit_set::{BitSet, BitMatrix};
6363
use std::borrow::Cow;
6464
use std::iter;
65-
use std::marker::PhantomData;
6665
use std::mem;
6766
use crate::transform::{MirPass, MirSource};
6867
use crate::transform::simplify;
@@ -578,8 +577,8 @@ fn compute_storage_conflicts(
578577
body: &'mir Body<'tcx>,
579578
stored_locals: &liveness::LiveVarSet,
580579
ignored: &StorageIgnored,
581-
requires_storage: DataflowResults<'tcx, RequiresStorage<'mir, 'tcx, '_>>,
582-
_requires_storage_analysis: RequiresStorage<'mir, 'tcx, '_>,
580+
requires_storage: DataflowResults<'tcx, RequiresStorage<'mir, 'tcx>>,
581+
_requires_storage_analysis: RequiresStorage<'mir, 'tcx>,
583582
) -> BitMatrix<GeneratorSavedLocal, GeneratorSavedLocal> {
584583
assert_eq!(body.local_decls.len(), ignored.0.domain_size());
585584
assert_eq!(body.local_decls.len(), stored_locals.domain_size());
@@ -596,7 +595,6 @@ fn compute_storage_conflicts(
596595
body,
597596
stored_locals: &stored_locals,
598597
local_conflicts: BitMatrix::from_row_n(&ineligible_locals, body.local_decls.len()),
599-
_phantom: PhantomData::default(),
600598
};
601599
let mut state = FlowAtLocation::new(requires_storage);
602600
visitor.analyze_results(&mut state);
@@ -628,19 +626,18 @@ fn compute_storage_conflicts(
628626
storage_conflicts
629627
}
630628

631-
struct StorageConflictVisitor<'body: 'b, 'tcx, 's, 'b> {
629+
struct StorageConflictVisitor<'body, 'tcx, 's> {
632630
body: &'body Body<'tcx>,
633631
stored_locals: &'s liveness::LiveVarSet,
634632
// FIXME(tmandry): Consider using sparse bitsets here once we have good
635633
// benchmarks for generators.
636634
local_conflicts: BitMatrix<Local, Local>,
637-
_phantom: PhantomData<&'b ()>,
638635
}
639636

640-
impl<'body, 'tcx, 's, 'b> DataflowResultsConsumer<'body, 'tcx>
641-
for StorageConflictVisitor<'body, 'tcx, 's, 'b>
637+
impl<'body, 'tcx, 's> DataflowResultsConsumer<'body, 'tcx>
638+
for StorageConflictVisitor<'body, 'tcx, 's>
642639
{
643-
type FlowState = FlowAtLocation<'tcx, RequiresStorage<'body, 'tcx, 'b>>;
640+
type FlowState = FlowAtLocation<'tcx, RequiresStorage<'body, 'tcx>>;
644641

645642
fn body(&self) -> &'body Body<'tcx> {
646643
self.body
@@ -668,9 +665,9 @@ impl<'body, 'tcx, 's, 'b> DataflowResultsConsumer<'body, 'tcx>
668665
}
669666
}
670667

671-
impl<'body, 'tcx, 's, 'b> StorageConflictVisitor<'body, 'tcx, 's, 'b> {
668+
impl<'body, 'tcx, 's> StorageConflictVisitor<'body, 'tcx, 's> {
672669
fn apply_state(&mut self,
673-
flow_state: &FlowAtLocation<'tcx, RequiresStorage<'body, 'tcx, 'b>>,
670+
flow_state: &FlowAtLocation<'tcx, RequiresStorage<'body, 'tcx>>,
674671
loc: Location) {
675672
// Ignore unreachable blocks.
676673
match self.body.basic_blocks()[loc.block].terminator().kind {

0 commit comments

Comments
 (0)