Skip to content

Commit b80cb47

Browse files
committed
Auto merge of #54286 - nnethercote:BitSet, r=pnkfelix
Merge `bitvec.rs` and `indexed_set.rs` Because it's not good to have two separate implementations. Also, I will combine the best parts of each to improve NLL memory usage on some benchmarks significantly.
2 parents 2224a42 + 53589b7 commit b80cb47

40 files changed

+1279
-1404
lines changed

src/librustc/mir/traversal.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use rustc_data_structures::bitvec::BitArray;
11+
use rustc_data_structures::bit_set::BitSet;
1212

1313
use super::*;
1414

@@ -32,7 +32,7 @@ use super::*;
3232
#[derive(Clone)]
3333
pub struct Preorder<'a, 'tcx: 'a> {
3434
mir: &'a Mir<'tcx>,
35-
visited: BitArray<BasicBlock>,
35+
visited: BitSet<BasicBlock>,
3636
worklist: Vec<BasicBlock>,
3737
}
3838

@@ -42,7 +42,7 @@ impl<'a, 'tcx> Preorder<'a, 'tcx> {
4242

4343
Preorder {
4444
mir,
45-
visited: BitArray::new(mir.basic_blocks().len()),
45+
visited: BitSet::new_empty(mir.basic_blocks().len()),
4646
worklist,
4747
}
4848
}
@@ -104,15 +104,15 @@ impl<'a, 'tcx> ExactSizeIterator for Preorder<'a, 'tcx> {}
104104
/// A Postorder traversal of this graph is `D B C A` or `D C B A`
105105
pub struct Postorder<'a, 'tcx: 'a> {
106106
mir: &'a Mir<'tcx>,
107-
visited: BitArray<BasicBlock>,
107+
visited: BitSet<BasicBlock>,
108108
visit_stack: Vec<(BasicBlock, Successors<'a>)>
109109
}
110110

