Commit Graph

279 Commits

Author SHA1 Message Date
Nicholas Nethercote
4aadc68a8a Improve CFG traversal in iterate_to_fixpoint
`iterate_to_fixpoint` uses a FIFO worklist. It is seeded in a good order
(reverse postorder for forward analyses, postorder for backward
analyses). But when back edges are present, re-dirtied blocks are pushed
to the back of the queue. Successor blocks of these re-dirtied blocks are
then analyzed even though we know the input states may change later on.

This commit switches to a new min-rank algorithm that always processes
the earliest dirty block in dataflow order.

On most code this makes little difference, but cranelift-codegen has one
enormous function with over 18,000 basic blocks. The old algorithm
required 1.5 million calls to `apply_effects_in_block` to reach a
fixpoint for `EverInitializedPlaces`. The new algorithm requires 90,000.
This results in a 17% reduction in instruction counts for a `Check Full`
build.

Note: the new algorithm also avoids doing anything for unreachable
blocks in backward analyses. (The old algorithm computed states but
never used them meaningfully.)
2026-07-31 09:18:06 +10:00
DaniPopes
71321f5593 Manually implement Clone for GrowableBitSet
Forwards `clone_from` to `DenseBitSet`'s manual implementation.

I don't believe this is currently used but I think it doesn't hurt,
since it could be a small performance footgun.
2026-07-16 22:46:07 +02:00
Amanda Stjerna
219a65fa36 Simplify the initialisation of region values in region_infer
- `RegionInferenceContext::init_free_and_bound_regions()` is inlined into `::new()` and pulled to before initial SCC values are assigned
- A couple of iteration-then-index patterns are changed into `iter_enumerated()`-style patterns
- Some leftover code comments are removed and revised to actually describe the initialisation
- Free regions are now marked as live everywhere in liveness constraints, then copied to scc_values upon initialisation, avoiding performing that logic twice

It should do strictly less work, but almost all of it would only happen on free regions, and there shouldn't be large numbers of those. Depending on the cleverness of the optimiser most of the option/some checks should have been compiled away anyway.

The key advantage as I see it is clearer flow: first liveness constraints are set up, then initial values are initialised, then region inference is ready to run.
2026-06-09 18:06:54 +02:00
bors
e50aa6fba4 Auto merge of #153640 - Zalathar:subchunk, r=wesleywiser
Make bitset `would_modify_words` more vectorizer-friendly



Currently this function compares a single pair of `u64` at a time, which is potentially slower than comparing multiple words before each early-exit check, especially for the large chunks used by ChunkedBitSet.

Perf shows a notable improvement in `cranelift-codegen`, which is the one benchmark that is known to stress these code paths.

- Incorporates https://github.com/rust-lang/rust/pull/153759.
2026-05-19 20:02:33 +00:00
Camille Gillot
c9c70fd45c Simplify append_range. 2026-05-13 20:29:15 +00:00
Camille Gillot
161efa96b3 DestinationPropagation: compute liveness as ranges instead of traveling bitsets. 2026-05-13 20:24:31 +00:00
Zalathar
3dc7e27a97 Make bitset would_modify_words more vectorizer-friendly 2026-05-08 13:58:54 +10:00
Zalathar
766aa193e7 Rename some confusing bitset helper functions 2026-05-08 13:58:54 +10:00
Jonathan Brouwer
8e450e52cf Rollup merge of #153759 - Zalathar:chunk-tests, r=wesleywiser
Add a suite of ChunkedBitSet union/subtract/intersect test scenarios

While working on https://github.com/rust-lang/rust/pull/153754, I found that these code paths are under-tested.
2026-05-07 22:44:05 +02:00
Jacob Pratt
4c592137d2 Rollup merge of #155381 - nnethercote:fix-ChunkedBitSet-subtract, r=Zalathar
Fix a bug in `ChunkedBitSet::subtract`

An operator precedence bug means an incorrect mask is used in `ChunkedBitSet::subtract`. Details in individual commits.

