Skip to content

Commit 52b90f7

Browse files
committed
In MaybeRequiresStorage, store Results instead of ResultsCursor.
This requires a `clone` call in `check_for_move`, but makes `MaybeRequiresStorage` an immutable analysis, which enables the next commit.
1 parent c4c2d2c commit 52b90f7

File tree

2 files changed

+19
-21
lines changed

2 files changed

+19
-21
lines changed

compiler/rustc_mir_dataflow/src/impls/storage_liveness.rs

Lines changed: 15 additions & 16 deletions
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::{Analysis, GenKill, ResultsCursor};
8+
use crate::{Analysis, GenKill, Results, ResultsCursor};
99

1010
pub struct MaybeStorageLive<'a> {
1111
always_live_locals: Cow<'a, BitSet<Local>>,
@@ -96,17 +96,19 @@ impl<'a, 'tcx> Analysis<'tcx> for MaybeStorageDead<'a> {
9696
}
9797
}
9898

99-
type BorrowedLocalsResults<'mir, 'tcx> = ResultsCursor<'mir, 'tcx, MaybeBorrowedLocals>;
100-
10199
/// Dataflow analysis that determines whether each local requires storage at a
102100
/// given location; i.e. whether its storage can go away without being observed.
103101
pub struct MaybeRequiresStorage<'mir, 'tcx> {
104-
borrowed_locals: BorrowedLocalsResults<'mir, 'tcx>,
102+
body: &'mir Body<'tcx>,
103+
borrowed_locals: Results<'tcx, MaybeBorrowedLocals>,
105104
}
106105

107106
impl<'mir, 'tcx> MaybeRequiresStorage<'mir, 'tcx> {
108-
pub fn new(borrowed_locals: BorrowedLocalsResults<'mir, 'tcx>) -> Self {
109-
MaybeRequiresStorage { borrowed_locals }
107+
pub fn new(
108+
body: &'mir Body<'tcx>,
109+
borrowed_locals: Results<'tcx, MaybeBorrowedLocals>,
110+
) -> Self {
111+
MaybeRequiresStorage { body, borrowed_locals }
110112
}
111113
}
112114

@@ -135,7 +137,7 @@ impl<'tcx> Analysis<'tcx> for MaybeRequiresStorage<'_, 'tcx> {
135137
loc: Location,
136138
) {
137139
// If a place is borrowed in a statement, it needs storage for that statement.
138-
self.borrowed_locals.mut_analysis().apply_statement_effect(trans, stmt, loc);
140+
self.borrowed_locals.analysis.apply_statement_effect(trans, stmt, loc);
139141

140142
match &stmt.kind {
141143
StatementKind::StorageDead(l) => trans.kill(*l),
@@ -179,10 +181,7 @@ impl<'tcx> Analysis<'tcx> for MaybeRequiresStorage<'_, 'tcx> {
179181
loc: Location,
180182
) {
181183
// If a place is borrowed in a terminator, it needs storage for that terminator.
182-
self.borrowed_locals
183-
.mut_analysis()
184-
.transfer_function(trans)
185-
.visit_terminator(terminator, loc);
184+
self.borrowed_locals.analysis.transfer_function(trans).visit_terminator(terminator, loc);
186185

187186
match &terminator.kind {
188187
TerminatorKind::Call { destination, .. } => {
@@ -283,15 +282,15 @@ impl<'tcx> Analysis<'tcx> for MaybeRequiresStorage<'_, 'tcx> {
283282

284283
impl<'tcx> MaybeRequiresStorage<'_, 'tcx> {
285284
/// Kill locals that are fully moved and have not been borrowed.
286-
fn check_for_move(&mut self, trans: &mut <Self as Analysis<'tcx>>::Domain, loc: Location) {
287-
let body = self.borrowed_locals.body();
288-
let mut visitor = MoveVisitor { trans, borrowed_locals: &mut self.borrowed_locals };
289-
visitor.visit_location(body, loc);
285+
fn check_for_move(&self, trans: &mut <Self as Analysis<'tcx>>::Domain, loc: Location) {
286+
let borrowed_locals = self.borrowed_locals.clone().into_results_cursor(self.body);
287+
let mut visitor = MoveVisitor { trans, borrowed_locals };
288+
visitor.visit_location(self.body, loc);
290289
}
291290
}
292291

293292
struct MoveVisitor<'a, 'mir, 'tcx> {
294-
borrowed_locals: &'a mut BorrowedLocalsResults<'mir, 'tcx>,
293+
borrowed_locals: ResultsCursor<'mir, 'tcx, MaybeBorrowedLocals>,
295294
trans: &'a mut BitSet<Local>,
296295
}
297296

compiler/rustc_mir_transform/src/coroutine.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -679,11 +679,10 @@ fn locals_live_across_suspend_points<'tcx>(
679679

680680
// Calculate the MIR locals that we actually need to keep storage around
681681
// for.
682-
let mut requires_storage_cursor =
683-
MaybeRequiresStorage::new(borrowed_locals_results.into_results_cursor(body))
684-
.into_engine(tcx, body)
685-
.iterate_to_fixpoint()
686-
.into_results_cursor(body);
682+
let mut requires_storage_cursor = MaybeRequiresStorage::new(body, borrowed_locals_results)
683+
.into_engine(tcx, body)
684+
.iterate_to_fixpoint()
685+
.into_results_cursor(body);
687686

688687
// Calculate the liveness of MIR locals ignoring borrows.
689688
let mut liveness = MaybeLiveLocals

0 commit comments

Comments
 (0)