From e07ffe97b8f9d9e0a8e549dacde4b4b93d43a05b Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Wed, 27 Sep 2023 17:16:30 +0000 Subject: [PATCH] Use a plain bitset for liveness analyses. --- compiler/rustc_mir_dataflow/src/impls/initialized.rs | 7 +++++++ compiler/rustc_mir_dataflow/src/impls/liveness.rs | 10 +++++----- compiler/rustc_mir_dataflow/src/points.rs | 6 +++--- compiler/rustc_mir_dataflow/src/rustc_peek.rs | 4 ++-- 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/compiler/rustc_mir_dataflow/src/impls/initialized.rs b/compiler/rustc_mir_dataflow/src/impls/initialized.rs index 6653b99b3f5..720515f262d 100644 --- a/compiler/rustc_mir_dataflow/src/impls/initialized.rs +++ b/compiler/rustc_mir_dataflow/src/impls/initialized.rs @@ -305,7 +305,10 @@ fn update_bits( } impl<'tcx> AnalysisDomain<'tcx> for MaybeInitializedPlaces<'_, 'tcx> { + /// There can be many more `MovePathIndex` than there are locals in a MIR body. + /// We use a chunked bitset to avoid paying too high a memory footprint. type Domain = MaybeReachable>; + const NAME: &'static str = "maybe_init"; fn bottom_value(&self, _: &mir::Body<'tcx>) -> Self::Domain { @@ -437,6 +440,8 @@ fn switch_int_edge_effects>( } impl<'tcx> AnalysisDomain<'tcx> for MaybeUninitializedPlaces<'_, 'tcx> { + /// There can be many more `MovePathIndex` than there are locals in a MIR body. + /// We use a chunked bitset to avoid paying too high a memory footprint. type Domain = ChunkedBitSet; const NAME: &'static str = "maybe_uninit"; @@ -636,6 +641,8 @@ fn call_return_effect( } impl<'tcx> AnalysisDomain<'tcx> for EverInitializedPlaces<'_, 'tcx> { + /// There can be many more `InitIndex` than there are locals in a MIR body. + /// We use a chunked bitset to avoid paying too high a memory footprint. type Domain = ChunkedBitSet; const NAME: &'static str = "ever_init"; diff --git a/compiler/rustc_mir_dataflow/src/impls/liveness.rs b/compiler/rustc_mir_dataflow/src/impls/liveness.rs index 04bae6ae2fe..334fa9976f0 100644 --- a/compiler/rustc_mir_dataflow/src/impls/liveness.rs +++ b/compiler/rustc_mir_dataflow/src/impls/liveness.rs @@ -1,4 +1,4 @@ -use rustc_index::bit_set::{BitSet, ChunkedBitSet}; +use rustc_index::bit_set::BitSet; use rustc_middle::mir::visit::{MutatingUseContext, NonMutatingUseContext, PlaceContext, Visitor}; use rustc_middle::mir::{ self, CallReturnPlaces, Local, Location, Place, StatementKind, TerminatorEdges, @@ -26,14 +26,14 @@ pub struct MaybeLiveLocals; impl<'tcx> AnalysisDomain<'tcx> for MaybeLiveLocals { - type Domain = ChunkedBitSet; + type Domain = BitSet; type Direction = Backward; const NAME: &'static str = "liveness"; fn bottom_value(&self, body: &mir::Body<'tcx>) -> Self::Domain { // bottom = not live - ChunkedBitSet::new_empty(body.local_decls.len()) + BitSet::new_empty(body.local_decls.len()) } fn initialize_start_block(&self, _: &mir::Body<'tcx>, _: &mut Self::Domain) { @@ -233,14 +233,14 @@ pub fn new(always_live: &'a BitSet) -> Self { } impl<'a, 'tcx> AnalysisDomain<'tcx> for MaybeTransitiveLiveLocals<'a> { - type Domain = ChunkedBitSet; + type Domain = BitSet; type Direction = Backward; const NAME: &'static str = "transitive liveness"; fn bottom_value(&self, body: &mir::Body<'tcx>) -> Self::Domain { // bottom = not live - ChunkedBitSet::new_empty(body.local_decls.len()) + BitSet::new_empty(body.local_decls.len()) } fn initialize_start_block(&self, _: &mir::Body<'tcx>, _: &mut Self::Domain) { diff --git a/compiler/rustc_mir_dataflow/src/points.rs b/compiler/rustc_mir_dataflow/src/points.rs index ff17ce1fe07..bbfb37d2a82 100644 --- a/compiler/rustc_mir_dataflow/src/points.rs +++ b/compiler/rustc_mir_dataflow/src/points.rs @@ -1,5 +1,5 @@ use crate::framework::{visit_results, ResultsVisitable, ResultsVisitor}; -use rustc_index::bit_set::ChunkedBitSet; +use rustc_index::bit_set::BitSet; use rustc_index::interval::SparseIntervalMatrix; use rustc_index::Idx; use rustc_index::IndexVec; @@ -102,7 +102,7 @@ pub fn save_as_intervals<'tcx, N, R>( ) -> SparseIntervalMatrix where N: Idx, - R: ResultsVisitable<'tcx, FlowState = ChunkedBitSet>, + R: ResultsVisitable<'tcx, FlowState = BitSet>, { let values = SparseIntervalMatrix::new(elements.num_points()); let mut visitor = Visitor { elements, values }; @@ -124,7 +124,7 @@ impl<'mir, 'tcx, R, N> ResultsVisitor<'mir, 'tcx, R> for Visitor<'_, N> where N: Idx, { - type FlowState = ChunkedBitSet; + type FlowState = BitSet; fn visit_statement_after_primary_effect( &mut self, diff --git a/compiler/rustc_mir_dataflow/src/rustc_peek.rs b/compiler/rustc_mir_dataflow/src/rustc_peek.rs index 08a5d70fb6f..cbbf3548c07 100644 --- a/compiler/rustc_mir_dataflow/src/rustc_peek.rs +++ b/compiler/rustc_mir_dataflow/src/rustc_peek.rs @@ -12,7 +12,7 @@ use crate::{Analysis, JoinSemiLattice, ResultsCursor}; use rustc_ast::MetaItem; use rustc_hir::def_id::DefId; -use rustc_index::bit_set::ChunkedBitSet; +use rustc_index::bit_set::BitSet; use rustc_middle::mir::MirPass; use rustc_middle::mir::{self, Body, Local, Location}; use rustc_middle::ty::{self, Ty, TyCtxt}; @@ -275,7 +275,7 @@ fn peek_at( &self, tcx: TyCtxt<'tcx>, place: mir::Place<'tcx>, - flow_state: &ChunkedBitSet, + flow_state: &BitSet, call: PeekCall, ) { info!(?place, "peek_at");