r? @dingxiangfei2009
2026-04-28 05:37:21 -04:00
Jonathan Brouwer
421a94fc88 Rollup merge of #154481 - ferrocene:hoverbear/flag-off-unused-code, r=wesleywiser
Mark a function only used in nightly as nightly only

If you run `./x.py test rustc_next_trait_solver` you'll currently see a failure:

```
warning: method `merge` is never used
  --> compiler/rustc_abi/src/callconv.rs:38:8
   |
25 | impl HomogeneousAggregate {
   | ------------------------- method in this implementation
...
38 |     fn merge(self, other: HomogeneousAggregate) -> Result<HomogeneousAggregate, Heterogeneous> {
   |        ^^^^^
   |
   = note: `#[warn(dead_code)]` (part of `#[warn(unused)]`) on by default

warning: `rustc_abi` (lib) generated 1 warning
```

This is because the usages are behind a nightly feature flag:

fda6d37bb8/compiler/rustc_abi/src/callconv.rs (L52)

fda6d37bb8/compiler/rustc_abi/src/callconv.rs (L131)

fda6d37bb8/compiler/rustc_abi/src/callconv.rs (L167)

This does the flag off.

Test on `main` and this branch:

```
./x.py test rustc_next_trait_solver
```
2026-04-23 09:38:23 +02:00
Mark Rousskov
a64c420c70 Bump stage0 to 1.96 beta 2026-04-16 19:30:56 -04:00
Nicholas Nethercote
3f9dbf2a97 Fix bug in ChunkedBitSet::subtract.
It does a masking operation but the mask is computed incorrectly due to
operator precedence. The mask is of the form `1 << N - 1` but it
should be `(1 << N) - 1` because `-` binds tighter than `1 << N`.

This commit fixes the problem, not by adjusting the precedence, but by
instead using the existing `clear_excess_bits_in_final_word`, which is
consistent with other similar operations.

LLM disclosure: this bug was identified by Claude Code. I did everything
else.
2026-04-16 15:52:33 +10:00
Nicholas Nethercote
c81ff33d1b Add test demonstrating a bug in ChunkedBitSet::subtract.
It results in `b64` having many fewer bits set than it should.

LLM disclosure: this bug was identified by Claude Code. I did everything
else.
2026-04-16 15:51:58 +10:00
Nicholas Nethercote
72b8bc763d Store chunk_domain_size explicitly in Chunk.
Currently we compute it on demand, but it's a little simpler and
slightly faster to store it.
2026-04-07 16:50:19 +10:00
Peter Jaszkowiak
620e92f016 stabilize new Range type and iterator
stabilizes `core::range::Range`
stabilizes `core::range::RangeIter`
stabilizes `std::range` which was missed in prior PRs

Updates docs to reflect stabilization (removed "experimental")

`RangeIter::remainder` is excluded from stabilization
2026-03-30 22:17:27 -06:00
Jynn Nelson
6ea175cd05 Remove unused code 2026-03-30 07:56:16 +00:00
Jonathan Brouwer
997493114f Rollup merge of #151148 - Jarcho:gbit_set, r=davidtwco
Add functions to `GrowableBitSet`

Only really need `insert_range` for clippy, but may as well add the others. Using `Range` instead of `RangeBounds` since an end bound is needed for this to make sense and there aren't any traits to enforce that.
2026-03-25 19:52:56 +01:00
Zalathar
fb850aebcd Remove unused types UnusedGenericParams and FiniteBitSet
These types have been unused since polymorphization was removed in
<https://github.com/rust-lang/rust/pull/133883>.
2026-03-18 10:36:19 +11:00
Zalathar
0a90f8ddc2 Use named fields in ChunkedBitSet's Chunk::Mixed
This helps to clarify that the field with type `ChunkSize` is a count of 1s,
not a length or size.
2026-03-14 21:17:33 +11:00
Zalathar
2a870404fd Add a suite of ChunkedBitSet union/subtract/intersect test scenarios 2026-03-12 17:37:01 +11:00
mu001999
a07f837491 Remove unused features in compiler 2026-02-13 09:25:39 +08:00
Jason Newcomb
e7d56c6d01 Add functions to GrowableBitSet. 2026-01-23 17:06:24 -05:00
Usman Akinyemi
0dc5b52e8e simplify words initialization using Rc::new_zeroed
Now that Rc::new_zeroed is stable, remove the cfg(feature = "nightly")
branch and the temporary zeroed array on stable. This avoids copying a
potentially large [Word; CHUNK_WORDS] into the Rc.

Signed-off-by: Usman Akinyemi <usmanakinyemi202@gmail.com>
2026-01-16 04:25:12 +05:30
Moulins
b31ee3af9c layout: Store inverse memory index in FieldsShape::Arbitrary
All usages of `memory_index` start by calling `invert_bijective_mapping`, so
storing the inverted mapping directly saves some work and simplifies the code.
2025-12-18 22:25:34 +01:00
bjorn3
973c7527b4 Unify the configuration of the compiler docs
Previously it was rather inconsistent which crates got the rust logo and
which didn't and setting html_root_url was forgotten in many cases.
2025-11-05 11:25:27 +00:00
Stuart Cook
cc1d776c1f Rollup merge of #148341 - jyn514:feature-unification, r=BoxyUwU
compiler: Fix a couple issues around cargo feature unification

cc https://github.com/rust-lang/rust/issues/148266. this doesn't fix all the issues (`rustc_public` and `rustc_transmute` still emit warnings when tested individually), but it fixes all the simple ones.

To fix rustc_public I will probably need help from ````@AlexanderPortland```` or ````@makai410```` to make sure I am not accidentally cfg-ing out items that are meant to be public. To fix `rustc_transmute`, I will need to know (from ````@jswrenn```` ?) in what context the `rustc` cargo feature is disapled. To reproduce the issues, you can run `x test rustc_{transmute,public}` locally.

---

The first issue I fixed was a warning in `rustc_index`:
```
Testing stage2 {rustc_parse_format} (aarch64-apple-darwin)
   Compiling rustc_index v0.0.0 (/Users/ci/project/compiler/rustc_index)
