Commit Graph

655 Commits

Author SHA1 Message Date
Nicholas Nethercote
0f0b9f8981 Simplify MaybeRequiresStorage
It currently contains a `MaybeBorrowedLocals` cursor. The cursor is
within a `RefCell` because cursor traversal requires mutation. The
cursor is used in the `MaybeRequiresStorage::check_for_move` operation.

Instead of using this cursor within `MaybeRequiresStorage` it's possible
to do a pre-traversal of `MaybeBorrowedLocals` to extract the necessary
information and then give that (immutably) to `MaybeRequiresStorage`.

This commit makes that change. The extracted information is in the new
`KillableLocals` type, which is computed by the `KillableLocalsVisitor`
type within `MaybeRequiresStorage::new`. `MaybeRequiresStorage` no
longer needs lifetimes. `MoveVisitor` is no longer needed. And the
complicated `locals_live_across_suspend_points` gets a little simpler.
2026-07-29 06:58:04 +10:00
Jonathan Brouwer
d30eb6534e Rollup merge of #159637 - nnethercote:Place-Analysis-tweaks, r=cjgillot
Some place analysis tweaks

Details in individual commits.

r? @cjgillot
2026-07-27 11:58:06 +02:00
Nicholas Nethercote
3fb482fdde Remove MaybeUninitializedPlaces::include_inactive_in_otherwise
It always has the same value as `mark_inactive_variants_as_uninit`, and
it's only read if `mark_inactive_variants_as_uninit` is true.
2026-07-21 15:04:18 +10:00
Nicholas Nethercote
06a0c50a7f Simplify a discriminants iteration
By using an iterator instead of a manual loop.
2026-07-21 15:03:23 +10:00
Nicholas Nethercote
205f590bf4 Clarify MoveData
- By improving various comments.
- By renaming some fields. This gives a clear split between
  `move_outs`/`move_out_loc_map`/`move_out_path_map` and
  `inits`/`init_loc_map`/`init_path_map`.
2026-07-21 11:06:40 +10:00
Nicholas Nethercote
87c8b4e271 Don't re-derive the terminator
Use the one that's passed in.
2026-07-21 11:06:40 +10:00
Nicholas Nethercote
e736635dd3 Inline and remove Direction::apply_effects_in_range
It has a single call site. The commit removes the assertions because they
necessary any more due to the assertions and checks at the call site.
This then removes the need for `index_precedes`.
2026-07-20 14:28:37 +10:00
Nicholas Nethercote
61b5db69f7 Eliminate ResultsVisitor::visit_block_entry
It's only used by `StateDiffCollector`, and it's just a complicated way
to get the entry state, which can instead be done directly (avoiding the
creation of a `bottom_value` which was immediately overwritten).
2026-07-20 14:28:32 +10:00
Nicholas Nethercote
642e9d2b47 Simplify apply_effects_in_range
This commit adds `Analysis::apply_effect`, which takes an `EffectIndex`
and calls the appropriate `Analysis::apply_*` method.

Once that is in place, it is possible to use it with `next_index` to
write a simple `apply_effects_in_range` method that can be shared
between `Forward` and `Backward`. The end result is much easier to
understand.
2026-07-20 13:42:17 +10:00
Nicholas Nethercote
f2063f9099 Avoid some IS_FORWARD tests
By adding more methods to `Direction`. This makes things more concise,
and these new methods will be used more in subsequent commits.
2026-07-20 13:42:16 +10:00
Nicholas Nethercote
17b364262b Remove ResultsVisitor::visit_block_end
`ResultsVisitor` has `visit_block_start` which is called on entry to a
a block in a forwards analysis and on exit from a block in a backwards
analysis. And vice versa for `visit_block_end`.

The only visitor that impls these methods is `StateDiffCollector`, which
does something in `visit_block_start` for a forwards analysis and the
same thing in `visit_block_end` for a backwards analysis. In other
words, `StateDiffCollector` wants to always do the same thing on entry
to a block and never do anything on exit from a block.

This commit replaces `visit_block_{start,end}` with `visit_block_entry`,
which is always called on entry to a block. This is simpler overall.
2026-07-20 13:42:16 +10:00
Jonathan Brouwer
3bb66d7229 Rollup merge of #158632 - addiesh:superfisher, r=oli-obk
First steps of late-bound turbofishing (place FnDef behind a dummy binder)

r? oli-obk

This PR is part of rust-lang/rust#156581. This should be functionally identical to prior behavior, with the added fact that FnDef now places its arguments behind a binder.

most changes boil down to
- replacing `args` from `FnDef` with `args.no_bound_vars().unwrap()`
- replacing `Ty::new_fn_def(/* ... */, args)` with `Ty::new_fn_def(/* ... */, ty::Binder::dummy(args))`
2026-07-13 20:18:00 +02:00
Jonathan Brouwer
490097dc9a Rollup merge of #157706 - jdonszelmann:deny-todo, r=wafflelapkin
Deny `todo!()` in tidy

Implements https://github.com/rust-lang/compiler-team/issues/999

Part of https://github.com/rust-lang/rust/issues/158173
2026-07-13 20:17:57 +02:00
Jana Dönszelmann
91311aecb9 Fixup all current uses of todo!() in the compiler 2026-07-13 10:47:09 +02:00
addie.sh
8fb83aba33 place FnDef behind a binder, instantiate w/ Dummy 2026-07-10 14:53:35 -04:00
Xiangfei Ding
401dc215a7 fix remapping in indexing and self-assignments
Storage is still required even if the local is moved out and
immediately moved in again.

