639 Commits

Author SHA1 Message Date
Adwin White 6279106e72 fix all errors 2026-04-20 00:18:28 +08:00
Waffle Lapkin 0f767084b8 ty::Alias refactor: fixup all the compiler code 2026-04-07 10:08:12 +02:00
Jonathan Brouwer 5d17f08215 Rollup merge of #153432 - nnethercote:dataflow-comments, r=cjgillot
Fix some comments about dataflow analysis.

Mostly in the examples in `initialized.rs`. In particular, the `EverInitializedPlaces` example currently doesn't cover how it's initialization sites that are tracked, rather than local variables (that's the `b_0`/`b_1` distinction in the example.)

r? @cjgillot
2026-03-12 12:31:40 +01:00
Zalathar 985b41d387 Remove the rustc_data_structures::assert_matches! re-exports 2026-03-08 22:02:23 +11:00
Josh Stone 32bae1353e Update cfg(bootstrap) 2026-03-07 10:42:02 -08:00
Nicholas Nethercote 1f94e979fb Fix some comments about dataflow analysis.
Mostly in the examples in `initialized.rs`. In particular, the
`EverInitializedPlaces` example currently doesn't cover how it's
initialization sites that are tracked, rather than local variables
(that's the `b_0`/`b_1` distinction in the example.)
2026-03-05 16:09:39 +11:00
Jana Dönszelmann decec173ec remove AttributeKind everywhere 2026-02-20 09:50:16 +01:00
Jana Dönszelmann 63edc913fa change all uses 2026-02-20 09:50:16 +01:00
Camille Gillot 6d4b1b38e7 Remove ShallowInitBox. 2026-02-17 11:25:50 +00:00
Lukas Bergdoll 2f3b952349 Stabilize assert_matches 2026-02-11 14:13:44 +01:00
Jonathan Brouwer 4fdd085e28 Convert to inline diagnostics in rustc_mir_dataflow 2026-02-03 23:25:59 +01:00
Jamie Hill-Daniel b668057d79 Port rustc_mir to attribute parser 2026-02-03 13:55:45 +00:00
Zalathar 7ec34defe9 Temporarily re-export assert_matches! to reduce stabilization churn 2026-01-19 18:26:53 +11:00
Nicholas Nethercote 8ca47cd1fe Clarify MoveData::init_loc_map.
Change the `SmallVec` size from 4 to 1, because that's sufficient in the
vast majority of cases. (This doesn't affect performance in practice, so
it's more of a code clarity change than a performance change.)
2026-01-02 09:29:26 +11:00
bors c7aa99f36c Auto merge of #142881 - cjgillot:minimap, r=saethlin
JumpThreading: compute place and value indices on-demand

Profiling JumpThreading reveals that a large part of the runtime happens constructing the place and value `Map`. This is unfortunate, as jump-threading may end up not even doing anything.

The cause for this large up-front cost is following: `Map` attempts to create a `PlaceIndex` for each place that *may* hold a relevant value. This means all places that appear in MIR, but also all places whose value is accessed by a projection of a copy of a larger place.

This PR refactors the creation of `Map` to happen on-demand: place and value indices are created when threading computation happens.

The up-front mode is still relevant for DataflowConstProp, so is not touched.
2025-12-27 03:12:17 +00:00
Camille Gillot 6319bee585 Introduce Operand::RuntimeChecks. 2025-12-14 17:25:53 +00:00
Camille Gillot 1a227bd47f Replace Rvalue::NullaryOp by a variant in mir::ConstValue. 2025-12-14 17:25:51 +00:00
Camille GILLOT 9415102fb4 Create place and value indices on-demand. 2025-12-14 16:33:24 +00:00
Camille GILLOT 051dd12f9e Pre-allocate places vectors. 2025-12-14 16:33:24 +00:00
Camille GILLOT 3d83b9597d Split Map::register. 2025-12-14 16:33:24 +00:00
Esteban Küber 146711fc24 Use let...else instead of match foo { ... _ => return }; and if let ... else return 2025-12-12 17:52:39 +00:00
bors 4ad239f415 Auto merge of #142821 - cjgillot:jump-threading-single, r=saethlin
Compute jump threading opportunities in a single pass

The current implementation of jump threading walks MIR CFG backwards from each `SwitchInt` terminator. This PR replaces this by a single postorder traversal of MIR. In theory, we could do a full fixpoint dataflow analysis, but this has low returns as we forbid threading through a loop header.

The second commit in this PR modifies the carried state to a lighter data structure. The current implementation uses some kind of `IndexVec<ValueIndex, &[Condition]>`. This is needlessly heavy, as the state rarely ever carries more than a few `Condition`s. The first commit replaces this state with a simpler `&[Condition]`, and puts the corresponding `ValueIndex` inside `Condition`.

The three later commits are perf tweaks.

The sixth commit is the main change. Instead of carrying the goto target inside the condition, we maintain a set of conditions associated with each block, and their consequences in following blocks. Think: if this condition is fulfilled in this block, then that condition is fulfilled in that block. This makes the threading algorithm much easier to implement, without the extra bookkeeping of `ThreadingOpportunity` we had.

Later commits modify that algorithm to shrink the set of duplicated blocks. By propagating fulfilled conditions down the CFG, and trimming costly threads.
2025-12-01 23:44:49 +00:00
Camille Gillot 72444372ae Replace OffsetOf by an actual sum. 2025-11-18 00:10:03 +00:00
Camille GILLOT acf3b6a6a6 Skip process_constant if state has no matching value. 2025-11-16 01:38:16 +00:00
Camille Gillot 4f24d70395 Extend value_analysis API. 2025-11-16 01:37:48 +00:00
Stuart Cook d3475140ee Rollup merge of #128666 - pitaj:intrinsic-overflow_checks, r=BoxyUwU
Add `overflow_checks` intrinsic

This adds an intrinsic which allows code in a pre-built library to inherit the overflow checks option from a crate depending on it. This enables code in the standard library to explicitly change behavior based on whether `overflow_checks` are enabled, regardless of the setting used when standard library was compiled.

This is very similar to the `ub_checks` intrinsic, and refactors the two to use a common mechanism.

The primary use case for this is to allow the new `RangeFrom` iterator to yield the maximum element before overflowing, as requested [here](https://github.com/rust-lang/rust/issues/125687#issuecomment-2151118208). This PR includes a working `IterRangeFrom` implementation based on this new intrinsic that exhibits the desired behavior.

[Prior discussion on Zulip](https://rust-lang.zulipchat.com/#narrow/stream/219381-t-libs/topic/Ability.20to.20select.20code.20based.20on.20.60overflow_checks.60.3F)
2025-11-09 13:22:23 +11:00
Peter Jaszkowiak cc8b95cc54 add overflow_checks intrinsic 2025-11-08 10:57:35 -07:00
Nicholas Nethercote 8793239702 Put Analysis back into Results.
`Results` used to contain an `Analysis`, but it was removed in #140234.
That change made sense because the analysis was mutable but the entry
states were immutable and it was good to separate them so the mutability
of the different pieces was clear.

Now that analyses are immutable there is no need for the separation,
lots of analysis+results pairs can be combined, and the names are going
back to what they were before:
- `Results` -> `EntryStates`
- `AnalysisAndResults` -> `Results`
2025-10-28 10:26:50 +11:00
Nicholas Nethercote a97cd3ba57 Make Analysis immutable in many more places.
The `state: A::Domain` value is the primary things that's modified when
performing an analysis. The `Analysis` impl is immutable in every case
but one (`MaybeRequiredStorage`) and it now uses interior mutability.

As well as changing many `&mut A` arguments to `&A`, this also:
- lets `CowMut` be replaced with the simpler `SimpleCow` in `cursor.rs`;
- removes the need for the `RefCell` in `Formatter`;
- removes the need for `MaybeBorrowedLocals` to impl `Clone`, because
  it's a unit type and it's now clear that its constructor can be used
  directly instead of being put into a local variable and cloned.
2025-10-28 08:23:27 +11:00
Nicholas Nethercote 8afbd9fe02 Use a RefCell in MaybeRequiresStorage.
This will let us make `Analysis` arguments in many other places
immutable, in the next commit.
2025-10-27 18:37:10 +11:00
Nicholas Nethercote 517b767fa1 Reorder args for visit_results_in_block.
Put `analysis` first, to match `apply_effects_in_range`.
2025-10-27 18:37:10 +11:00
Nicholas Nethercote 958a2e4a3d Make Analysis immutable in ResultsVisitor::visit_* methods.
This makes sense -- you wouldn't expect that visiting the results of an
analysis would change the analysis itself.
2025-10-27 18:37:06 +11:00
Peter Jaszkowiak 2e5d395f2b refactor ub_checks and contract_checks to share logic 2025-10-25 14:30:04 -06:00
Camille Gillot 5dfbf67f94 Replace NullOp::SizeOf and NullOp::AlignOf by lang items. 2025-10-23 00:38:28 +00:00
beepster4096 bce7f71589 make move unwrap_binder! a move subpath 2025-10-11 22:51:40 -07:00
beepster4096 b151a5e6a2 update movepath docs 2025-10-11 22:51:40 -07:00
beepster4096 fb1c90a0ae use abstraction over projectionelem in move analysis 2025-10-11 22:51:40 -07:00
Camille Gillot b7c2b3dc80 Remove StatementKind::Deinit. 2025-10-10 12:57:24 +00:00
dianqk 8da04285cf mir-opt: Eliminate dead statements even if they are used by debuginfos 2025-10-02 14:58:59 +08:00
dianqk 85b2f70693 mir-opt: Eliminate trivial unnecessary storage annotations 2025-10-02 14:55:51 +08:00
dianqk 571412f819 mir-opt: Eliminate dead ref statements 2025-10-02 14:55:50 +08:00
beepster4096 aa5a21450a ProjectionElem::Subtype -> CastKind::Subtype 2025-09-26 01:25:26 -07:00
Stuart Cook 540fd20ba6 Rollup merge of #146664 - fmease:clean-up-dyn, r=jdonszelmann
Clean up `ty::Dynamic`

1. As a follow-up to PR rust-lang/rust#143036, remove `DynKind` entirely.
2. Inside HIR ty lowering, consolidate modules `dyn_compatibility` and `lint` into `dyn_trait`
   * `dyn_compatibility` wasn't about dyn compatibility itself, it's about lowering trait object types
   * `lint` contained dyn-Trait-specific diagnostics+lints only
2025-09-18 11:48:51 +10:00
León Orell Valerian Liehr 26f3337d4e Remove DynKind 2025-09-17 04:46:46 +02:00
Camille Gillot 53b91ea87f Remove Rvalue::Len. 2025-09-16 22:23:19 +00:00
Boxy e379c77586 erase_regions to erase_and_anonymize_regions 2025-09-09 14:49:16 +02:00
bors 2f3f27bf79 Auto merge of #145541 - cjgillot:dest-prop-live-range, r=Amanieu
Reimplement DestinationPropagation according to live ranges.

This PR reimplements DestinationPropagation as a problem of merging live-ranges of locals. We merge locals that have disjoint live-ranges. This allows merging several locals in the same round by updating live range information.

Live ranges are mainly computed using the `MaybeLiveLocals` analysis. The subtlety is that we split each statement and terminator in 2 positions. The first position is the regular statement. The second position is a shadow, which is always more live. It encodes partial writes and dead writes as a local being live for half a statement. This half statement ensures that writes conflict with another local's writes and regular liveness.

r? `@Amanieu`
2025-09-07 23:36:21 +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
Camille GILLOT 4e7a068c9a Introduce PlaceContext::may_observe_address. 2025-09-07 13:51:53 +00:00