error: extern crate `smallvec` is unused in crate `rustc_index`
 --> compiler/rustc_index/src/lib.rs:2:1
  |
2 | #![cfg_attr(all(feature = "nightly", test), feature(stmt_expr_attributes))]
  | ^
  |
  = help: remove the dependency or add `use smallvec as _;` to the crate root
  = note: `-D unused-crate-dependencies` implied by `-D warnings`
  = help: to override `-D warnings` add `#[allow(unused_crate_dependencies)]`

error: could not compile `rustc_index` (lib) due to 1 previous error
```

The second was that `type_ir_macros` didn't fully specify its dependencies:
```
Testing stage1 {rustc_type_ir_macros} (aarch64-apple-darwin)
   Compiling rustc_type_ir_macros v0.0.0 (/Users/jyn/src/ferrocene3/compiler/rustc_type_ir_macros)
error[E0432]: unresolved import `syn::visit_mut`
   --> compiler/rustc_type_ir_macros/src/lib.rs:2:10
    |
  2 | use syn::visit_mut::VisitMut;
    |          ^^^^^^^^^ could not find `visit_mut` in `syn`
    |
note: found an item that was configured out
   --> /Users/jyn/.local/lib/cargo/registry/src/index.crates.io-1949cf8c6b5b557f/syn-2.0.106/src/lib.rs:880:21
    |
878 | #[cfg(feature = "visit-mut")]
    |       --------------------- the item is gated behind the `visit-mut` feature
879 | #[cfg_attr(docsrs, doc(cfg(feature = "visit-mut")))]
880 | pub use crate::gen::visit_mut;
    |                     ^^^^^^^^^

error[E0433]: failed to resolve: could not find `visit_mut` in `syn`
   --> compiler/rustc_type_ir_macros/src/lib.rs:206:18
    |
