Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 36b495f

Browse files
committed
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.
1 parent 523a1b1 commit 36b495f

File tree

14 files changed

+804
-73
lines changed

14 files changed

+804
-73
lines changed

compiler/rustc_borrowck/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use rustc_errors::{Applicability, Diagnostic, DiagnosticBuilder, ErrorReported};
2222
use rustc_hir as hir;
2323
use rustc_hir::def_id::LocalDefId;
2424
use rustc_hir::Node;
25-
use rustc_index::bit_set::BitSet;
25+
use rustc_index::bit_set::ChunkedBitSet;
2626
use rustc_index::vec::IndexVec;
2727
use rustc_infer::infer::{InferCtxt, TyCtxtInferExt};
2828
use rustc_middle::mir::{
@@ -1667,7 +1667,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
16671667
location: Location,
16681668
desired_action: InitializationRequiringAction,
16691669
place_span: (PlaceRef<'tcx>, Span),
1670-
maybe_uninits: &BitSet<MovePathIndex>,
1670+
maybe_uninits: &ChunkedBitSet<MovePathIndex>,
16711671
from: u64,
16721672
to: u64,
16731673
) {

compiler/rustc_data_structures/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ extern crate cfg_if;
3737
#[macro_use]
3838
extern crate rustc_macros;
3939

40+
pub use rustc_index::static_assert_size;
41+
4042
#[inline(never)]
4143
#[cold]
4244
pub fn cold_path<F: FnOnce() -> R, R>(f: F) -> R {

compiler/rustc_data_structures/src/macros.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,3 @@
1-
/// Type size assertion. The first argument is a type and the second argument is its expected size.
2-
#[macro_export]
3-
macro_rules! static_assert_size {
4-
($ty:ty, $size:expr) => {
5-
const _: [(); $size] = [(); ::std::mem::size_of::<$ty>()];
6-
};
7-
}
8-
91
#[macro_export]
102
macro_rules! enum_from_u32 {
113
($(#[$attr:meta])* pub enum $name:ident {

0 commit comments

Comments
 (0)