Commit Graph

2997 Commits

Author SHA1 Message Date
Camille Gillot
b198bf8060 Rebase fallout. 2025-10-11 20:56:10 +00:00
Camille Gillot
c653430714 Suggest unit struct and constants. 2025-10-11 20:50:21 +00:00
Camille GILLOT
ca0379d6cd Diagnose liveness on MIR. 2025-10-11 20:50:21 +00:00
dianqk
0ef3d203e8 Rollup merge of #147544 - cjgillot:nodeinit, r=saethlin
Remove StatementKind::Deinit.

It is a remnant from the time we deaggreated MIR.

Now, it is only constructed by the `LargeEnums` MIR pass, which is disabled by default.
2025-10-11 07:05:58 +08:00
dianqk
1ee2c58e89 Replace locals in debuginfo records during dest_prop 2025-10-10 22:06:04 +08:00
Camille Gillot
b7c2b3dc80 Remove StatementKind::Deinit. 2025-10-10 12:57:24 +00:00
dianqk
b2e81b00e5 Replace locals in debuginfo records during ref_prop 2025-10-10 18:30:53 +08:00
dianqk
9462e7301f MIR validation: ensure that debuginfo records are not emitted for locals that are not in debuginfo 2025-10-10 18:30:53 +08:00
bors
0b278a5394 Auto merge of #147483 - cjgillot:reorder-passes, r=nnethercote
Perform InstSimplify before ReferencePropagation.

`InstSimplify` clears CFG caches.

But it currently happens between `ReferencePropagation` and `GVN`, which both use dominators, a quite expensive computation.

r? `@ghost`
2025-10-09 14:05:16 +00:00
Camille Gillot
c3432bbec0 Explicit comment. 2025-10-09 11:51:17 +00:00
Stuart Cook
18d470e475 Rollup merge of #147480 - cjgillot:invalidate-ctfelimit, r=tmiasko
Do not invalidate CFG caches in CtfeLimit.

This does not matter much, as no optimization pass runs after `CtfeLimit`, but I still find the code cleaner.
2025-10-09 18:43:24 +11:00
bors
61efd19024 Auto merge of #147477 - cjgillot:split-call-guards, r=tmiasko
Refactor AddCallGuards in two loops.

This PR splits the pass into an analysis loop and a change loop. This allows to avoid invalidating CFG caches if there are no changes to be performed.

r? `@ghost` for perf
2025-10-08 23:12:38 +00:00
Camille Gillot
5702fbf03d Refactor AddCallGuards in two loops. 2025-10-08 19:44:56 +00:00
Camille Gillot
2533f78d62 Reorder passes. 2025-10-08 15:24:44 +00:00
Camille Gillot
973ddd8bc7 Do not invalidate CFG caches in CtfeLimit. 2025-10-08 15:03:43 +00:00
Camille Gillot
5da52f57c5 Evaluate constants lazily in GVN. 2025-10-08 12:23:31 +00:00
Boxy Uwu
8e9b0c4ca9 rename select_where_possible and select_all_or_error 2025-10-07 23:02:23 +01:00
bors
d773bd07d6 Auto merge of #147099 - cjgillot:split-nop-landing, r=lcnr
Refactor remove_noop_landing_pads in two loops.

The point is to avoid clearing the CFG cache as often.

r? `@ghost` for perf
2025-10-07 03:31:27 +00:00
Camille Gillot
5407eb8ca2 GVN: Support unions. 2025-10-06 19:31:40 +00:00
Camille Gillot
94b2c303aa Use traversal::postorder. 2025-10-04 17:02:08 +00:00
Camille Gillot
1ac5d4c278 Create resume block later. 2025-10-04 16:59:04 +00:00
Camille Gillot
cf341eac19 Refactor remove_noop_landing_pads in two loops. 2025-10-04 16:59:04 +00:00
Camille GILLOT
3d96e54656 Use a VnIndex in Address projection. 2025-10-04 16:36:52 +00:00
Camille GILLOT
11802781f7 Make Value Copy by arena-allocating vectors. 2025-10-04 16:36:52 +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
cc93132ae4 simplifycfg: Preserve debuginfos when merging bbs 2025-10-02 14:55:50 +08:00
dianqk
571412f819 mir-opt: Eliminate dead ref statements 2025-10-02 14:55:50 +08:00
bors
42b384ec0d Auto merge of #147055 - beepster4096:subtype_is_not_a_projection, r=lcnr
Turn ProjectionElem::Subtype into CastKind::Subtype

I noticed that drop elaboration can't, in general, handle `ProjectionElem::SubType`. It creates a disjoint move path that overlaps with other move paths. (`Subslice` does too, and I'm working on a different PR to make that special case less fragile.) If its skipped and treated as the same move path as its parent then `MovePath.place` has multiple possible projections. (It would probably make sense to remove all `Subtype` projections for the canonical place but it doesn't make sense to have this special case for a problem that doesn't actually occur in real MIR.)

The only reason this doesn't break is that `Subtype` is always the sole projection of the local its applied to. For the same reason, it works fine as a `CastKind` so I figured that makes more sense than documenting and validating this hidden invariant.

cc rust-lang/rust#112651, rust-lang/rust#133258