206 |             syn::visit_mut::visit_type_path_mut(self, i);
    |                  ^^^^^^^^^ could not find `visit_mut` in `syn`
    |
note: found an item that was configured out
   --> /Users/jyn/.local/lib/cargo/registry/src/index.crates.io-1949cf8c6b5b557f/syn-2.0.106/src/lib.rs:880:21
    |
878 | #[cfg(feature = "visit-mut")]
    |       --------------------- the item is gated behind the `visit-mut` feature
879 | #[cfg_attr(docsrs, doc(cfg(feature = "visit-mut")))]
880 | pub use crate::gen::visit_mut;
    |                     ^^^^^^^^^
```
2025-11-05 10:59:19 +11:00
Marijn Schouten
9e4ec2acc7 clippy fixes and code simplification 2025-11-02 08:16:38 +00:00
Jynn Nelson
60c230b94a compiler: Fix a couple issues around cargo feature unification
The first was a warning:
```
Testing stage2 {rustc_parse_format} (aarch64-apple-darwin)
   Compiling rustc_index v0.0.0 (/Users/ci/project/compiler/rustc_index)
error: extern crate `smallvec` is unused in crate `rustc_index`
 --> compiler/rustc_index/src/lib.rs:2:1
  |
2 | #![cfg_attr(all(feature = "nightly", test), feature(stmt_expr_attributes))]
  | ^
  |
  = help: remove the dependency or add `use smallvec as _;` to the crate root
  = note: `-D unused-crate-dependencies` implied by `-D warnings`
  = help: to override `-D warnings` add `#[allow(unused_crate_dependencies)]`

error: could not compile `rustc_index` (lib) due to 1 previous error
```

The second was that `type_ir_macros` didn't fully specify its
dependencies:
```
Testing stage1 {rustc_type_ir_macros} (aarch64-apple-darwin)
   Compiling rustc_type_ir_macros v0.0.0 (/Users/jyn/src/ferrocene3/compiler/rustc_type_ir_macros)
error[E0432]: unresolved import `syn::visit_mut`
   --> compiler/rustc_type_ir_macros/src/lib.rs:2:10
    |
  2 | use syn::visit_mut::VisitMut;
    |          ^^^^^^^^^ could not find `visit_mut` in `syn`
    |
note: found an item that was configured out
   --> /Users/jyn/.local/lib/cargo/registry/src/index.crates.io-1949cf8c6b5b557f/syn-2.0.106/src/lib.rs:880:21
    |
878 | #[cfg(feature = "visit-mut")]
    |       --------------------- the item is gated behind the `visit-mut` feature
879 | #[cfg_attr(docsrs, doc(cfg(feature = "visit-mut")))]
880 | pub use crate::gen::visit_mut;
    |                     ^^^^^^^^^

error[E0433]: failed to resolve: could not find `visit_mut` in `syn`
   --> compiler/rustc_type_ir_macros/src/lib.rs:206:18
    |
206 |             syn::visit_mut::visit_type_path_mut(self, i);
    |                  ^^^^^^^^^ could not find `visit_mut` in `syn`
    |
note: found an item that was configured out
   --> /Users/jyn/.local/lib/cargo/registry/src/index.crates.io-1949cf8c6b5b557f/syn-2.0.106/src/lib.rs:880:21
    |
878 | #[cfg(feature = "visit-mut")]
    |       --------------------- the item is gated behind the `visit-mut` feature
879 | #[cfg_attr(docsrs, doc(cfg(feature = "visit-mut")))]
880 | pub use crate::gen::visit_mut;
    |                     ^^^^^^^^^
