1
Fork 0

Don't require owned data in MaybeStorageLive

This commit is contained in:
Jakob Degen 2022-12-13 04:22:47 -08:00
parent 109cccbe4f
commit 3522d48112
3 changed files with 10 additions and 9 deletions

View file

@ -52,7 +52,7 @@ impl<'tcx> MirPass<'tcx> for Validator {
}; };
let always_live_locals = always_storage_live_locals(body); let always_live_locals = always_storage_live_locals(body);
let storage_liveness = MaybeStorageLive::new(always_live_locals) let storage_liveness = MaybeStorageLive::new(std::borrow::Cow::Owned(always_live_locals))
.into_engine(tcx, body) .into_engine(tcx, body)
.iterate_to_fixpoint() .iterate_to_fixpoint()
.into_results_cursor(body); .into_results_cursor(body);
@ -79,7 +79,7 @@ struct TypeChecker<'a, 'tcx> {
param_env: ParamEnv<'tcx>, param_env: ParamEnv<'tcx>,
mir_phase: MirPhase, mir_phase: MirPhase,
reachable_blocks: BitSet<BasicBlock>, reachable_blocks: BitSet<BasicBlock>,
storage_liveness: ResultsCursor<'a, 'tcx, MaybeStorageLive>, storage_liveness: ResultsCursor<'a, 'tcx, MaybeStorageLive<'static>>,
place_cache: Vec<PlaceRef<'tcx>>, place_cache: Vec<PlaceRef<'tcx>>,
value_cache: Vec<u128>, value_cache: Vec<u128>,
} }

View file

@ -3,20 +3,21 @@ pub use super::*;
use crate::{CallReturnPlaces, GenKill, Results, ResultsRefCursor}; use crate::{CallReturnPlaces, GenKill, Results, ResultsRefCursor};
use rustc_middle::mir::visit::{NonMutatingUseContext, PlaceContext, Visitor}; use rustc_middle::mir::visit::{NonMutatingUseContext, PlaceContext, Visitor};
use rustc_middle::mir::*; use rustc_middle::mir::*;
use std::borrow::Cow;
use std::cell::RefCell; use std::cell::RefCell;
#[derive(Clone)] #[derive(Clone)]
pub struct MaybeStorageLive { pub struct MaybeStorageLive<'a> {
always_live_locals: BitSet<Local>, always_live_locals: Cow<'a, BitSet<Local>>,
} }
impl MaybeStorageLive { impl<'a> MaybeStorageLive<'a> {
pub fn new(always_live_locals: BitSet<Local>) -> Self { pub fn new(always_live_locals: Cow<'a, BitSet<Local>>) -> Self {
MaybeStorageLive { always_live_locals } MaybeStorageLive { always_live_locals }
} }
} }
impl<'tcx> crate::AnalysisDomain<'tcx> for MaybeStorageLive { impl<'tcx, 'a> crate::AnalysisDomain<'tcx> for MaybeStorageLive<'a> {
type Domain = BitSet<Local>; type Domain = BitSet<Local>;
const NAME: &'static str = "maybe_storage_live"; const NAME: &'static str = "maybe_storage_live";
@ -38,7 +39,7 @@ impl<'tcx> crate::AnalysisDomain<'tcx> for MaybeStorageLive {
} }
} }
impl<'tcx> crate::GenKillAnalysis<'tcx> for MaybeStorageLive { impl<'tcx, 'a> crate::GenKillAnalysis<'tcx> for MaybeStorageLive<'a> {
type Idx = Local; type Idx = Local;
fn statement_effect( fn statement_effect(

View file

@ -490,7 +490,7 @@ fn locals_live_across_suspend_points<'tcx>(
// Calculate when MIR locals have live storage. This gives us an upper bound of their // Calculate when MIR locals have live storage. This gives us an upper bound of their
// lifetimes. // lifetimes.
let mut storage_live = MaybeStorageLive::new(always_live_locals.clone()) let mut storage_live = MaybeStorageLive::new(std::borrow::Cow::Borrowed(always_live_locals))
.into_engine(tcx, body_ref) .into_engine(tcx, body_ref)
.iterate_to_fixpoint() .iterate_to_fixpoint()
.into_results_cursor(body_ref); .into_results_cursor(body_ref);