Signed-off-by: Xiangfei Ding <dingxiangfei2009@protonmail.ch>
2026-07-06 06:46:33 +00:00
Adwin White
3dbe96a5a1 add IsRigid marker to TyKind::Alias and constants 2026-06-25 17:12:10 +08:00
Amanda Stjerna
dbf6d75478 RegionValues: disable unnecessary range check
Currently, when adding liveness points to region values
in the `RegionValues` struct, the locations of the points
are checked for ranges. This is unnecessarily cautious because
they always are in range by construction.

This adds documentation (including debug assertions) to make this
clearer and removes the checks, which should have a strictly
positive impact on performance.
2026-06-18 16:19:03 +02:00
Ben Kimock
321f54ca94 Add #![feature(loop_hints)] and #[unroll] 2026-06-11 20:32:52 -04:00
Guillaume Gomez
b679cbd70c Rename rustc_mir_dataflow/src/errors.rs into rustc_mir_dataflow/src/diagnostics.rs 2026-06-10 13:04:51 +02:00
Camille Gillot
a27155e691 Remove async_fut.
This is now unused.
2026-05-31 16:02:15 +00:00
Camille Gillot
cef7bd7064 Yield drop assigns to the resume_arg. 2026-05-30 14:25:00 +00:00
Nicholas Nethercote
bdf8d768d5 Reduce more visibilities 2026-05-27 08:53:08 +10:00
Nicholas Nethercote
33f59590d3 Remove unused functions in value_analysis.rs
And reduce visibility of functions only used within the crate.
2026-05-27 08:53:03 +10:00
bors
281c97c324 Auto merge of #156518 - estebank:match-rustfmt, r=mejrs
[style] rustfmt `match`es with comments in or-patterns

Using https://github.com/rust-lang/rustfmt/pull/6893, I reformatted the whole codebase. The result is that `match`es that *should have* been formatted under normal circumstances but are getting skipped now got their expected format. These match expressions were being entirely skipped because they contain or-patterns with comments in between patterns, causing rustfmt to bail out entirely. The or-patterns with comments themselves remain untouched, but now the match arm bodies and other patterns without comments do get formatted under that PR.

Because the fix in rustfmt isn't landed yet, I reworked some of the or-patterns with comments so that formatting doesn't regress. Tried doing this only in larger blocks that are more likely to regress in the meantime.

(Introduced and) removed a bunch of stray backticks \` likely left after an editor autoclosed the intended closing \`, resulting in <code>\`name\`\`</code> in comments.
2026-05-17 01:27:37 +00:00
bors
d7f14d3d89 Auto merge of #156218 - cjgillot:dest-prop-range, r=Amanieu
DestinationPropagation: compute liveness as ranges instead of traveling bitsets

The current implementation of `save_as_liveness` is very slow, and consists in inserting a traveling bitset in an interval set.

As the `MaybeLiveLocals` has a gen-kill property, we can leverage it to make it faster. "Gen" is creating a new interval. "Kill" is ending this interval, ripe to save in the interval set.
2026-05-15 18:05:42 +00:00
Camille Gillot
161efa96b3 DestinationPropagation: compute liveness as ranges instead of traveling bitsets. 2026-05-13 20:24:31 +00:00
cyrgani
8d2116e035 use deref_patterns in rustc_mir_dataflow 2026-05-13 19:45:13 +00:00
Esteban Küber
31e0383ea6 rustfmt matches with comments in or-patterns
Using https://github.com/rust-lang/rustfmt/pull/6893, reformat the codebase. The result is that matches that *would have* been formatted under normal circumstances get their expected format. These match expressions were being entirely skipped because they contain or-patterns with comments in between patterns, causing rustfmt to bail out entirely. The or-patterns with comments themselves remain untouched, but now the match arm bodies and other patterns without comments do get formatted under that PR.

Because the fix in rustfmt isn't landed yet, I reworked some of the or-patterns with comments so that formatting doesn't regress. Tried doing this only in larger blocks that are more likely to regress in the meantime.
2026-05-13 02:35:29 +00:00
lcnr
3fb166fb6f tiny PR 2026-05-12 21:58:50 +02:00
Matthias Krüger
02f733bb48 Rollup merge of #156169 - nnethercote:simplify-SwitchInt-stuff, r=cjgillot
Change `SwitchInt` handling in dataflow analysis.

We call `get_switch_int_data` once for the switch and then pass that data to `apply_switch_int_edge_effect` for each switch target.

The only case in practice is `MaybePlacesSwitchIntData` which does an awkward thing, maintaining an index into the discriminants and updating it on each call to `apply_switch_int_edge_effect`.

This commit changes things to do more work up front in `get_switch_int_data`, in order to then do less work in `apply_switch_int_edge_effect`. This avoids the need for the `variants` and `next_discr` methods and the discriminants index. Overall it's a little simpler.

r? @cjgillot
2026-05-10 03:17:00 +02:00
Aapo Alasuutari
2d88ee87dd Reborrow traits 2026-05-07 21:55:44 +03:00
Nicholas Nethercote
d0eab573aa Change SwitchInt handling in dataflow analysis.
We call `get_switch_int_data` once for the switch and then pass that
data to `apply_switch_int_edge_effect` for each switch target.

The only case in practice is `MaybePlacesSwitchIntData` which does an
awkward thing, maintaining an index into the discriminants and updating
it on each call to `apply_switch_int_edge_effect`.

This commit changes things to do more work up front in
`get_switch_int_data`, in order to then do less work in
`apply_switch_int_edge_effect`. This avoids the need for the `variants`
and `next_discr` methods and the discriminants index. Overall it's a
little simpler.
2026-05-05 13:02:52 +10:00
Ralf Jung
e402c1edf0 miri: remove retag statements, make typed copies retag implicitly instead 2026-05-02 17:40:33 +02:00
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