Commit Graph

73 Commits

Author SHA1 Message Date
Nicholas Nethercote
36b495f3cf Introduce ChunkedBitSet and use it for some dataflow analyses.
This reduces peak memory usage significantly for some programs with very
large functions, such as:
- `keccak`, `unicode_normalization`, and `match-stress-enum`, from
  the `rustc-perf` benchmark suite;
- `http-0.2.6` from crates.io.

The new type is used in the analyses where the bitsets can get huge
(e.g. 10s of thousands of bits): `MaybeInitializedPlaces`,
`MaybeUninitializedPlaces`, and `EverInitializedPlaces`.

Some refactoring was required in `rustc_mir_dataflow`. All existing
analysis domains are either `BitSet` or a trivial wrapper around
`BitSet`, and access in a few places is done via `Borrow<BitSet>` or
`BorrowMut<BitSet>`. Now that some of these domains are `ClusterBitSet`,
that no longer works. So this commit replaces the `Borrow`/`BorrowMut`
usage with a new trait `BitSetExt` containing the needed bitset
operations. The impls just forward these to the underlying bitset type.
This required fiddling with trait bounds in a few places.

The commit also:
- Moves `static_assert_size` from `rustc_data_structures` to
  `rustc_index` so it can be used in the latter; the former now
  re-exports it so existing users are unaffected.
- Factors out some common "clear excess bits in the final word"
  functionality in `bit_set.rs`.
- Uses `fill` in a few places instead of loops.
2022-02-23 10:18:49 +11:00
est31
2ef8af6619 Adopt let else in more places 2022-02-19 17:27:43 +01:00
est31
60f969a4f2 Adopt let_else in even more places 2022-02-16 22:43:39 +01:00
lcnr
ea624699e3 implement lint for suspicious auto trait impls 2022-02-01 09:55:19 +01:00
Nicholas Nethercote
416399dc10 Make Decodable and Decoder infallible.
`Decoder` has two impls:
- opaque: this impl is already partly infallible, i.e. in some places it
  currently panics on failure (e.g. if the input is too short, or on a
  bad `Result` discriminant), and in some places it returns an error
  (e.g. on a bad `Option` discriminant). The number of places where
  either happens is surprisingly small, just because the binary
  representation has very little redundancy and a lot of input reading
  can occur even on malformed data.
- json: this impl is fully fallible, but it's only used (a) for the
  `.rlink` file production, and there's a `FIXME` comment suggesting it
  should change to a binary format, and (b) in a few tests in
  non-fundamental ways. Indeed #85993 is open to remove it entirely.

And the top-level places in the compiler that call into decoding just
abort on error anyway. So the fallibility is providing little value, and
getting rid of it leads to some non-trivial performance improvements.

Much of this commit is pretty boring and mechanical. Some notes about
a few interesting parts:
- The commit removes `Decoder::{Error,error}`.
- `InternIteratorElement::intern_with`: the impl for `T` now has the same
  optimization for small counts that the impl for `Result<T, E>` has,
  because it's now much hotter.
- Decodable impls for SmallVec, LinkedList, VecDeque now all use
  `collect`, which is nice; the one for `Vec` uses unsafe code, because
  that gave better perf on some benchmarks.
2022-01-22 10:38:31 +11:00
lcnr
962582981f remove unused FIXME 2022-01-12 16:09:01 +01:00
Mark Rousskov
00c55a1bb8 Introduce IntervalSet
This is a compact, fast storage for variable-sized sets, typically consisting of
larger ranges. It is less efficient than a bitset if ranges are both small and
the domain size is small, but will still perform acceptably. With enormous
domain sizes and large ranges, the interval set performs much better, as it can
be much more densely packed in memory than the uncompressed bit set alternative.
2021-12-30 22:33:44 -05:00
pierwill
a4a8c241c7 Require Ord for rustc_index::SparseBitSet::last_set_in 2021-12-22 10:50:57 -06:00
pierwill
8df9248591 Remove PartialOrd and Ord from LocalDefId
Implement `Ord`, `PartialOrd` for SpanData
2021-12-22 10:50:57 -06:00
Tomasz Miąsko
d496cca3b1 Derive hash for BitSet and BitMatrix 2021-12-18 08:56:38 +01:00
PFPoitras
304ede6bcc Stabilize iter::zip. 2021-12-14 18:50:31 -04:00
bors
8a48b376d5 Auto merge of #90491 - Mark-Simulacrum:push-pred-faster, r=matthewjasper
Optimize live point computation

This refactors the live-point computation to lower per-MIR-instruction costs by operating on a largely per-block level. This doesn't fundamentally change the number of operations necessary, but it greatly improves the practical performance by aggregating bit manipulation into ranges rather than single-bit; this scales much better with larger blocks.

On the benchmark provided in #90445, with 100,000 array elements, walltime for a check build is improved from 143 seconds to 15.

I consider the tiny losses here acceptable given the many small wins on real world benchmarks and large wins on stress tests. The new code scales much better, but on some subset of inputs the slightly higher constant overheads decrease performance somewhat. Overall though, this is expected to be a big win for pathological cases (as illustrated by the test case motivating this work) and largely not material for non-pathological cases. I consider the new code somewhat easier to follow, too.
2021-11-24 15:51:46 +00:00
pierwill
845c25d1b4 Generate documentation in rustc rustc_index::newtype_index macro
The macro now documents all generated items. Documentation notes
possible panics and unsafety.
2021-11-13 18:50:29 -06:00
Mark Rousskov
03afb61b53 Optimize live point computation
This is just replicating the previous algorithm, but taking advantage of the
bitset structures to optimize into tighter and better optimized loops.
Particularly advantageous on enormous MIR blocks, which are relatively rare in
practice.
2021-11-03 11:24:59 -04:00
Pietro Albini
b63ab8005a update cfg(bootstrap) 2021-10-23 21:55:57 -04:00
Matthias Krüger
4457014398 Revert "Auto merge of #89709 - clemenswasser:apply_clippy_suggestions_2, r=petrochenkov"
The PR had some unforseen perf regressions that are not as easy to find.
Revert the PR for now.

