Remove uses of ResultsClonedCursor.

By just cloning the entire `Results` in the one place where
`ResultsClonedCursor` was used. This is extra allocations but the
performance effect is negligible.
This commit is contained in:
Nicholas Nethercote 2023-11-24 11:14:00 +11:00
parent 5f5263bfc8
commit 500e55ba8c
4 changed files with 17 additions and 17 deletions

View File

@ -31,6 +31,7 @@ use super::{
pub type EntrySets<'tcx, A> = IndexVec<BasicBlock, <A as AnalysisDomain<'tcx>>::Domain>;
/// A dataflow analysis that has converged to fixpoint.
#[derive(Clone)]
pub struct Results<'tcx, A, E = EntrySets<'tcx, A>>
where
A: Analysis<'tcx>,

View File

@ -5,7 +5,7 @@ use rustc_middle::mir::*;
use std::borrow::Cow;
use super::MaybeBorrowedLocals;
use crate::{GenKill, ResultsClonedCursor};
use crate::{GenKill, ResultsCursor};
#[derive(Clone)]
pub struct MaybeStorageLive<'a> {
@ -152,22 +152,21 @@ impl<'tcx> crate::GenKillAnalysis<'tcx> for MaybeStorageDead {
}
}
type BorrowedLocalsResults<'res, 'mir, 'tcx> =
ResultsClonedCursor<'res, 'mir, 'tcx, MaybeBorrowedLocals>;
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<'res, 'mir, 'tcx> {
borrowed_locals: BorrowedLocalsResults<'res, 'mir, 'tcx>,
pub struct MaybeRequiresStorage<'mir, 'tcx> {
borrowed_locals: BorrowedLocalsResults<'mir, 'tcx>,
}
impl<'res, 'mir, 'tcx> MaybeRequiresStorage<'res, 'mir, 'tcx> {
pub fn new(borrowed_locals: BorrowedLocalsResults<'res, 'mir, 'tcx>) -> Self {
impl<'mir, 'tcx> MaybeRequiresStorage<'mir, 'tcx> {
pub fn new(borrowed_locals: BorrowedLocalsResults<'mir, 'tcx>) -> Self {
MaybeRequiresStorage { borrowed_locals }
}
}
impl<'tcx> crate::AnalysisDomain<'tcx> for MaybeRequiresStorage<'_, '_, 'tcx> {
impl<'tcx> crate::AnalysisDomain<'tcx> for MaybeRequiresStorage<'_, 'tcx> {
type Domain = BitSet<Local>;
const NAME: &'static str = "requires_storage";
@ -186,7 +185,7 @@ impl<'tcx> crate::AnalysisDomain<'tcx> for MaybeRequiresStorage<'_, '_, 'tcx> {
}
}
impl<'tcx> crate::GenKillAnalysis<'tcx> for MaybeRequiresStorage<'_, '_, 'tcx> {
impl<'tcx> crate::GenKillAnalysis<'tcx> for MaybeRequiresStorage<'_, 'tcx> {
type Idx = Local;
fn domain_size(&self, body: &Body<'tcx>) -> usize {
@ -343,7 +342,7 @@ impl<'tcx> crate::GenKillAnalysis<'tcx> for MaybeRequiresStorage<'_, '_, 'tcx> {
}
}
impl<'tcx> 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) {
let body = self.borrowed_locals.body();
@ -352,12 +351,12 @@ impl<'tcx> MaybeRequiresStorage<'_, '_, 'tcx> {
}
}
struct MoveVisitor<'a, 'res, 'mir, 'tcx, T> {
borrowed_locals: &'a mut BorrowedLocalsResults<'res, 'mir, 'tcx>,
struct MoveVisitor<'a, 'mir, 'tcx, T> {
borrowed_locals: &'a mut BorrowedLocalsResults<'mir, 'tcx>,
trans: &'a mut T,
}
impl<'tcx, T> Visitor<'tcx> for MoveVisitor<'_, '_, '_, 'tcx, T>
impl<'tcx, T> Visitor<'tcx> for MoveVisitor<'_, '_, 'tcx, T>
where
T: GenKill<Local>,
{

View File

@ -24,7 +24,7 @@ pub use self::framework::{
fmt, lattice, visit_results, Analysis, AnalysisDomain, Direction, GenKill, GenKillAnalysis,
JoinSemiLattice, MaybeReachable, Results, ResultsCursor, ResultsVisitable, ResultsVisitor,
};
use self::framework::{Backward, ResultsClonedCursor, SwitchIntEdgeEffects};
use self::framework::{Backward, SwitchIntEdgeEffects};
use self::move_paths::MoveData;
pub mod debuginfo;

View File

@ -680,12 +680,12 @@ fn locals_live_across_suspend_points<'tcx>(
let borrowed_locals_results =
MaybeBorrowedLocals.into_engine(tcx, body).pass_name("coroutine").iterate_to_fixpoint();
let mut borrowed_locals_cursor = borrowed_locals_results.cloned_results_cursor(body);
let mut borrowed_locals_cursor = borrowed_locals_results.clone().into_results_cursor(body);
// Calculate the MIR locals that we actually need to keep storage around
// for.
let mut requires_storage_cursor =
MaybeRequiresStorage::new(borrowed_locals_results.cloned_results_cursor(body))
MaybeRequiresStorage::new(borrowed_locals_results.into_results_cursor(body))
.into_engine(tcx, body)
.iterate_to_fixpoint()
.into_results_cursor(body);
@ -829,7 +829,7 @@ fn compute_storage_conflicts<'mir, 'tcx>(
body: &'mir Body<'tcx>,
saved_locals: &CoroutineSavedLocals,
always_live_locals: BitSet<Local>,
mut requires_storage: rustc_mir_dataflow::Results<'tcx, MaybeRequiresStorage<'_, 'mir, 'tcx>>,
mut requires_storage: rustc_mir_dataflow::Results<'tcx, MaybeRequiresStorage<'mir, 'tcx>>,
) -> BitMatrix<CoroutineSavedLocal, CoroutineSavedLocal> {
assert_eq!(body.local_decls.len(), saved_locals.domain_size());