111111
impl<'a, 'tcx> Postorder<'a, 'tcx> {
112112
pub fn new(mir: &'a Mir<'tcx>, root: BasicBlock) -> Postorder<'a, 'tcx> {
113113
let mut po = Postorder {
114114
mir,
115-
visited: BitArray::new(mir.basic_blocks().len()),
115+
visited: BitSet::new_empty(mir.basic_blocks().len()),
116116
visit_stack: Vec::new()
117117
};
118118

src/librustc/traits/select.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ use ty::relate::TypeRelation;
4444
use middle::lang_items;
4545
use mir::interpret::{GlobalId};
4646

47+
use rustc_data_structures::bit_set::BitSet;
4748
use rustc_data_structures::sync::Lock;
48-
use rustc_data_structures::bitvec::BitArray;
4949
use std::iter;
5050
use std::cmp;
5151
use std::fmt;
@@ -3069,7 +3069,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
30693069
} else {
30703070
return Err(Unimplemented);
30713071
};
3072-
let mut ty_params = BitArray::new(substs_a.types().count());
3072+
let mut ty_params = BitSet::new_empty(substs_a.types().count());
30733073
let mut found = false;
30743074
for ty in field.walk() {
30753075
if let ty::Param(p) = ty.sty {

src/librustc/ty/query/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,14 @@ use util::nodemap::{DefIdSet, DefIdMap, ItemLocalSet};
4949
use util::common::{ErrorReported};
5050
use util::profiling::ProfileCategory::*;
5151

52-
use rustc_data_structures::indexed_set::IdxSet;
53-
use rustc_target::spec::PanicStrategy;
52+
use rustc_data_structures::bit_set::BitSet;
5453
use rustc_data_structures::indexed_vec::IndexVec;
5554
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
5655
use rustc_data_structures::stable_hasher::StableVec;
56+
use rustc_data_structures::sync::Lrc;
57+
use rustc_target::spec::PanicStrategy;
5758

5859
use std::ops::Deref;
59-
use rustc_data_structures::sync::Lrc;
6060
use std::sync::Arc;
6161
use syntax_pos::{Span, DUMMY_SP};
6262
use syntax_pos::symbol::InternedString;
@@ -208,7 +208,7 @@ define_queries! { <'tcx>
208208
/// Maps DefId's that have an associated Mir to the result
209209
/// of the MIR qualify_consts pass. The actual meaning of
210210
/// the value isn't known except to the pass itself.
211-
[] fn mir_const_qualif: MirConstQualif(DefId) -> (u8, Lrc<IdxSet<mir::Local>>),
211+
[] fn mir_const_qualif: MirConstQualif(DefId) -> (u8, Lrc<BitSet<mir::Local>>),
212212

213213
/// Fetch the MIR for a given def-id right after it's built - this includes
214214
/// unreachable code.

src/librustc_codegen_llvm/debuginfo/create_scope_map.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use libc::c_uint;
2121

2222
use syntax_pos::Pos;
2323

24-
use rustc_data_structures::bitvec::BitArray;
24+
use rustc_data_structures::bit_set::BitSet;
2525
use rustc_data_structures::indexed_vec::{Idx, IndexVec};
2626

2727
use syntax_pos::BytePos;
@@ -64,7 +64,7 @@ pub fn create_mir_scopes(
6464
};
6565

6666
// Find all the scopes with variables defined in them.
67-
let mut has_variables = BitArray::new(mir.source_scopes.len());
67+
let mut has_variables = BitSet::new_empty(mir.source_scopes.len());
6868
for var in mir.vars_iter() {
6969
let decl = &mir.local_decls[var];
7070
has_variables.insert(decl.visibility_scope);
@@ -81,7 +81,7 @@ pub fn create_mir_scopes(
8181

8282
fn make_mir_scope(cx: &CodegenCx<'ll, '_>,
8383
mir: &Mir,
84-
has_variables: &BitArray<SourceScope>,
84+
has_variables: &BitSet<SourceScope>,
8585
debug_context: &FunctionDebugContextData<'ll>,
8686
scope: SourceScope,
8787
scopes: &mut IndexVec<SourceScope, MirDebugScope<'ll>>) {

src/librustc_codegen_llvm/mir/analyze.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
//! An analysis to determine which locals require allocas and
1212
//! which do not.
1313
14-
use rustc_data_structures::bitvec::BitArray;
14+
use rustc_data_structures::bit_set::BitSet;
1515
use rustc_data_structures::graph::dominators::Dominators;
1616
use rustc_data_structures::indexed_vec::{Idx, IndexVec};
1717
use rustc::mir::{self, Location, TerminatorKind};
@@ -22,7 +22,7 @@ use rustc::ty::layout::LayoutOf;
2222
use type_of::LayoutLlvmExt;
2323
use super::FunctionCx;
2424

25-
pub fn non_ssa_locals(fx: &FunctionCx<'a, 'll, 'tcx>) -> BitArray<mir::Local> {
25+
pub fn non_ssa_locals(fx: &FunctionCx<'a, 'll, 'tcx>) -> BitSet<mir::Local> {
2626
let mir = fx.mir;
2727
let mut analyzer = LocalAnalyzer::new(fx);
2828

@@ -54,7 +54,7 @@ pub fn non_ssa_locals(fx: &FunctionCx<'a, 'll, 'tcx>) -> BitArray<mir::Local> {
5454
struct LocalAnalyzer<'mir, 'a: 'mir, 'll: 'a, 'tcx: 'll> {
5555
fx: &'mir FunctionCx<'a, 'll, 'tcx>,
5656
dominators: Dominators<mir::BasicBlock>,
57-
non_ssa_locals: BitArray<mir::Local>,
57+
non_ssa_locals: BitSet<mir::Local>,
5858
// The location of the first visited direct assignment to each
5959
// local, or an invalid location (out of bounds `block` index).
6060
first_assignment: IndexVec<mir::Local, Location>
@@ -67,7 +67,7 @@ impl LocalAnalyzer<'mir, 'a, 'll, 'tcx> {
6767
let mut analyzer = LocalAnalyzer {
6868
fx,
6969
dominators: fx.mir.dominators(),
70-
non_ssa_locals: BitArray::new(fx.mir.local_decls.len()),
70+
non_ssa_locals: BitSet::new_empty(fx.mir.local_decls.len()),
7171
first_assignment: IndexVec::from_elem(invalid_location, &fx.mir.local_decls)
7272
};
7373

src/librustc_codegen_llvm/mir/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use syntax::symbol::keywords;
3131

3232
use std::iter;
3333

34-
use rustc_data_structures::bitvec::BitArray;
34+
use rustc_data_structures::bit_set::BitSet;
3535
use rustc_data_structures::indexed_vec::IndexVec;
3636

3737
pub use self::constant::codegen_static_initializer;
@@ -341,7 +341,7 @@ pub fn codegen_mir(
341341
debuginfo::start_emitting_source_locations(&fx.debug_context);
342342

343343
let rpo = traversal::reverse_postorder(&mir);
344-
let mut visited = BitArray::new(mir.basic_blocks().len());
344+
let mut visited = BitSet::new_empty(mir.basic_blocks().len());
345345

346346
// Codegen the body of each block using reverse postorder
347347
for (bb, _) in rpo {
@@ -435,7 +435,7 @@ fn arg_local_refs(
435435
bx: &Builder<'a, 'll, 'tcx>,
436436
fx: &FunctionCx<'a, 'll, 'tcx>,
437437
scopes: &IndexVec<mir::SourceScope, debuginfo::MirDebugScope<'ll>>,
438-
memory_locals: &BitArray<mir::Local>,
438+
memory_locals: &BitSet<mir::Local>,
439439
) -> Vec<LocalRef<'ll, 'tcx>> {
440440
let mir = fx.mir;
441441
let tcx = bx.tcx();

0 commit comments

Comments
 (0)