r? Icnr (bc you've been the main person dealing with `Subtype` it looks like)
2025-10-02 01:54:48 +00:00
Jacob Pratt
b310eb91ab Rollup merge of #146457 - alexcrichton:wasm-no-exn-instructions, r=bjorn3
Skip cleanups on unsupported targets

This commit is an update to the `AbortUnwindingCalls` MIR pass in the compiler. Specifically a new boolean is added for "can this target possibly unwind" and if that's `false` then terminators are all adjusted to be unreachable/not present. The end result is that this fixes rust-lang/rust#140293 for wasm targets.

The motivation for this PR is that currently on WebAssembly targets the usage of the `C-unwind` ABI can lead LLVM to either (a) emit exception-handling instructions or (b) hit a LLVM-ICE-style codegen error. WebAssembly as a base instruction set does not support unwinding at all, and a later proposal to WebAssembly, the exception-handling proposal, was what enabled this. This means that the current intent of WebAssembly targets is that they maintain the baseline of "don't emit exception-handling instructions unless enabled". The commit here is intended to restore this behavior by skipping these instructions even when `C-unwind` is present.

Exception-handling is a relatively tricky and also murky topic in WebAssembly, however. There are two sets of instructions LLVM can emit for WebAssembly exceptions, Rust's Emscripten target supports exceptions, WASI targets do not, the LLVM flags to enable this are not always obvious, and additionally this all touches on "changing exception-handling behavior should be a target-level concern, not a feature". Effectively WebAssembly's exception-handling integration into Rust is not finalized at this time. The best idea at this time is that a parallel set of targets will eventually be added which support exceptions, but it's not clear if/when to do this. In the meantime the goal is to keep existing targets working while still enabling experimentation with exception-handling with `-Zbuild-std` and various permutations of LLVM flags.

To that extent this commit does not blanket disable these landing pads and cleanup routines for WebAssembly but instead checks to see if panic=unwind is enabled or if `+exception-handling` is enabled. Tests are updated here as well to account for this where, by default, using a `C-unwind` ABI won't affect Rust codegen at all. If `+exception-handling` is enabled, however, then Rust codegen will look like native platforms where exceptions are caught and the program aborts. More-or-less I've done my best to keep exceptions working on wasm where it's possible to have them work, but turned them off where they're not supposed to be emitted.

Closes rust-lang/rust#140293
2025-09-29 21:37:50 -04:00
Matthias Krüger
fdb965f3f7 Rollup merge of #147131 - cjgillot:patch-branches, r=davidtwco
Use MirPatch in simplify_branches.

This allows to avoid clearing the CFG cache if we don't perform any change.

r? ``@ghost`` for perf
2025-09-29 21:42:43 +02:00
Jubilee Young
0c9d0dfe04 remove explicit deref of AbiAlign for most methods
Much of the compiler calls functions on Align projected from AbiAlign.
AbiAlign impls Deref to its inner Align, so we can simplify these away.
Also, it will minimize disruption when AbiAlign is removed.

For now, preserve usages that might resolve to PartialOrd or PartialEq,
as those have odd inference.
2025-09-28 15:02:14 -07:00
Camille Gillot
599e8db838 Use MirPatch in simplify_branches. 2025-09-28 19:52:28 +00:00
Camille Gillot
d13a5b0a6c Handle self-loops too. 2025-09-26 20:44:06 +00:00
beepster4096
aa5a21450a ProjectionElem::Subtype -> CastKind::Subtype 2025-09-26 01:25:26 -07:00
Camille Gillot
1a37374973 JumpThreading: Avoid computing dominators to identify loop headers. 2025-09-26 00:07:53 +00:00
bors
eabf390b4c Auto merge of #146697 - cjgillot:invalidate-patch, r=lcnr
Avoid invalidating CFG caches from MirPatch::apply.

Small effort to reduce invalidating CFG caches.
2025-09-25 17:19:29 +00:00
Camille Gillot
ce677c7db8 Update compiler/rustc_mir_transform/src/patch.rs
Co-authored-by: lcnr <rust@lcnr.de>
2025-09-23 20:38:38 -03:00
bors
4056082360 Auto merge of #146317 - saethlin:panic=immediate-abort, r=nnethercote
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-23 06:37:03 +00:00
Ben Kimock
888679013d Add panic=immediate-abort 2025-09-21 13:12:18 -04:00
bors
7e4b8d702f Auto merge of #146659 - cjgillot:impossible-taint, r=oli-obk
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-21 16:28:12 +00:00
Stuart Cook
5c1c47925e Rollup merge of #146744 - beepster4096:derefs_in_ref_prop, r=cjgillot
Deref related cleanups in ref_prop

Cherry picked from rust-lang/rust#146710

r? cjgillot
2025-09-21 14:42:35 +10:00
Camille Gillot
3934fc9eb2 Consider errors in MIR as impossible predicates. 2025-09-21 03:26:21 +00:00
Camille Gillot
3c232fe38f Make term_patch_map sparse. 2025-09-20 13:53:58 +00:00
bors
e10aa88911 Auto merge of #145737 - cjgillot:gvn-valueset, r=saethlin
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-19 12:15:03 +00:00
beepster4096
7ce81d1453 deref related cleanups in ref_prop 2025-09-18 19:55:40 -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
Camille Gillot
b216cf34b1 Avoid invalidating from MirPatch::apply. 2025-09-18 01:09:53 +00:00
Camille Gillot
912785d966 Lint overlapping assignments in MIR. 2025-09-17 21:12:17 +00:00
bors
ce6daf3d5a Auto merge of #142915 - cjgillot:dest-prop-default, r=saethlin
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-17 10:44:22 +00:00