Skip to content

Commit

Permalink
Auto merge of #116152 - cjgillot:unchunck, r=<try>
Browse files Browse the repository at this point in the history
Experiment: only use dense bitsets

r? `@ghost`
  • Loading branch information
bors committed Sep 25, 2023
2 parents 9d32ba3 + f528b4c commit b5f969f
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 27 deletions.
4 changes: 2 additions & 2 deletions compiler/rustc_borrowck/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use rustc_errors::{Diagnostic, DiagnosticBuilder, DiagnosticMessage, Subdiagnost
use rustc_fluent_macro::fluent_messages;
use rustc_hir as hir;
use rustc_hir::def_id::LocalDefId;
use rustc_index::bit_set::{BitSet, ChunkedBitSet};
use rustc_index::bit_set::BitSet;
use rustc_index::{IndexSlice, IndexVec};
use rustc_infer::infer::{
InferCtxt, NllRegionVariableOrigin, RegionVariableOrigin, TyCtxtInferExt,
Expand Down Expand Up @@ -1657,7 +1657,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
location: Location,
desired_action: InitializationRequiringAction,
place_span: (PlaceRef<'tcx>, Span),
maybe_uninits: &ChunkedBitSet<MovePathIndex>,
maybe_uninits: &BitSet<MovePathIndex>,
from: u64,
to: u64,
) {
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_borrowck/src/type_check/liveness/trace.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
use rustc_index::bit_set::HybridBitSet;
use rustc_index::bit_set::BitSet;
use rustc_index::interval::IntervalSet;
use rustc_infer::infer::canonical::QueryRegionConstraints;
use rustc_middle::mir::{BasicBlock, Body, ConstraintCategory, Local, Location};
Expand Down Expand Up @@ -106,7 +106,7 @@ struct LivenessResults<'me, 'typeck, 'flow, 'tcx> {
cx: LivenessContext<'me, 'typeck, 'flow, 'tcx>,

/// Set of points that define the current local.
defs: HybridBitSet<PointIndex>,
defs: BitSet<PointIndex>,

/// Points where the current variable is "use live" -- meaning
/// that there is a future "full use" that may use its value.
Expand All @@ -129,7 +129,7 @@ impl<'me, 'typeck, 'flow, 'tcx> LivenessResults<'me, 'typeck, 'flow, 'tcx> {
let num_points = cx.elements.num_points();
LivenessResults {
cx,
defs: HybridBitSet::new_empty(num_points),
defs: BitSet::new_empty(num_points),
use_live_at: IntervalSet::new(num_points),
drop_live_at: IntervalSet::new(num_points),
drop_locations: vec![],
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_index/src/bit_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ impl<T: Idx> BitSet<T> {
not_already
}

fn last_set_in(&self, range: impl RangeBounds<T>) -> Option<T> {
pub fn last_set_in(&self, range: impl RangeBounds<T>) -> Option<T> {
let (start, end) = inclusive_start_end(range, self.domain_size)?;
let (start_word_index, _) = word_index_and_mask(start);
let (end_word_index, end_mask) = word_index_and_mask(end);
Expand Down Expand Up @@ -1278,7 +1278,7 @@ impl<T: Idx> SparseBitSet<T> {
}

impl<T: Idx + Ord> SparseBitSet<T> {
fn last_set_in(&self, range: impl RangeBounds<T>) -> Option<T> {
pub fn last_set_in(&self, range: impl RangeBounds<T>) -> Option<T> {
let mut last_leq = None;
for e in self.iter() {
if range.contains(e) {
Expand Down
17 changes: 8 additions & 9 deletions compiler/rustc_mir_dataflow/src/impls/initialized.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use rustc_index::bit_set::{BitSet, ChunkedBitSet};
use rustc_index::bit_set::BitSet;
use rustc_index::Idx;
use rustc_middle::mir::{self, Body, CallReturnPlaces, Location, TerminatorEdges};
use rustc_middle::ty::{self, TyCtxt};
Expand Down Expand Up @@ -68,7 +68,7 @@ impl<'a, 'tcx> MaybeInitializedPlaces<'a, 'tcx> {
pub fn is_unwind_dead(
&self,
place: mir::Place<'tcx>,
state: &MaybeReachable<ChunkedBitSet<MovePathIndex>>,
state: &MaybeReachable<BitSet<MovePathIndex>>,
) -> bool {
if let LookupResult::Exact(path) = self.move_data().rev_lookup.find(place.as_ref()) {
let mut maybe_live = false;
Expand Down Expand Up @@ -308,7 +308,7 @@ impl<'a, 'tcx> DefinitelyInitializedPlaces<'a, 'tcx> {
}

impl<'tcx> AnalysisDomain<'tcx> for MaybeInitializedPlaces<'_, 'tcx> {
type Domain = MaybeReachable<ChunkedBitSet<MovePathIndex>>;
type Domain = MaybeReachable<BitSet<MovePathIndex>>;
const NAME: &'static str = "maybe_init";

fn bottom_value(&self, _: &mir::Body<'tcx>) -> Self::Domain {
Expand All @@ -317,8 +317,7 @@ impl<'tcx> AnalysisDomain<'tcx> for MaybeInitializedPlaces<'_, 'tcx> {
}

fn initialize_start_block(&self, _: &mir::Body<'tcx>, state: &mut Self::Domain) {
*state =
MaybeReachable::Reachable(ChunkedBitSet::new_empty(self.move_data().move_paths.len()));
*state = MaybeReachable::Reachable(BitSet::new_empty(self.move_data().move_paths.len()));
drop_flag_effects_for_function_entry(self.tcx, self.body, self.mdpe, |path, s| {
assert!(s == DropFlagState::Present);
state.gen(path);
Expand Down Expand Up @@ -444,13 +443,13 @@ impl<'tcx> GenKillAnalysis<'tcx> for MaybeInitializedPlaces<'_, 'tcx> {
}

impl<'tcx> AnalysisDomain<'tcx> for MaybeUninitializedPlaces<'_, 'tcx> {
type Domain = ChunkedBitSet<MovePathIndex>;
type Domain = BitSet<MovePathIndex>;

const NAME: &'static str = "maybe_uninit";

fn bottom_value(&self, _: &mir::Body<'tcx>) -> Self::Domain {
// bottom = initialized (start_block_effect counters this at outset)
ChunkedBitSet::new_empty(self.move_data().move_paths.len())
BitSet::new_empty(self.move_data().move_paths.len())
}

// sets on_entry bits for Arg places
Expand Down Expand Up @@ -649,13 +648,13 @@ impl<'tcx> GenKillAnalysis<'tcx> for DefinitelyInitializedPlaces<'_, 'tcx> {
}

impl<'tcx> AnalysisDomain<'tcx> for EverInitializedPlaces<'_, 'tcx> {
type Domain = ChunkedBitSet<InitIndex>;
type Domain = BitSet<InitIndex>;

const NAME: &'static str = "ever_init";

fn bottom_value(&self, _: &mir::Body<'tcx>) -> Self::Domain {
// bottom = no initialized variables by default
ChunkedBitSet::new_empty(self.move_data().inits.len())
BitSet::new_empty(self.move_data().inits.len())
}

fn initialize_start_block(&self, body: &mir::Body<'tcx>, state: &mut Self::Domain) {
Expand Down
10 changes: 5 additions & 5 deletions compiler/rustc_mir_dataflow/src/impls/liveness.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -27,14 +27,14 @@ use crate::{Analysis, AnalysisDomain, Backward, GenKill, GenKillAnalysis};
pub struct MaybeLiveLocals;

impl<'tcx> AnalysisDomain<'tcx> for MaybeLiveLocals {
type Domain = ChunkedBitSet<Local>;
type Domain = BitSet<Local>;
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) {
Expand Down Expand Up @@ -234,14 +234,14 @@ impl<'a> MaybeTransitiveLiveLocals<'a> {
}

impl<'a, 'tcx> AnalysisDomain<'tcx> for MaybeTransitiveLiveLocals<'a> {
type Domain = ChunkedBitSet<Local>;
type Domain = BitSet<Local>;
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) {
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_mir_dataflow/src/rustc_peek.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use rustc_span::symbol::sym;
use rustc_span::Span;

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};
Expand Down Expand Up @@ -264,7 +264,7 @@ impl<'tcx> RustcPeekAt<'tcx> for MaybeLiveLocals {
&self,
tcx: TyCtxt<'tcx>,
place: mir::Place<'tcx>,
flow_state: &ChunkedBitSet<Local>,
flow_state: &BitSet<Local>,
call: PeekCall,
) {
info!(?place, "peek_at");
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_mir_transform/src/nrvo.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! See the docs for [`RenameReturnPlace`].

use rustc_hir::Mutability;
use rustc_index::bit_set::HybridBitSet;
use rustc_index::bit_set::BitSet;
use rustc_middle::mir::visit::{MutVisitor, NonUseContext, PlaceContext, Visitor};
use rustc_middle::mir::{self, BasicBlock, Local, Location};
use rustc_middle::ty::TyCtxt;
Expand Down Expand Up @@ -123,7 +123,7 @@ fn find_local_assigned_to_return_place(
body: &mut mir::Body<'_>,
) -> Option<Local> {
let mut block = start;
let mut seen = HybridBitSet::new_empty(body.basic_blocks.len());
let mut seen = BitSet::new_empty(body.basic_blocks.len());

// Iterate as long as `block` has exactly one predecessor that we have not yet visited.
while seen.insert(block) {
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_mir_transform/src/remove_uninit_drops.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use rustc_index::bit_set::ChunkedBitSet;
use rustc_index::bit_set::BitSet;
use rustc_middle::mir::{Body, TerminatorKind};
use rustc_middle::ty::GenericArgsRef;
use rustc_middle::ty::{self, ParamEnv, Ty, TyCtxt, VariantDef};
Expand Down Expand Up @@ -79,7 +79,7 @@ impl<'tcx> MirPass<'tcx> for RemoveUninitDrops {
fn is_needs_drop_and_init<'tcx>(
tcx: TyCtxt<'tcx>,
param_env: ParamEnv<'tcx>,
maybe_inits: &ChunkedBitSet<MovePathIndex>,
maybe_inits: &BitSet<MovePathIndex>,
move_data: &MoveData<'tcx>,
ty: Ty<'tcx>,
mpi: MovePathIndex,
Expand Down

0 comments on commit b5f969f

Please sign in to comment.