Skip to content

Commit dba968f

Browse files
committed
Auto merge of #116152 - cjgillot:unchunck, r=<try>
Only use dense bitsets in dataflow analyses r? `@ghost`
2 parents d4589a4 + a3e432c commit dba968f

File tree

6 files changed

+21
-14
lines changed

6 files changed

+21
-14
lines changed

compiler/rustc_borrowck/src/type_check/liveness/trace.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
2-
use rustc_index::bit_set::HybridBitSet;
2+
use rustc_index::bit_set::BitSet;
33
use rustc_index::interval::IntervalSet;
44
use rustc_infer::infer::canonical::QueryRegionConstraints;
55
use rustc_middle::mir::{BasicBlock, Body, ConstraintCategory, Local, Location};
@@ -106,7 +106,7 @@ struct LivenessResults<'me, 'typeck, 'flow, 'tcx> {
106106
cx: LivenessContext<'me, 'typeck, 'flow, 'tcx>,
107107

108108
/// Set of points that define the current local.
109-
defs: HybridBitSet<PointIndex>,
109+
defs: BitSet<PointIndex>,
110110

111111
/// Points where the current variable is "use live" -- meaning
112112
/// that there is a future "full use" that may use its value.
@@ -129,7 +129,7 @@ impl<'me, 'typeck, 'flow, 'tcx> LivenessResults<'me, 'typeck, 'flow, 'tcx> {
129129
let num_points = cx.elements.num_points();
130130
LivenessResults {
131131
cx,
132-
defs: HybridBitSet::new_empty(num_points),
132+
defs: BitSet::new_empty(num_points),
133133
use_live_at: IntervalSet::new(num_points),
134134
drop_live_at: IntervalSet::new(num_points),
135135
drop_locations: vec![],

compiler/rustc_index/src/bit_set.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ impl<T: Idx> BitSet<T> {
293293
not_already
294294
}
295295

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

12801280
impl<T: Idx + Ord> SparseBitSet<T> {
1281-
fn last_set_in(&self, range: impl RangeBounds<T>) -> Option<T> {
1281+
pub fn last_set_in(&self, range: impl RangeBounds<T>) -> Option<T> {
12821282
let mut last_leq = None;
12831283
for e in self.iter() {
12841284
if range.contains(e) {

compiler/rustc_mir_dataflow/src/impls/initialized.rs

+7
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,10 @@ impl<'a, 'tcx> DefinitelyInitializedPlaces<'a, 'tcx> {
308308
}
309309

310310
impl<'tcx> AnalysisDomain<'tcx> for MaybeInitializedPlaces<'_, 'tcx> {
311+
/// There can be many more `MovePathIndex` than there are locals in a MIR body.
312+
/// We use a chunked bitset to avoid paying too high a memory footprint.
311313
type Domain = MaybeReachable<ChunkedBitSet<MovePathIndex>>;
314+
312315
const NAME: &'static str = "maybe_init";
313316

314317
fn bottom_value(&self, _: &mir::Body<'tcx>) -> Self::Domain {
@@ -444,6 +447,8 @@ impl<'tcx> GenKillAnalysis<'tcx> for MaybeInitializedPlaces<'_, 'tcx> {
444447
}
445448

446449
impl<'tcx> AnalysisDomain<'tcx> for MaybeUninitializedPlaces<'_, 'tcx> {
450+
/// There can be many more `MovePathIndex` than there are locals in a MIR body.
451+
/// We use a chunked bitset to avoid paying too high a memory footprint.
447452
type Domain = ChunkedBitSet<MovePathIndex>;
448453

449454
const NAME: &'static str = "maybe_uninit";
@@ -649,6 +654,8 @@ impl<'tcx> GenKillAnalysis<'tcx> for DefinitelyInitializedPlaces<'_, 'tcx> {
649654
}
650655

651656
impl<'tcx> AnalysisDomain<'tcx> for EverInitializedPlaces<'_, 'tcx> {
657+
/// There can be many more `InitIndex` than there are locals in a MIR body.
658+
/// We use a chunked bitset to avoid paying too high a memory footprint.
652659
type Domain = ChunkedBitSet<InitIndex>;
653660

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

compiler/rustc_mir_dataflow/src/impls/liveness.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use rustc_index::bit_set::{BitSet, ChunkedBitSet};
1+
use rustc_index::bit_set::BitSet;
22
use rustc_middle::mir::visit::{MutatingUseContext, NonMutatingUseContext, PlaceContext, Visitor};
33
use rustc_middle::mir::{
44
self, CallReturnPlaces, Local, Location, Place, StatementKind, TerminatorEdges,
@@ -27,14 +27,14 @@ use crate::{Analysis, AnalysisDomain, Backward, GenKill, GenKillAnalysis};
2727
pub struct MaybeLiveLocals;
2828

2929
impl<'tcx> AnalysisDomain<'tcx> for MaybeLiveLocals {
30-
type Domain = ChunkedBitSet<Local>;
30+
type Domain = BitSet<Local>;
3131
type Direction = Backward;
3232

3333
const NAME: &'static str = "liveness";
3434

3535
fn bottom_value(&self, body: &mir::Body<'tcx>) -> Self::Domain {
3636
// bottom = not live
37-
ChunkedBitSet::new_empty(body.local_decls.len())
37+
BitSet::new_empty(body.local_decls.len())
3838
}
3939

4040
fn initialize_start_block(&self, _: &mir::Body<'tcx>, _: &mut Self::Domain) {
@@ -234,14 +234,14 @@ impl<'a> MaybeTransitiveLiveLocals<'a> {
234234
}
235235

236236
impl<'a, 'tcx> AnalysisDomain<'tcx> for MaybeTransitiveLiveLocals<'a> {
237-
type Domain = ChunkedBitSet<Local>;
237+
type Domain = BitSet<Local>;
238238
type Direction = Backward;
239239

240240
const NAME: &'static str = "transitive liveness";
241241

242242
fn bottom_value(&self, body: &mir::Body<'tcx>) -> Self::Domain {
243243
// bottom = not live
244-
ChunkedBitSet::new_empty(body.local_decls.len())
244+
BitSet::new_empty(body.local_decls.len())
245245
}
246246

247247
fn initialize_start_block(&self, _: &mir::Body<'tcx>, _: &mut Self::Domain) {

compiler/rustc_mir_dataflow/src/rustc_peek.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use rustc_span::symbol::sym;
22
use rustc_span::Span;
33

4-
use rustc_index::bit_set::ChunkedBitSet;
4+
use rustc_index::bit_set::BitSet;
55
use rustc_middle::mir::MirPass;
66
use rustc_middle::mir::{self, Body, Local, Location};
77
use rustc_middle::ty::{self, Ty, TyCtxt};
@@ -264,7 +264,7 @@ impl<'tcx> RustcPeekAt<'tcx> for MaybeLiveLocals {
264264
&self,
265265
tcx: TyCtxt<'tcx>,
266266
place: mir::Place<'tcx>,
267-
flow_state: &ChunkedBitSet<Local>,
267+
flow_state: &BitSet<Local>,
268268
call: PeekCall,
269269
) {
270270
info!(?place, "peek_at");

compiler/rustc_mir_transform/src/nrvo.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! See the docs for [`RenameReturnPlace`].
22
33
use rustc_hir::Mutability;
4-
use rustc_index::bit_set::HybridBitSet;
4+
use rustc_index::bit_set::BitSet;
55
use rustc_middle::mir::visit::{MutVisitor, NonUseContext, PlaceContext, Visitor};
66
use rustc_middle::mir::{self, BasicBlock, Local, Location};
77
use rustc_middle::ty::TyCtxt;
@@ -123,7 +123,7 @@ fn find_local_assigned_to_return_place(
123123
body: &mut mir::Body<'_>,
124124
) -> Option<Local> {
125125
let mut block = start;
126-
let mut seen = HybridBitSet::new_empty(body.basic_blocks.len());
126+
let mut seen = BitSet::new_empty(body.basic_blocks.len());
127127

128128
// Iterate as long as `block` has exactly one predecessor that we have not yet visited.
129129
while seen.insert(block) {

0 commit comments

Comments
 (0)