1
Fork 0

Don't require owned data in MaybeStorageDead

This commit is contained in:
Tomasz Miąsko 2023-12-16 00:00:00 +00:00
parent 1d36e3ae03
commit b4877753c3
2 changed files with 8 additions and 7 deletions

View file

@ -81,17 +81,17 @@ impl<'tcx, 'a> crate::GenKillAnalysis<'tcx> for MaybeStorageLive<'a> {
} }
#[derive(Clone)] #[derive(Clone)]
pub struct MaybeStorageDead { pub struct MaybeStorageDead<'a> {
always_live_locals: BitSet<Local>, always_live_locals: Cow<'a, BitSet<Local>>,
} }
impl MaybeStorageDead { impl<'a> MaybeStorageDead<'a> {
pub fn new(always_live_locals: BitSet<Local>) -> Self { pub fn new(always_live_locals: Cow<'a, BitSet<Local>>) -> Self {
MaybeStorageDead { always_live_locals } MaybeStorageDead { always_live_locals }
} }
} }
impl<'tcx> crate::AnalysisDomain<'tcx> for MaybeStorageDead { impl<'tcx, 'a> crate::AnalysisDomain<'tcx> for MaybeStorageDead<'a> {
type Domain = BitSet<Local>; type Domain = BitSet<Local>;
const NAME: &'static str = "maybe_storage_dead"; const NAME: &'static str = "maybe_storage_dead";
@ -112,7 +112,7 @@ impl<'tcx> crate::AnalysisDomain<'tcx> for MaybeStorageDead {
} }
} }
impl<'tcx> crate::GenKillAnalysis<'tcx> for MaybeStorageDead { impl<'tcx, 'a> crate::GenKillAnalysis<'tcx> for MaybeStorageDead<'a> {
type Idx = Local; type Idx = Local;
fn domain_size(&self, body: &Body<'tcx>) -> usize { fn domain_size(&self, body: &Body<'tcx>) -> usize {

View file

@ -7,6 +7,7 @@ use rustc_middle::ty::TyCtxt;
use rustc_mir_dataflow::impls::MaybeStorageDead; use rustc_mir_dataflow::impls::MaybeStorageDead;
use rustc_mir_dataflow::storage::always_storage_live_locals; use rustc_mir_dataflow::storage::always_storage_live_locals;
use rustc_mir_dataflow::Analysis; use rustc_mir_dataflow::Analysis;
use std::borrow::Cow;
use crate::ssa::{SsaLocals, StorageLiveLocals}; use crate::ssa::{SsaLocals, StorageLiveLocals};
@ -120,7 +121,7 @@ fn compute_replacement<'tcx>(
// Compute `MaybeStorageDead` dataflow to check that we only replace when the pointee is // Compute `MaybeStorageDead` dataflow to check that we only replace when the pointee is
// definitely live. // definitely live.
let mut maybe_dead = MaybeStorageDead::new(always_live_locals) let mut maybe_dead = MaybeStorageDead::new(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);