about summary refs log tree commit diff
path: root/compiler/rustc_mir_transform
AgeCommit message (Collapse)AuthorLines
2025-09-26Handle self-loops too.Camille Gillot-3/+5
2025-09-26JumpThreading: Avoid computing dominators to identify loop headers.Camille Gillot-17/+23
2025-09-25Auto merge of #146697 - cjgillot:invalidate-patch, r=lcnrbors-15/+21
Avoid invalidating CFG caches from MirPatch::apply. Small effort to reduce invalidating CFG caches.
2025-09-23Update compiler/rustc_mir_transform/src/patch.rsCamille Gillot-0/+2
Co-authored-by: lcnr <rust@lcnr.de>
2025-09-23Auto merge of #146317 - saethlin:panic=immediate-abort, r=nnethercotebors-7/+8
Add panic=immediate-abort MCP: https://github.com/rust-lang/compiler-team/issues/909 This adds a new panic strategy, `-Cpanic=immediate-abort`. This panic strategy essentially just codifies use of `-Zbuild-std-features=panic_immediate_abort`. This PR is intended to just set up infrastructure, and while it will change how the compiler is invoked for users of the feature, there should be no other impacts. In many parts of the compiler, `PanicStrategy::ImmediateAbort` behaves just like `PanicStrategy::Abort`, because actually most parts of the compiler just mean to ask "can this unwind?" so I've added a helper function so we can say `sess.panic_strategy().unwinds()`. The panic and unwind strategies have some level of compatibility, which mostly means that we can pre-compile the sysroot with unwinding panics then the sysroot can be linked with aborting panics later. The immediate-abort strategy is all-or-nothing, enforced by `compiler/rustc_metadata/src/dependency_format.rs` and this is tested for in `tests/ui/panic-runtime/`. We could _technically_ be more compatible with the other panic strategies, but immediately-aborting panics primarily exist for users who want to eliminate all the code size responsible for the panic runtime. I'm open to other use cases if people want to present them, but not right now. This PR is already large. `-Cpanic=immediate-abort` sets both `cfg(panic = "immediate-abort")` _and_ `cfg(panic = "abort")`. bjorn3 pointed out that people may be checking for the abort cfg to ask if panics will unwind, and also the sysroot feature this is replacing used to require `-Cpanic=abort` so this seems like a good back-compat step. At least for the moment. Unclear if this is a good idea indefinitely. I can imagine this being confusing. The changes to the standard library attributes are purely mechanical. Apart from that, I removed an `unsafe` we haven't needed for a while since the `abort` intrinsic became safe, and I've added a helpful diagnostic for people trying to use the old feature. To test that `-Cpanic=immediate-abort` conflicts with other panic strategies, I've beefed up the core-stubs infrastructure a bit. There is now a separate attribute to set flags on it. I've added a test that this produces the desired codegen, called `tests/run-make-cargo/panic-immediate-abort-codegen/` and also a separate run-make-cargo test that checks that we can build a binary.
2025-09-21Add panic=immediate-abortBen Kimock-7/+8
2025-09-21Auto merge of #146659 - cjgillot:impossible-taint, r=oli-obkbors-13/+20
Consider errors in MIR as impossible predicates to empty the body. The ICEs come from elaborating drops or performing state transform in MIR bodies that fail typeck or borrowck. If the body is tainted, replace it with `unreachable`. Fixes https://github.com/rust-lang/rust/issues/122630 Fixes https://github.com/rust-lang/rust/issues/122904 Fixes https://github.com/rust-lang/rust/issues/125185 Fixes https://github.com/rust-lang/rust/issues/139556
2025-09-21Rollup merge of #146744 - beepster4096:derefs_in_ref_prop, r=cjgillotStuart Cook-20/+13
Deref related cleanups in ref_prop Cherry picked from rust-lang/rust#146710 r? cjgillot
2025-09-21Consider errors in MIR as impossible predicates.Camille Gillot-13/+20
2025-09-20Make term_patch_map sparse.Camille Gillot-14/+18
2025-09-19Auto merge of #145737 - cjgillot:gvn-valueset, r=saethlinbors-44/+179
GVN: stop hashing opaque values GVN generates values that are not meant to be unified with any other. For instance `Opaque` (aka we don't know anything), non-deterministic constants and borrows. The current algorithm generates a unique index, so the generated `Value` will be different from all the existing. This is wasteful, as we should not hash that `Value` at all. This PR proposes to do this. This involves partially reimplementing a `FxIndexSet`, but yields a small but consistent perf improvement (https://github.com/rust-lang/rust/pull/145737#issuecomment-3276951054).
2025-09-18deref related cleanups in ref_propbeepster4096-20/+13
2025-09-18Rollup merge of #146664 - fmease:clean-up-dyn, r=jdonszelmannStuart Cook-1/+1
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-18Avoid invalidating from MirPatch::apply.Camille Gillot-3/+3
2025-09-17Lint overlapping assignments in MIR.Camille Gillot-27/+35
2025-09-17Auto merge of #142915 - cjgillot:dest-prop-default, r=saethlinbors-246/+2
Enable DestinationPropagation by default This PR proposes to perform destination propagation on MIR. Most of the pass was fully rewritten by `@JakobDegen` in rust-lang/rust#96451. This pass is quite heavy, as it needs to perform and save the results of a full liveness dataflow analysis. This accounts for ~50% of the pass' runtime. Perf sees a few decent savings in later llvm passes, but also sizeable régressions when there are no savings to balance this pass' runtime.
2025-09-17Rollup merge of #146564 - cjgillot:mir-nolen, r=scottmcmStuart Cook-102/+40
Remove Rvalue::Len again. Now that we have `RawPtrKind::FakeForPtrMetadata`, we can reimplement `Rvalue::Len` using `PtrMetadata(&raw const (fake) place)`. r? ``@scottmcm``
2025-09-17Remove `DynKind`León Orell Valerian Liehr-1/+1
2025-09-16Do not renumber resume local.Camille Gillot-27/+20
2025-09-16Remove Rvalue::Len.Camille Gillot-102/+40
2025-09-16Enable DestinationPropagation by default.Camille GILLOT-246/+2
2025-09-16Restrict simple assignment condition.Camille Gillot-2/+8
2025-09-14Elaborate comment.Camille Gillot-2/+6
2025-09-14Comment.Camille Gillot-0/+9
2025-09-13Mark reads in statements to avoid overlapping assingments.Camille Gillot-10/+19
2025-09-13Stop counting opaques.Camille Gillot-25/+24
2025-09-13Do not hash opaques in GVN.Camille Gillot-39/+90
2025-09-13Introduce ValueSet.Camille Gillot-21/+97
2025-09-09Auto merge of #145717 - BoxyUwU:erase_regions_rename, r=lcnrbors-3/+4
rename erase_regions to erase_and_anonymize_regions I find it consistently confusing that `erase_regions` does more than replacing regions with `'erased`. it also makes some code look real goofy to be writing manual folders to erase regions with a comment saying "we cant use erase regions" :> or code that re-calls erase_regions on types with regions already erased just to anonymize all the bound regions. r? lcnr idk how i feel about the name being almost twice as long now
2025-09-09erase_regions to erase_and_anonymize_regionsBoxy-3/+4
2025-09-08fixup limit handling codeJana Dönszelmann-1/+1
2025-09-08Rollup merge of #146298 - cjgillot:gvn-derefer, r=nnethercoteMatthias Krüger-0/+5
GVN: Ensure indirect is first projection in try_as_place. I haven't found any report for this bug on existing code, but managed to trigger it with rust-lang/rust#143333
2025-09-08Auto merge of #145910 - saethlin:ignore-intrinsic-calls, r=cjgillotbors-1/+10
Ignore intrinsic calls in cross-crate-inlining cost model I noticed in a side project that a function which just compares to `[u64; 2]` for equality is not cross-crate-inlinable. That was surprising to me because I didn't think that code contained a function call, but of course our array comparisons are lowered to an intrinsic. Intrinsic calls don't make a function no longer a leaf, so it makes sense to add this as an exception to the "only leaves" cross-crate-inline heuristic. This is the useful compare link: https://perf.rust-lang.org/compare.html?start=7cb1a81145a739c4fd858abe3c624ce8e6e5f9cd&end=c3f0a64dbf9fba4722dacf8e39d2fe00069c995e&stat=instructions%3Au because it disables CGU merging in both commits, so effects that cause changes in the sysroot to perturb partitioning downstream are excluded. Perturbations to what is and isn't cross-crate-inlinable in the sysroot has chaotic effects on what items are in which CGUs after merging. It looks like before this PR by sheer luck some of the CGUs dirtied by the patch in eza incr-unchanged happened to be merged together, and with this PR they are not. The perf runs on this PR point to a nice runtime performance improvement.
2025-09-07Auto merge of #145541 - cjgillot:dest-prop-live-range, r=Amanieubors-502/+292
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-07Rollup merge of #146297 - cjgillot:may-observe-address, r=saethlinMatthias Krüger-1/+3
Introduce PlaceContext::may_observe_address. A small utility method to avoid open-coding the logic in several MIR opts.
2025-09-07Use rustc_data_structures::union_find.Camille Gillot-28/+14
2025-09-07Simplify candidate collection.Camille Gillot-55/+43
2025-09-07Unify a source with all possible destinations.Camille Gillot-59/+39
2025-09-07Do not use prepend to avoid quadratic behaviour.Camille Gillot-23/+28
2025-09-07Simplify VisitPlacesWith.Camille Gillot-18/+7
2025-09-07Use regular MaybeLiveLocals.Camille Gillot-133/+48
2025-09-07Reimplement DestinationPropagation according to live ranges.Camille GILLOT-458/+385
2025-09-07Auto merge of #146289 - cjgillot:gvn-aggregate, r=dianqkbors-28/+17
GVN: Allow reusing aggregates if LHS is not a simple local. This resolves a FIXME in the code. I don't see a reason not to allow this.
2025-09-07Ensure indirect is first projection in try_as_place.Camille GILLOT-0/+5
2025-09-07Introduce PlaceContext::may_observe_address.Camille GILLOT-1/+3
2025-09-07Rollup merge of #146254 - yotamofek:pr/itertools-all-equal-value, r=cjgillotMatthias Krüger-22/+18
Use `Itertools::all_equal_value()` where applicable Just a small cleanup. We already have `itertools` as a dep in these crates, so might as well use another of its features. Makes the code simpler IMHO :)
2025-09-07Allow simplifying aggregates if LHS is not a simple local.Camille GILLOT-28/+17
2025-09-05Ignore intrinsic calls in cross-crate-inlining cost modelBen Kimock-1/+10
2025-09-05Use `Itertools::all_equal_value()` where applicableYotam Ofek-22/+18
2025-09-05remove couple of clonesMatthias Krüger-1/+1