Skip to content

Commit

Permalink
Improve handling of type bounds in bit_set.rs.
Browse files Browse the repository at this point in the history
Currently, `BitSet` doesn't actually know its own domain size; it just
knows how many words it contains. To improve things, this commit makes
the following changes.

- It changes `BitSet` and `SparseBitSet` to store their own domain size,
  and do more precise bounds and same-size checks with it. It also
  changes the signature of `BitSet::to_string()` (and puts it within
  `impl ToString`) now that the domain size need not be passed in from
  outside.

- It uses `derive(RustcDecodable, RustcEncodable)` for `BitSet`. This
  required adding code to handle `PhantomData` in `libserialize`.

- As a result, it removes the domain size from `HybridBitSet`, making a
  lot of that code nicer.

- Both set_up_to() and clear_above() were overly general, working with
  arbitrary sizes when they are only needed for the domain size. The
  commit removes the former, degeneralizes the latter, and removes the
  (overly general) tests.

- Changes `GrowableBitSet::grow()` to `ensure()`, fixing a bug where a
  (1-based) domain size was confused with a (0-based) element index.

- Changes `BitMatrix` to store its row count, and do more precise bounds
  checks with it.

- Changes `ty_params` in `select.rs` from a `BitSet` to a
  `GrowableBitSet` because it repeatedly failed the new, more precise
  bounds checks. (Changing the type was simpler than computing an
  accurate domain size.)

- Various other minor improvements.
  • Loading branch information
nnethercote committed Sep 19, 2018
1 parent ff6422d commit 99f05e8
Show file tree
Hide file tree
Showing 6 changed files with 210 additions and 202 deletions.
4 changes: 2 additions & 2 deletions src/librustc/traits/select.rs
Expand Up @@ -44,7 +44,7 @@ use ty::relate::TypeRelation;
use middle::lang_items;
use mir::interpret::{GlobalId};

use rustc_data_structures::bit_set::BitSet;
use rustc_data_structures::bit_set::GrowableBitSet;
use rustc_data_structures::sync::Lock;
use std::iter;
use std::cmp;
Expand Down Expand Up @@ -3069,7 +3069,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
} else {
return Err(Unimplemented);
};
let mut ty_params = BitSet::new_empty(substs_a.types().count());
let mut ty_params = GrowableBitSet::new_empty();
let mut found = false;
for ty in field.walk() {
if let ty::Param(p) = ty.sty {
Expand Down

0 comments on commit 99f05e8

Please sign in to comment.