Commit Graph

82 Commits

Author SHA1 Message Date
Oli Scherer ff7e604154 Stop using rustc_layout_scalar_valid_range_* in rustc 2026-03-07 15:36:56 +00: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 9415102fb4 Create place and value indices on-demand. 2025-12-14 16:33:24 +00:00
Camille Gillot 223620f3c6 Filter costly chains after simplification. 2025-11-16 01:38:16 +00:00
Camille Gillot 2a63fde0bc Simplify condition graph. 2025-11-16 01:38:16 +00:00
Camille GILLOT f59dfc1a4a Maintain a graph of fulfilled conditions. 2025-11-16 01:38:16 +00:00
Camille GILLOT acf3b6a6a6 Skip process_constant if state has no matching value. 2025-11-16 01:38:16 +00:00
Camille GILLOT f12ab2790d Do not flood if state is empty. 2025-11-16 01:38:16 +00:00
Camille GILLOT d67e3e6c5a Use a simpler condition set in jump threading. 2025-11-16 01:38:11 +00:00
dianqk 2048b9c027 GVN: Invalidate derefs at loop headers 2025-10-14 08:09:32 +08:00
bors 3be68033b6 Auto merge of #145513 - beepster4096:erasedereftemps, r=saethlin,cjgillot
Validate CopyForDeref and DerefTemps better and remove them from runtime MIR

