Skip to content

Commit

Permalink
Merge indexed_set.rs into bitvec.rs, and rename it bit_set.rs.
Browse files Browse the repository at this point in the history
Currently we have two files implementing bitsets (and 2D bit matrices).
This commit combines them into one, taking the best features from each.

This involves renaming a lot of things. The high level changes are as
follows.
- bitvec.rs              --> bit_set.rs
- indexed_set.rs         --> (removed)
- BitArray + IdxSet      --> BitSet (merged, see below)
- BitVector              --> GrowableBitSet
- {,Sparse,Hybrid}IdxSet --> {,Sparse,Hybrid}BitSet
- BitMatrix              --> BitMatrix
- SparseBitMatrix        --> SparseBitMatrix

The changes within the bitset types themselves are as follows.

```
OLD             OLD             NEW
BitArray<C>     IdxSet<T>       BitSet<T>
--------        ------          ------
grow            -               grow
new             -               (remove)
new_empty       new_empty       new_empty
new_filled      new_filled      new_filled
-               to_hybrid       to_hybrid
clear           clear           clear
set_up_to       set_up_to       set_up_to
clear_above     -               clear_above
count           -               count
contains(T)     contains(&T)    contains(T)
contains_all    -               superset
is_empty        -               is_empty
insert(T)       add(&T)         insert(T)
insert_all      -               insert_all()
remove(T)       remove(&T)      remove(T)
words           words           words
words_mut       words_mut       words_mut
-               overwrite       overwrite
merge           union           union
-               subtract        subtract
-               intersect       intersect
iter            iter            iter
```

In general, when choosing names I went with:
- names that are more obvious (e.g. `BitSet` over `IdxSet`).
- names that are more like the Rust libraries (e.g. `T` over `C`,
  `insert` over `add`);
- names that are more set-like (e.g. `union` over `merge`, `superset`
  over `contains_all`, `domain_size` over `num_bits`).

Also, using `T` for index arguments seems more sensible than `&T` --
even though the latter is standard in Rust collection types -- because
indices are always copyable. It also results in fewer `&` and `*`
sigils in practice.
  • Loading branch information
nnethercote committed Sep 17, 2018
1 parent 8a2dec6 commit 266e2d3
Show file tree
Hide file tree
Showing 40 changed files with 1,276 additions and 1,377 deletions.
10 changes: 5 additions & 5 deletions src/librustc/mir/traversal.rs
Expand Up @@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use rustc_data_structures::bitvec::BitArray;
use rustc_data_structures::bit_set::BitSet;

use super::*;

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

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

Preorder {
mir,
visited: BitArray::new(mir.basic_blocks().len()),
visited: BitSet::new_empty(mir.basic_blocks().len()),
worklist,
}
}
Expand Down Expand Up @@ -104,15 +104,15 @@ impl<'a, 'tcx> ExactSizeIterator for Preorder<'a, 'tcx> {}
/// A Postorder traversal of this graph is `D B C A` or `D C B A`
pub struct Postorder<'a, 'tcx: 'a> {
mir: &'a Mir<'tcx>,
visited: BitArray<BasicBlock>,
visited: BitSet<BasicBlock>,
visit_stack: Vec<(BasicBlock, Successors<'a>)>
}

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

Expand Down
4 changes: 2 additions & 2 deletions src/librustc/traits/select.rs
Expand Up @@ -44,8 +44,8 @@ use ty::relate::TypeRelation;
use middle::lang_items;
use mir::interpret::{GlobalId};

