Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Still more rustc_mir_dataflow cleanups #132062

Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 15 additions & 16 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::{Analysis, GenKill, ResultsCursor};
use crate::{Analysis, GenKill, Results, ResultsCursor};

pub struct MaybeStorageLive<'a> {
always_live_locals: Cow<'a, BitSet<Local>>,
Expand Down Expand Up @@ -96,17 +96,19 @@ impl<'a, 'tcx> Analysis<'tcx> for MaybeStorageDead<'a> {
}
}

type BorrowedLocalsResults<'mir, 'tcx> = ResultsCursor<'mir, 'tcx, MaybeBorrowedLocals>;

/// Dataflow analysis that determines whether each local requires storage at a
/// given location; i.e. whether its storage can go away without being observed.
pub struct MaybeRequiresStorage<'mir, 'tcx> {
borrowed_locals: BorrowedLocalsResults<'mir, 'tcx>,
body: &'mir Body<'tcx>,
borrowed_locals: Results<'tcx, MaybeBorrowedLocals>,
}

impl<'mir, 'tcx> MaybeRequiresStorage<'mir, 'tcx> {
pub fn new(borrowed_locals: BorrowedLocalsResults<'mir, 'tcx>) -> Self {
MaybeRequiresStorage { borrowed_locals }
pub fn new(
body: &'mir Body<'tcx>,
borrowed_locals: Results<'tcx, MaybeBorrowedLocals>,
) -> Self {
MaybeRequiresStorage { body, borrowed_locals }
}
}

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

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

match &terminator.kind {
TerminatorKind::Call { destination, .. } => {
Expand Down Expand Up @@ -283,15 +282,15 @@ impl<'tcx> Analysis<'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 <Self as Analysis<'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);
fn check_for_move(&self, trans: &mut <Self as Analysis<'tcx>>::Domain, loc: Location) {
let borrowed_locals = self.borrowed_locals.clone().into_results_cursor(self.body);
let mut visitor = MoveVisitor { trans, borrowed_locals };
visitor.visit_location(self.body, loc);
nnethercote marked this conversation as resolved.
Show resolved Hide resolved
}
}

struct MoveVisitor<'a, 'mir, 'tcx> {
borrowed_locals: &'a mut BorrowedLocalsResults<'mir, 'tcx>,
borrowed_locals: ResultsCursor<'mir, 'tcx, MaybeBorrowedLocals>,
trans: &'a mut BitSet<Local>,
}

Expand Down
9 changes: 4 additions & 5 deletions compiler/rustc_mir_transform/src/coroutine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -679,11 +679,10 @@ fn locals_live_across_suspend_points<'tcx>(

// Calculate the MIR locals that we actually need to keep storage around
// for.
let mut requires_storage_cursor =
MaybeRequiresStorage::new(borrowed_locals_results.into_results_cursor(body))
.into_engine(tcx, body)
.iterate_to_fixpoint()
.into_results_cursor(body);
let mut requires_storage_cursor = MaybeRequiresStorage::new(body, borrowed_locals_results)
.into_engine(tcx, body)
.iterate_to_fixpoint()
.into_results_cursor(body);

// Calculate the liveness of MIR locals ignoring borrows.
let mut liveness = MaybeLiveLocals
Expand Down