Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve handling of type bounds in bit_set.rs. #54370

Merged
merged 1 commit into from
Sep 22, 2018

Conversation

nnethercote
Copy link
Contributor

Currently, BitSet doesn't actually know its own domain size; it just
knows how many words it contains. We can make it better.

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.
@rust-highfive
Copy link
Collaborator

r? @nikomatsakis

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 19, 2018
@nnethercote
Copy link
Contributor Author

BTW, is it reasonable to change the encoding/decoding representation of BitSet? I would guess that one version of the compiler would refuse to deserialize output that was serialized by a different version of the compiler...?

@nnethercote
Copy link
Contributor Author

I did some local perf runs. The cost of the extra assertions was negligible.

@nikomatsakis
Copy link
Contributor

@nnethercote

BTW, is it reasonable to change the encoding/decoding representation of BitSet? I would guess that one version of the compiler would refuse to deserialize output that was serialized by a different version of the compiler...?

We do not currently guarantee a stable ABI across compiler revisions... so yes, it is ok.

@nikomatsakis
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Sep 20, 2018

📌 Commit 99f05e8 has been approved by nikomatsakis

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 20, 2018
pietroalbini added a commit to pietroalbini/rust that referenced this pull request Sep 22, 2018
…ikomatsakis

Improve handling of type bounds in `bit_set.rs`.

Currently, `BitSet` doesn't actually know its own domain size; it just
knows how many words it contains. We can make it better.
bors added a commit that referenced this pull request Sep 22, 2018
Rollup of 16 pull requests

Successful merges:

 - #53652 (define copy_within on slices)
 - #54261 (Make `dyn` a keyword in the 2018 edition)
 - #54280 (remove (more) CAS API from Atomic* types where not natively supported)
 - #54323 (rustbuild: drop color handling)
 - #54350 (Support specifying edition in doc test)
 - #54370 (Improve handling of type bounds in `bit_set.rs`.)
 - #54371 (add -Zui-testing to rustdoc)
 - #54374 (Make 'proc_macro::MultiSpan' public.)
 - #54402 (Use no_default_libraries for all NetBSD flavors)
 - #54409 (Detect `for _ in in bar {}` typo)
 - #54412 (add applicability to span_suggestion call)
 - #54413 (Add UI test for deref recursion limit printing twice)
 - #54415 (parser: Tweak function parameter parsing to avoid rollback on succesfull path)
 - #54420 (Compress `Liveness` data some more.)
 - #54422 (Simplify slice's first(_mut) and last(_mut) with get)
 - #54446 (Unify christianpoveda's emails)

Failed merges:

 - #54058 (Introduce the partition_dedup/by/by_key methods for slices)

r? @ghost
bors added a commit that referenced this pull request Sep 22, 2018
Rollup of 16 pull requests

Successful merges:

 - #53652 (define copy_within on slices)
 - #54261 (Make `dyn` a keyword in the 2018 edition)
 - #54280 (remove (more) CAS API from Atomic* types where not natively supported)
 - #54323 (rustbuild: drop color handling)
 - #54350 (Support specifying edition in doc test)
 - #54370 (Improve handling of type bounds in `bit_set.rs`.)
 - #54371 (add -Zui-testing to rustdoc)
 - #54374 (Make 'proc_macro::MultiSpan' public.)
 - #54402 (Use no_default_libraries for all NetBSD flavors)
 - #54409 (Detect `for _ in in bar {}` typo)
 - #54412 (add applicability to span_suggestion call)
 - #54413 (Add UI test for deref recursion limit printing twice)
 - #54415 (parser: Tweak function parameter parsing to avoid rollback on succesfull path)
 - #54420 (Compress `Liveness` data some more.)
 - #54422 (Simplify slice's first(_mut) and last(_mut) with get)
 - #54446 (Unify christianpoveda's emails)

Failed merges:

 - #54058 (Introduce the partition_dedup/by/by_key methods for slices)

r? @ghost
@bors bors merged commit 99f05e8 into rust-lang:master Sep 22, 2018
@nnethercote nnethercote deleted the better-domain_size branch September 23, 2018 21:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants