From 3522d48112e03a015e3714d4019b59f46d84f587 Mon Sep 17 00:00:00 2001 From: Jakob Degen Date: Tue, 13 Dec 2022 04:22:47 -0800 Subject: [PATCH] Don't require owned data in `MaybeStorageLive` --- compiler/rustc_const_eval/src/transform/validate.rs | 4 ++-- .../src/impls/storage_liveness.rs | 13 +++++++------ compiler/rustc_mir_transform/src/generator.rs | 2 +- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/compiler/rustc_const_eval/src/transform/validate.rs b/compiler/rustc_const_eval/src/transform/validate.rs index 64318f5f54d5d..1b932d0e7084f 100644 --- a/compiler/rustc_const_eval/src/transform/validate.rs +++ b/compiler/rustc_const_eval/src/transform/validate.rs @@ -52,7 +52,7 @@ impl<'tcx> MirPass<'tcx> for Validator { }; 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) .iterate_to_fixpoint() .into_results_cursor(body); @@ -79,7 +79,7 @@ struct TypeChecker<'a, 'tcx> { param_env: ParamEnv<'tcx>, mir_phase: MirPhase, reachable_blocks: BitSet, - storage_liveness: ResultsCursor<'a, 'tcx, MaybeStorageLive>, + storage_liveness: ResultsCursor<'a, 'tcx, MaybeStorageLive<'static>>, place_cache: Vec>, value_cache: Vec, } diff --git a/compiler/rustc_mir_dataflow/src/impls/storage_liveness.rs b/compiler/rustc_mir_dataflow/src/impls/storage_liveness.rs index 18760b6c6fa54..8d379b90a86db 100644 --- a/compiler/rustc_mir_dataflow/src/impls/storage_liveness.rs +++ b/compiler/rustc_mir_dataflow/src/impls/storage_liveness.rs @@ -3,20 +3,21 @@ pub use super::*; use crate::{CallReturnPlaces, GenKill, Results, ResultsRefCursor}; use rustc_middle::mir::visit::{NonMutatingUseContext, PlaceContext, Visitor}; use rustc_middle::mir::*; +use std::borrow::Cow; use std::cell::RefCell; #[derive(Clone)] -pub struct MaybeStorageLive { - always_live_locals: BitSet, +pub struct MaybeStorageLive<'a> { + always_live_locals: Cow<'a, BitSet>, } -impl MaybeStorageLive { - pub fn new(always_live_locals: BitSet) -> Self { +impl<'a> MaybeStorageLive<'a> { + pub fn new(always_live_locals: Cow<'a, BitSet>) -> Self { MaybeStorageLive { always_live_locals } } } -impl<'tcx> crate::AnalysisDomain<'tcx> for MaybeStorageLive { +impl<'tcx, 'a> crate::AnalysisDomain<'tcx> for MaybeStorageLive<'a> { type Domain = BitSet; 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; fn statement_effect( diff --git a/compiler/rustc_mir_transform/src/generator.rs b/compiler/rustc_mir_transform/src/generator.rs index c08593afe9d88..c097af6161159 100644 --- a/compiler/rustc_mir_transform/src/generator.rs +++ b/compiler/rustc_mir_transform/src/generator.rs @@ -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 // 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) .iterate_to_fixpoint() .into_results_cursor(body_ref);