This reverts commit 6ae8912a3e, reversing
changes made to 86d6d2b738.
2021-10-15 11:28:23 +02:00
LingMan
7943c9c446 Use Option::map_or instead of open coding it 2021-10-12 14:47:52 +02:00
Matthias Krüger
b80dd9e445
Rollup merge of #89643 - cjgillot:overlap, r=matthewjasper
Fix inherent impl overlap check.

The current implementation of the overlap check was slightly buggy, and unified the wrong connected component in the `ids.len() <= 1` case. This became visible in another PR which changed the iteration order of items.

r? ``@matthewjasper`` since you reviewed the other PR.
2021-10-11 23:45:46 +02:00
Clemens Wasser
14b6cf6fd7 Remove unnecessary variable 2021-10-11 08:11:30 +02:00
Clemens Wasser
71dd0b928b Apply clippy suggestions 2021-10-10 15:38:19 +02:00
Camille GILLOT
a3f98a7501 Fix inherent impl overlap check. 2021-10-07 22:42:18 +02:00
Jubilee
9866b090f4
Rollup merge of #89508 - jhpratt:stabilize-const_panic, r=joshtriplett
Stabilize `const_panic`

Closes #51999

FCP completed in #89006

```@rustbot``` label +A-const-eval +A-const-fn +T-lang

cc ```@oli-obk``` for review (not `r?`'ing as not on lang team)
2021-10-04 13:58:17 -07:00
Jacob Pratt
bce8621983
Stabilize const_panic 2021-10-04 02:33:33 -04:00
bjorn3
9f4cb862ca Replace Fn impls with RPIT impls in rustc_index
This is cleaner and removes an unstable feature usage
2021-10-03 17:50:53 +02:00
bjorn3
998753c6f7 Swap out unboxed_closures feature gate for min_specialization
For some reason unboxed_closures supresses the feature gate for
min_specialization when implementing TrustedStep. min_specialization is
the true feature that is used.
2021-10-02 19:09:29 +02:00
Vadim Petrochenkov
fbe5e5c0ee rustc_index: Add some map-like APIs to IndexVec 2021-09-22 03:11:29 +03:00
Mark Rousskov
c746be2219 Migrate to 2021 2021-09-20 22:21:42 -04:00
Will Crichton
e340a0e249 Suggested changes 2021-08-27 16:21:25 -07:00
Will Crichton
86bd551e4c Addd missing domain size assertions 2021-08-27 11:17:27 -07:00
Will Crichton
c7357270b8 Formatting 2021-08-26 13:23:24 -07:00
Will Crichton
8d9e4f98e1 Fix failing test 2021-08-26 13:09:39 -07:00
Will Crichton
2166c6db43 Add comments and unit tests for new SparseBitMatrix methods 2021-08-26 12:46:59 -07:00
Will Crichton
7e148b0cef Compile failure 2021-08-26 12:26:08 -07:00
Will Crichton
acba31c333 Typo 2021-08-26 12:14:37 -07:00
Will Crichton
953d685ea1 Add remaining impl for hybrid X dense 2021-08-26 12:12:29 -07:00
Will Crichton
e854027c12 Compilation failure in tests 2021-08-26 11:46:57 -07:00
Will Crichton
8767b00d67 Formatting 2021-08-26 11:46:00 -07:00
Will Crichton
ce37f0a355 Add comments 2021-08-26 11:45:25 -07:00
Will Crichton
d73a169f93 Fix sparse intersect bug, add more sparse / dense tests 2021-08-26 11:39:13 -07:00
Will Crichton
1c1603e0b5 Add unit tests for BitSet intersect/subtract 2021-08-25 23:15:21 -07:00
Will Crichton
800d6531a9 Small fixes 2021-08-25 22:54:26 -07:00
Will Crichton
2110ac303e Add optimized sparse-hybrid / dense-hybrid intersect 2021-08-25 15:10:33 -07:00
Will Crichton
415d5e860f Remove BitRelations impls for SparseBitSet, add optimizations 2021-08-25 15:03:09 -07:00
Will Crichton
6cf3786ba4 Fix HybridBitSet port issue 2021-08-24 18:14:39 -07:00
Will Crichton
79e0a0faf9 Refactor BitSet relational methods into trait with parameterized
right-hand side
2021-08-24 17:50:08 -07:00
Will Crichton
0ca51b6b66 Make SparseBitMatrix::ensure_row public to enable general mutation of rows 2021-08-23 16:13:17 -07:00
Jade
3cf820e17d rfc3052: Remove authors field from Cargo manifests
Since RFC 3052 soft deprecated the authors field anyway, hiding it from
crates.io, docs.rs, and making Cargo not add it by default, and it is
not generally up to date/useful information, we should remove it from
crates in this repo.
2021-07-29 14:56:05 -07:00
bjorn3
312f964478 Remove unused feature gates 2021-05-31 13:55:43 +02:00
bjorn3
9de82d7611 Use allow_internal_unstable more in rustc_index 2021-05-31 12:13:47 +02:00
Jacob Pratt
35ce36812a
Unify feature flags as step_trait
While stdlib implementations of the unchecked methods require unchecked
math, there is no reason to gate it behind this for external users. The
reasoning for a separate `step_trait_ext` feature is unclear, and as
such has been merged as well.
2021-05-26 18:07:10 -04:00