Commit Graph

677 Commits

Author SHA1 Message Date
Tim (Theemathas Chirananthavat)
6ce7842daf Remove MutatingUseContext::Retag
This variant was never constructed anywhere.
2026-08-12 17:48:07 +07:00
Jonathan Brouwer
18d4e3e6f7 Rollup merge of #160833 - nnethercote:rm-analysis-arg-from-visitors, r=cjgillot
Remove `analysis` arg from `ResultsVisitor` methods

It's not needed: if a visitor needs access to the analysis it can just hold a reference itself. Details in individual commits.

r? @cjgillot
2026-08-10 13:45:42 +02:00
Nicholas Nethercote
234b3544e3 Remove analysis arg from ResultsVisitor methods
It's no longer needed.
2026-08-10 15:45:55 +10:00
Nicholas Nethercote
3ef076c33e Store the analysis in StateDiffCollector
It's easy and enables a simplification in the next commit.
2026-08-10 15:44:59 +10:00
Chris Denton
4641990929 Remove ensure_sufficient_stack 2026-08-09 19:58:29 +00:00
Nicholas Nethercote
a7b542a64b Remove unnecessary & sigils 2026-08-07 08:31:38 +10:00
Nicholas Nethercote
d7a07f0345 Remove unused derives on DefUse 2026-08-07 08:31:38 +10:00
Nicholas Nethercote
d1689e22cf Fix a typo 2026-08-07 08:31:38 +10:00
Nicholas Nethercote
0ae7d22265 Remove an unnecessary lifetime 2026-08-07 08:31:38 +10:00
Nicholas Nethercote
7e95965ac1 Remove MaybeLiveLocals::transfer_function
It has only two uses, and it's just a synonym for
`LivenessTransferFunction`, which has more uses.
2026-08-07 08:31:37 +10:00
Nicholas Nethercote
530c82cb96 Rename TransferFunction
As `LivenessTransferFunction`. This avoids renaming it via a `use` item,
which makes things clearer.
2026-08-07 08:31:35 +10:00
Nicholas Nethercote
b829f17aa8 Simplify MaybeTransitiveLiveLocals
It's mostly identical to `MaybeLiveLocals`, and we can delegate most of
its operations to `MaybeLiveLocals`.

Note that there was a tiny difference between
`MaybeLiveLocals::apply_call_return_effect` and
`MaybeTransitiveLiveLocals::apply_call_return_effect`: the former uses
`state.kill(local)`, the latter used `state.remove(local)`. The two are
equivalent so the difference didn't matter, but it does demonstrate the
dangers of the code duplication.
2026-08-07 08:31:06 +10:00
Jonathan Brouwer
84127afd41 Rollup merge of #160555 - nnethercote:split-apply_terminator, r=cjgillot
Split `apply_primary_terminator_effect`

It currently does two distinct things, and it's a bit nicer it they are separated. Details in individual commits.

r? @cjgillot
2026-08-06 12:41:03 +02:00
Nicholas Nethercote
6377970b4c Split apply_primary_terminator_effect
This method currently does two things: it applies the effect, and also
computes the edges. However:
- Three of the four call sites don't use the edges.
- Most analyses just return `terminator.edges()` unconditionally.

This commit separates the edge computation into a new method,
`get_terminator_edges()`. It defaults to `terminator.edges()`, which
means that most analyses don't need to define it. And now edges are only
obtained when they are needed (in `Forward::apply_effects_in_block`).
2026-08-05 15:27:54 +10:00
Nicholas Nethercote
b7918718e6 Remove visit_reachable_results
It only has one call site; might as well just use `visit_results`.

Also, clarify that the blocks passed to `visit_results` must be
reachable; this is something I didn't realize, probably because the name
`visit_reachable_results` made `visit_results` sound like its blocks
*don't* need to be reachable.
2026-08-05 12:40:37 +10:00
Nicholas Nethercote
812c7a7397 Only visit reachable blocks in MaybeRequiresStorage::new
Currently it visits all blocks, which could trigger the debug_assert in
`seek_to_block_entry`.
2026-08-05 12:40:37 +10:00
Nicholas Nethercote
3a7e145ffc Fix "first assignment" labels for EverInitializedPlaces
This commit fixes the error message regression in the previous commit by
recomputing flow information at error-reporting time.
`is_local_ever_initialized` is replaced in two ways.
- In `check_access_permissions`: by the new `first_reaching_init`
  function which picks the first init that can reach the error location
  along a path that doesn't cross `StorageDead(local)`.
- In `add_used_mut`: by a simple `contains` test.
2026-08-03 12:02:02 +10:00
Nicholas Nethercote
d2d234bcfa Simplify domain of EverInitializedPlaces
Currently it tracks a bit for every `Init`, but it only uses the tracked
data for locals. This means it is tracking data for projections that is
unused.

This commit shrinks the domain to only track data for `Local`s, going
from `MixedBitSet<InitIndex>` to `DenseBitSet<Local>`.

This does regress the error messages in one test:
liveness-assign-imm-local-notes.rs. The next commit will fix that.

The commit also removes some `debug` statements which probably haven't
seen use in a long time. They can be re-added easily if anyone needs
them in the future.
2026-08-03 11:41:03 +10:00
bors
c47bb2f396 Auto merge of #160245 - xmakro:perf/location-map-single-alloc, r=nnethercote
perf: Avoid a heap allocation per basic block in MoveData's location maps

`MoveData` holds two `LocationMap`s, and each was an `IndexVec<BasicBlock, Vec<T>>` that heap-allocated one `Vec` per basic block. Building the move data for a body allocated a small vector for every block, twice over. Store the entries in one flat buffer indexed by a per-block start offset, so each map is two allocations regardless of block count.
2026-08-01 08:02:30 +00:00
bors
cb9d1b0640 Auto merge of #160193 - nnethercote:improve-cfg-traversal, r=cjgillot
Improve CFG traversal

This PR implements a new CFG traversal algorithm in `iterate_to_fixpoint` that drastically speeds up a pathological case in `cranelift-codegen`.

r? @cjgillot
2026-08-01 01:28:09 +00:00
Makro
b146323d4d perf: Avoid a heap allocation per basic block in MoveData's location maps 2026-07-31 11:45:46 +00:00
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
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