(split from my WIP rust-lang/rust#145344)

This PR:
- Removes `Rvalue::CopyForDeref` and `LocalInfo::DerefTemp` from runtime MIR
    - Using a new mir pass `EraseDerefTemps`
    - `CopyForDeref(x)` is turned into `Use(Copy(x))`
    - `DerefTemp` is turned into `Boring`
        - Not sure if this part is actually necessary, it made more sense in rust-lang/rust#145344 with `DerefTemp` storing actual data that I wanted to keep from having to be kept in sync with the rest of the body in runtime MIR
- Checks in validation that `CopyForDeref` and `DerefTemp` are only used together
- Removes special handling for `CopyForDeref` from many places
- Removes `CopyForDeref` from `custom_mir` reverting rust-lang/rust#111587
    - In runtime MIR simple copies can be used instead
    - In post cleanup analysis MIR it was already wrong to use due to the lack of support for creating `DerefTemp` locals
    - Possibly this should be its own PR?
 - Adds an argument to `deref_finder` to avoid creating new `DerefTemp`s and `CopyForDeref` in runtime MIR.
     - Ideally we would just avoid making intermediate derefs instead of fixing it at the end of a pass / during shim building
 - Removes some usages of `deref_finder` that I found out don't actually do anything

r? oli-obk
2025-10-12 02:34:20 +00:00
Camille Gillot b7c2b3dc80 Remove StatementKind::Deinit. 2025-10-10 12:57:24 +00:00
beepster4096 fc959e5464 remove DerefTemp and CopyFromDeref from runtime mir 2025-10-06 10:57:27 -07:00
Camille Gillot d13a5b0a6c Handle self-loops too. 2025-09-26 20:44:06 +00:00
Camille Gillot 1a37374973 JumpThreading: Avoid computing dominators to identify loop headers. 2025-09-26 00:07:53 +00:00
Stypox 708dc15cf1 Add InterpCx::layout_of with tracing, shadowing LayoutOf 2025-06-27 11:49:22 +02:00
Camille GILLOT 89b079d844 Only traverse reachable blocks in JumpThreading. 2025-06-15 21:12:17 +00:00
Scott McMurray 8bce2255e8 Update InterpCx::project_field to take FieldIdx
As suggested by Ralf in 142005.
2025-06-05 19:15:56 -07:00
bors d7df5bdf29 Auto merge of #140464 - oli-obk:successors-mut-perf, r=petrochenkov
Use a closure instead of three chained iterators

Fixes the perf regression from #123948

That PR had chained a third option to the iterator which apparently didn't optimize well
2025-05-03 10:43:38 +00:00
bors 0fbb922e53 Auto merge of #140023 - cjgillot:arena-try-alloc, r=BoxyUwU
Introduce Arena::try_alloc_from_iter.

`alloc_from_iter` already collects the iterator for reentrancy. So adding an early exit for a fallible iterator integrates naturally into the code. This avoids the other solution to allocate and dump the allocation.
2025-04-29 21:06:15 +00:00
Oli Scherer 9193dfe435 Use a closure instead of three chained iterators 2025-04-29 14:58:21 +00:00
Camille GILLOT d0d3021bf8 Introduce Arena::try_alloc_from_iter. 2025-04-19 01:13:18 +00:00
Camille GILLOT bd5c43835a Remove early exits from JumpThreading. 2025-04-18 23:34:37 +00:00
clubby789 41a5d8ef3d JumpThreading: Bail out on interp errors 2025-04-13 20:29:51 +00:00
clubby789 9f35fe47c7 JumpThreading: Re-enable and fix Not ops on non-booleans 2025-04-13 20:29:49 +00:00
Michael Goulet 12e3911d81 Greatly simplify lifetime captures in edition 2024 2025-02-22 22:24:52 +00:00
Michael Goulet 3d5438accd Fix binding mode problems 2025-02-22 00:13:19 +00:00
clubby789 7a9661d768 Disable non-required MIR opts with optimize(none)
Co-authored-by: Waffle Lapkin <waffle.lapkin@gmail.com>
2025-01-23 17:40:41 +00:00
Rémy Rakic a13354bea0 rename BitSet to DenseBitSet
This should make it clearer that this bitset is dense, with the
advantages and disadvantages that it entails.
2025-01-11 11:34:01 +00:00
Ralf Jung 21de42bf8d Variants::Single: do not use invalid VariantIdx for uninhabited enums 2024-12-18 11:00:21 +01:00
Ding Xiang Fei 297b618944 reduce false positives of tail-expr-drop-order from consumed values
take 2

open up coroutines

tweak the wordings

the lint works up until 2021

We were missing one case, for ADTs, which was
causing `Result` to yield incorrect results.

only include field spans with significant types

deduplicate and eliminate field spans

switch to emit spans to impl Drops

Co-authored-by: Niko Matsakis <nikomat@amazon.com>

collect drops instead of taking liveness diff

apply some suggestions and add explantory notes

small fix on the cache

let the query recurse through coroutine

new suggestion format with extracted variable name

fine-tune the drop span and messages

bugfix on runtime borrows

tweak message wording

filter out ecosystem types earlier

apply suggestions

clippy

check lint level at session level

further restrict applicability of the lint

translate bid into nop for stable mir

detect cycle in type structure
2024-11-20 20:53:11 +08:00
lcnr 7a90e84f4d InterpCx store TypingEnv instead of a ParamEnv 2024-11-19 21:36:23 +01:00
lcnr 9cba14b95b use TypingEnv when no infcx is available
the behavior of the type system not only depends on the current
assumptions, but also the currentnphase of the compiler. This is
mostly necessary as we need to decide whether and how to reveal
opaque types. We track this via the `TypingMode`.
2024-11-18 10:38:56 +01:00
Jubilee Young 843b6e0859 compiler: Directly use rustc_abi in mir_transform 2024-11-03 13:38:47 -08:00
Michael Goulet f0bfba2583 Disable jump threading UnOp::Not for non-bool 2024-10-03 15:37:31 -04:00
Ralf Jung c4ce8c114b make InterpResult a dedicated type to avoid accidentally discarding the error 2024-10-01 21:45:35 +02:00
Ralf Jung 4b8a5bd511 panic when an interpreter error gets unintentionally discarded 2024-09-30 08:37:00 +02:00
Ralf Jung 921a5ef6d7 try to get rid of mir::Const::normalize 2024-09-28 21:15:18 +02:00
Michael Goulet c682aa162b Reformat using the new identifier sorting from rustfmt 2024-09-22 19:11:29 -04:00
Nicholas Nethercote 8d32578fe1 Rename and reorder lots of lifetimes.
- Replace non-standard names like 's, 'p, 'rg, 'ck, 'parent, 'this, and
  'me with vanilla 'a. These are cases where the original name isn't
  really any more informative than 'a.
- Replace names like 'cx, 'mir, and 'body with vanilla 'a when the lifetime
  applies to multiple fields and so the original lifetime name isn't
  really accurate.
- Put 'tcx last in lifetime lists, and 'a before 'b.
2024-09-13 15:46:20 +10:00
Nicholas Nethercote 7023402691 Remove references from some structs.
In all cases the struct can own the relevant thing instead of having a
reference to it. This makes the code simpler, and in some cases removes
a struct lifetime.
2024-09-10 09:11:17 +10:00
Nicholas Nethercote 6af470e360 Reduce visibilities, and add warn(unreachable_pub).
Lots of unnecessary `pub`s in this crate. Most are downgraded to
`pub(super)`, though some don't need any visibility.
2024-09-09 08:48:09 +10:00
Nicholas Nethercote 2aae619edb Move MirPass to rustc_mir_transform.
Because that's now the only crate that uses it.

Moving stuff out of `rustc_middle` is always welcome.

I chose to use `impl crate::MirPass`/`impl crate::MirLint` (with
explicit `crate::`) everywhere because that's the only mention of
`MirPass`/`MirLint` used in all of these files. (Prior to this change,
`MirPass` was mostly imported via `use rustc_middle::mir::*` items.)
2024-09-03 16:03:46 +10:00
Matthias Krüger 7d025bb63d Rollup merge of #129767 - nnethercote:rm-extern-crate-tracing-4, r=jieyouxu
Remove `#[macro_use] extern crate tracing`, round 4

Because explicit importing of macros via use items is nicer (more standard and readable) than implicit importing via #[macro_use]. Continuing the work from #124511, #124914, and #125434. After this PR no `rustc_*` crates use `#[macro_use] extern crate tracing` except for `rustc_codegen_gcc` which is a special case and I will do separately.

r? ```@jieyouxu```
2024-08-31 14:46:11 +02:00
Nicholas Nethercote ed5161c5ac Remove #[macro_use] extern crate tracing from rustc_mir_transform. 2024-08-30 10:01:34 +10:00
Nicholas Nethercote fa4f8925f1 Remove Option<!> return types.
Several compiler functions have `Option<!>` for their return type.
That's odd. The only valid return value is `None`, so why is this type
used?

Because it lets you write certain patterns slightly more concisely. E.g.
if you have these common patterns:
```
    let Some(a) = f() else { return };
    let Ok(b) = g() else { return };
```
you can shorten them to these:
```
    let a = f()?;
    let b = g().ok()?;
```
Huh.

An `Option` return type typically designates success/failure. How should
I interpret the type signature of a function that always returns (i.e.
doesn't panic), does useful work (modifying `&mut` arguments), and yet
only ever fails? This idiom subverts the type system for a cute
syntactic trick.

Furthermore, returning `Option<!>` from a function F makes things
syntactically more convenient within F, but makes things worse at F's
callsites. The callsites can themselves use `?` with F but should not,
because they will get an unconditional early return, which is almost
certainly not desirable. Instead the return value should be ignored.
(Note that some of callsites of `process_operand`, `process_immedate`,
`process_assign` actually do use `?`, though the early return doesn't
matter in these cases because nothing of significance comes after those
calls. Ugh.)

When I first saw this pattern I had no idea how to interpret it, and it
took me several minutes of close reading to understand everything I've
written above. I even started a Zulip thread about it to make sure I
understood it properly. "Save a few characters by introducing types so
weird that compiler devs have to discuss it on Zulip" feels like a bad
trade-off to me. This commit replaces all the `Option<!>` return values
and uses `else`/`return` (or something similar) to replace the relevant
`?` uses. The result is slightly more verbose but much easier to
understand.
2024-08-30 08:18:41 +10:00
Nilstrieb f305e18804 Disable jump threading of float equality
Jump threading stores values as `u128` (`ScalarInt`) and does its
comparisons for equality as integer comparisons.
This works great for integers. Sadly, not everything is an integer.

Floats famously have wonky equality semantcs, with `NaN!=NaN` and
`0.0 == -0.0`. This does not match our beautiful integer bitpattern
equality and therefore causes things to go horribly wrong.

While jump threading could be extended to support floats by remembering
that they're floats in the value state and handling them properly,
it's signficantly easier to just disable it for now.
2024-07-27 15:11:59 +02:00
Camille GILLOT 76f5bc6a9f Create mapped places upon seeing them in the body. 2024-07-13 11:54:25 +00:00
Maybe Waffle 484152d562 Support tail calls in mir via TerminatorKind::TailCall 2024-07-07 17:11:04 +02:00