```
2025-10-31 14:14:05 -04:00
Josh Stone
8fd2dc0034 Update #[cfg(bootstrap)] 2025-10-28 13:35:43 -07:00
Camille Gillot
0156eaf0d1 Introduce indexvec macro. 2025-10-22 00:52:52 +00:00
Matthias Krüger
7604d12e05 Rollup merge of #147751 - nnethercote:bit_set-Word, r=Zalathar
Use `bit_set::Word` in a couple more places.

It's a synonym for `u64` and there are a couple of places where we use `u64` where we should use `Word`, which this commit fixes.

I found this when I tried changing `Word` to `u128` (which made performance worse).

r? `````@Zalathar`````
2025-10-16 19:35:27 +02:00
bors
779e19d8ba Auto merge of #147644 - cjgillot:bitsetvec, r=jackh726
Use regular Vec in BitSet.

That code is hot enough for the branch in all accesses to `SmallVec` to appear in profiles.
2025-10-16 14:06:35 +00:00
Nicholas Nethercote
8787c0b863 Use bit_set::Word in a couple more places.
It's a synonym for `u64` and there are a couple of places where we use
`u64` where we should use `Word`, which this commit fixes.

I found this when I tried changing `Word` to `u128` (which made
performance worse).
2025-10-16 11:45:07 +11:00
Nicholas Nethercote
60481827f6 Add a != check to ChunkedBitSet::union.
It's a big speed win for cranelift-codegen-0.119.0.
2025-10-15 13:49:38 +11:00
Nicholas Nethercote
facb9aca79 Refactor some ChunkedBitSet operations.
For less indentation, mostly.
2025-10-15 13:49:05 +11:00
Matthias Krüger
b134c9c135 Rollup merge of #147630 - nnethercote:bitset-cleanups, r=cjgillot,Zalathar
Bitset cleanups

Some minor cleanups I did while working on rust-lang/rust#147619.

r? ```@Zalathar```
2025-10-14 19:47:30 +02:00
Nicholas Nethercote
8386278866 Factor out a recurring pattern as count_ones. 2025-10-14 16:35:56 +11:00
Camille Gillot
04323227f4 Use regular Vec in BitSet. 2025-10-13 18:15:25 +00:00
Nicholas Nethercote
6e85c4e2d9 Remove some unused bitset code. 2025-10-13 21:51:56 +11:00
Nicholas Nethercote
2611bf753e Tidy some patterns in ChunkedBitSet ops. 2025-10-13 14:07:06 +11:00
Zalathar
9ff52bf332 Clear ChunkedBitSet without reallocating 2025-10-13 13:58:01 +11:00
Mark Rousskov
201f299ef6 Apply cfg(bootstrap) replacement 2025-09-26 19:09:23 -04:00
Stuart Cook
7a5819d154 Rollup merge of #144091 - thaliaarchi:stabilize-new-zeroed, r=Mark-Simulacrum
Stabilize `new_zeroed_alloc`

The corresponding `new_uninit` and `new_uninit_slice` functions were stabilized in rust-lang/rust#129401, but the zeroed counterparts were left for later out of a [desire](https://github.com/rust-lang/rust/issues/63291#issuecomment-2161039756) to stabilize only the minimal set. These functions are straightforward mirrors of the uninit functions and well-established. Since no blockers or design questions have surfaced in the past year, I think it's time to stabilize them.

Tracking issue: rust-lang/rust#129396
2025-09-21 14:42:33 +10:00
Matthias Krüger
d0ba5e33ff Rollup merge of #144765 - Qelxiros:range-inclusive-last, r=jhpratt
inclusive `Range`s: change `end` to `last`

Tracking issue: rust-lang/rust#125687
ACP: rust-lang/libs-team#511
2025-09-10 14:17:37 +02:00
Jeremy Smart
8d0c07f1a1 change end to last 2025-09-08 22:07:43 -04:00
Camille Gillot
4e9dd1b67b Do not use prepend to avoid quadratic behaviour. 2025-09-07 16:36:30 +00:00
Camille Gillot
b9262bce67 Use regular MaybeLiveLocals. 2025-09-07 16:35:30 +00:00
Camille GILLOT
9b8a719ae4 Reimplement DestinationPropagation according to live ranges. 2025-09-07 16:24:46 +00:00
Camille GILLOT
2ff92e83af Introduce fast insertion at extremities to IntervalSet. 2025-09-07 16:06:40 +00:00