use rustc_data_structures::bit_set::BitSet;
use rustc_data_structures::sync::Lock;
use rustc_data_structures::bitvec::BitArray;
use std::iter;
use std::cmp;
use std::fmt;
Expand Down Expand Up @@ -3069,7 +3069,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
} else {
return Err(Unimplemented);
};
let mut ty_params = BitArray::new(substs_a.types().count());
let mut ty_params = BitSet::new_empty(substs_a.types().count());
let mut found = false;
for ty in field.walk() {
if let ty::Param(p) = ty.sty {
Expand Down
8 changes: 4 additions & 4 deletions src/librustc/ty/query/mod.rs
Expand Up @@ -49,14 +49,14 @@ use util::nodemap::{DefIdSet, DefIdMap, ItemLocalSet};
use util::common::{ErrorReported};
use util::profiling::ProfileCategory::*;

use rustc_data_structures::indexed_set::IdxSet;
use rustc_target::spec::PanicStrategy;
use rustc_data_structures::bit_set::BitSet;
use rustc_data_structures::indexed_vec::IndexVec;
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_data_structures::stable_hasher::StableVec;
use rustc_data_structures::sync::Lrc;
use rustc_target::spec::PanicStrategy;

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

/// Fetch the MIR for a given def-id right after it's built - this includes
/// unreachable code.
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_codegen_llvm/debuginfo/create_scope_map.rs
Expand Up @@ -21,7 +21,7 @@ use libc::c_uint;

use syntax_pos::Pos;

use rustc_data_structures::bitvec::BitArray;
use rustc_data_structures::bit_set::BitSet;
use rustc_data_structures::indexed_vec::{Idx, IndexVec};

use syntax_pos::BytePos;
Expand Down Expand Up @@ -64,7 +64,7 @@ pub fn create_mir_scopes(
};

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

fn make_mir_scope(cx: &CodegenCx<'ll, '_>,
mir: &Mir,
has_variables: &BitArray<SourceScope>,
has_variables: &BitSet<SourceScope>,
debug_context: &FunctionDebugContextData<'ll>,
scope: SourceScope,
scopes: &mut IndexVec<SourceScope, MirDebugScope<'ll>>) {
Expand Down
8 changes: 4 additions & 4 deletions src/librustc_codegen_llvm/mir/analyze.rs
Expand Up @@ -11,7 +11,7 @@
//! An analysis to determine which locals require allocas and
//! which do not.

use rustc_data_structures::bitvec::BitArray;
use rustc_data_structures::bit_set::BitSet;
use rustc_data_structures::graph::dominators::Dominators;
use rustc_data_structures::indexed_vec::{Idx, IndexVec};
use rustc::mir::{self, Location, TerminatorKind};
Expand All @@ -22,7 +22,7 @@ use rustc::ty::layout::LayoutOf;
use type_of::LayoutLlvmExt;
use super::FunctionCx;

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

Expand Down Expand Up @@ -54,7 +54,7 @@ pub fn non_ssa_locals(fx: &FunctionCx<'a, 'll, 'tcx>) -> BitArray<mir::Local> {
struct LocalAnalyzer<'mir, 'a: 'mir, 'll: 'a, 'tcx: 'll> {
fx: &'mir FunctionCx<'a, 'll, 'tcx>,
dominators: Dominators<mir::BasicBlock>,
non_ssa_locals: BitArray<mir::Local>,
non_ssa_locals: BitSet<mir::Local>,
// The location of the first visited direct assignment to each
// local, or an invalid location (out of bounds `block` index).
first_assignment: IndexVec<mir::Local, Location>
Expand All @@ -67,7 +67,7 @@ impl LocalAnalyzer<'mir, 'a, 'll, 'tcx> {
let mut analyzer = LocalAnalyzer {
fx,
dominators: fx.mir.dominators(),
non_ssa_locals: BitArray::new(fx.mir.local_decls.len()),
non_ssa_locals: BitSet::new_empty(fx.mir.local_decls.len()),
first_assignment: IndexVec::from_elem(invalid_location, &fx.mir.local_decls)
};

Expand Down
6 changes: 3 additions & 3 deletions src/librustc_codegen_llvm/mir/mod.rs
Expand Up @@ -31,7 +31,7 @@ use syntax::symbol::keywords;

use std::iter;

use rustc_data_structures::bitvec::BitArray;
use rustc_data_structures::bit_set::BitSet;
use rustc_data_structures::indexed_vec::IndexVec;

pub use self::constant::codegen_static_initializer;
Expand Down Expand Up @@ -341,7 +341,7 @@ pub fn codegen_mir(
debuginfo::start_emitting_source_locations(&fx.debug_context);

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

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

0 comments on commit 266e2d3

Please sign in to comment.