Commit graph

3181 commits

Author SHA1 Message Date
Nicholas Nethercote
3aa31788b5 Remove Deref/DerefMut impl for Providers.
It's described as a "backwards compatibility hack to keep the diff
small". Removing it requires only a modest amount of churn, and the
resulting code is clearer without the invisible derefs.
2026-01-14 15:55:59 +11:00
Josh Stone
348bfe3e35 compiler: upgrade to hashbrown 0.16.1
See also #135634, #149159, and rust-lang/hashbrown#662.

This includes an in-tree upgrade of `indexmap` as well, which uses the
new `HashTable` buckets API internally, hopefully impacting performance
for the better!
2026-01-13 11:18:09 -08:00
Jonathan Brouwer
a2994063d4
Rollup merge of #150943 - port_must_not_suspend, r=jdonszelmann,JonathanBrouwer
Port `#[must_not_suspend]` to attribute parser

Tracking issue: rust-lang/rust#131229

r? @JonathanBrouwer
2026-01-13 09:01:31 +01:00
Edvin Bryntesson
418cff3ec0
Port #[must_not_suspend] to attribute parser 2026-01-12 18:16:37 +01:00
dianqk
3b1756fbf5
Run SimplifyComparisonIntegral with opt-level 2 2026-01-12 18:16:39 +08:00
dianqk
37f83fb11d
Use Copy in the SwitchInt terminator
Move can be used only when both the compared operand and the operand on switch are move operands.
This commit directly changes to Copy, because I don't know if Move has beneficial.
2026-01-12 18:16:39 +08:00
dianqk
ac80ccec5f
Only use SSA locals in SimplifyComparisonIntegral 2026-01-12 18:16:34 +08:00
yukang
ea93fb548c Underscore-prefixed bindings are explicitly allowed to be unused 2026-01-11 16:32:19 +08:00
Zalathar
539e855008 Use a hook to decouple rustc_mir_transform from rustc_mir_build 2026-01-10 22:14:35 +11:00
dianqk
e9a67c7472
Propagates assume 2026-01-08 22:31:15 +08:00
dianqk
0051e31f6f
New MIR Pass: SsaRangePropagation 2026-01-08 22:31:13 +08:00
Jamie Cunliffe
2afe5b1a83 Fix ICE in inline always warning emission.
The calls to `def_path_str` were outside the decorate callback in
`node_span_lint` which caused an ICE when the warning was an allowed
warning due to the call to `def_path_str` being executed but the
warning not actually being emitted.
2026-01-08 11:59:41 +00:00
Ben Kimock
74e0a9aa81 Make inliner cycle detection a fallible process 2025-12-30 22:01:49 -05: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
bors
000ccd651d Auto merge of #148766 - cjgillot:mir-const-runtime-checks, r=RalfJung,saethlin
Replace Rvalue::NullaryOp by a variant in mir::Operand.

Based on https://github.com/rust-lang/rust/pull/148151

This PR fully removes the MIR `Rvalue::NullaryOp`. After rust-lang/rust#148151, it was only useful for runtime checks like `ub_checks`, `contract_checks` and `overflow_checks`.

These are "runtime" checks, boolean constants that may only be `true` in codegen. It depends on a rustc flag passed to codegen, so we need to represent those flags cross-crate.

This PR replaces those runtime checks by special variants in MIR `ConstValue`. This allows code that expects constants to manipulate those as such, even if we may not always be able to evaluate them to actual scalars.
2025-12-22 06:58:28 +00:00
dianqk
37af3f647b
GVN: Adds the insert_unique method 2025-12-21 21:32:06 +08:00
Camille Gillot
c67b99fa09 Reinstate bonus for unused UbChecks. 2025-12-21 00:58:00 +00:00
Ben Kimock
4ff2c5c9f5 Don't treat asserts as a call in cross-crate inlining 2025-12-18 19:12:09 -05:00
David Wood
4185e9f2ec
mir_transform: prohibit scalable vectors in async
Scalable vectors cannot be members of ADTs and thus cannot be kept over
await points in async functions.
2025-12-16 11:00:12 +00:00
David Wood
a56b1b9283
codegen: implement repr(scalable)
Introduces `BackendRepr::ScalableVector` corresponding to scalable
vector types annotated with `repr(scalable)` which lowers to a scalable
vector type in LLVM.

Co-authored-by: Jamie Cunliffe <Jamie.Cunliffe@arm.com>
2025-12-16 11:00:12 +00:00
Camille Gillot
8759e5a8c6 Update doc. 2025-12-14 17:30:07 +00:00
Camille Gillot
6319bee585 Introduce Operand::RuntimeChecks. 2025-12-14 17:25:53 +00:00
Camille Gillot
1a227bd47f Replace Rvalue::NullaryOp by a variant in mir::ConstValue. 2025-12-14 17:25:51 +00:00
Camille GILLOT
9415102fb4 Create place and value indices on-demand. 2025-12-14 16:33:24 +00:00
Esteban Küber
146711fc24 Use let...else instead of match foo { ... _ => return }; and if let ... else return 2025-12-12 17:52:39 +00:00
bors
1c5a0cfc13 Auto merge of #149657 - Kobzol:revert-149147, r=chenyukang
Revert "Rollup merge of #149147 - chenyukang:yukang-fix-unused_assignments-macro-gen-147648, r=JonathanBrouwer"

This reverts commit 82a17b30d8, reversing
changes made to 5019bdaefe.

Reverts https://github.com/rust-lang/rust/pull/149147 due to a [perf regression](https://github.com/rust-lang/rust/pull/149147#issuecomment-3613098314).
2025-12-07 07:23:22 +00:00
bors
ba86c0460b Auto merge of #149704 - matthiaskrgr:rollup-u4zhw99, r=matthiaskrgr
Rollup of 5 pull requests

Successful merges:

 - rust-lang/rust#146826 (Implement `Allocator` for `&mut A` where `A: Allocator + ?Sized`)
 - rust-lang/rust#148487 (add Option::into_flat_iter)
 - rust-lang/rust#148814 (stabilize `array_windows`)
 - rust-lang/rust#149401 (Fix `name()` functions for local defs in rustc_public)
 - rust-lang/rust#149683 (Fix armv8r-none-eabihf tier)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-12-06 12:25:12 +00:00
Matthias Krüger
8a6f82efac
Rollup merge of #148814 - bend-n:stabilize_array_windows, r=scottmcm
stabilize `array_windows`

Tracking issue: rust-lang/rust#75027
Closes: rust-lang/rust#75027
FCP completed: https://github.com/rust-lang/rust/issues/75027#issuecomment-3477510526
2025-12-06 09:57:59 +01:00
Jacob Pratt
e5f552a02b
Rollup merge of #149592 - oli-obk:no_is_const_default_method_fn, r=fee1-dead
`is_const_default_method` is completely handled by the `constness` query

After  rust-lang/rust#149444 this function became obsolete

r? `@fee1-dead`
2025-12-05 23:26:37 -05:00
bors
97b131c900 Auto merge of #148602 - BoxyUwU:coercion_cleanup_uncontroversial, r=lcnr
misc coercion cleanups and handle safety correctly

r? lcnr

### "remove normalize call"

Fixes rust-lang/rust#132765

If the normalization fails we would sometimes get a `TypeError` containing inference variables created inside of the probe used by coercion. These would then get leaked out causing ICEs in diagnostics logic

### "leak check and lub for closure<->closure coerce-lubs of same defids"

Fixes https://github.com/rust-lang/trait-system-refactor-initiative/issues/233
```rust
fn peculiar() -> impl Fn(u8) -> u8 {
    return |x| x + 1
}
```
the `|x| x + 1` expr has a type of `Closure(?31t)` which we wind up inferring the RPIT to. The `CoerceMany` `ret_coercion` for the whole `peculiar` typeck has an expected type of `RPIT` (unnormalized). When we type check the `return |x| x + 1` expr we go from the never type to `Closure(?31t)` which then participates in the `ret_coercion` giving us a `coerce-lub(RPIT, Closure(?31t))`.

Normalizing `RPIT` gives us some `Closure(?50t)` where `?31t` and `?50t` have been unified with `?31t` as the root var. `resolve_vars_if_possible` doesn't resolve infer vars to their roots so these wind up with different structural identities so the fast path doesn't apply and we fall back to coercing to a `fn` ptr. cc rust-lang/rust#147193 which also fixes this

New solver probably just gets more inference variables here because canonicalization + generally different approach to normalization of opaques. Idk :3

### FCP worthy stuffy

there are some other FCP worthy things but they're in my FCP comment which also contains some analysis of the breaking nature of the previously listed changes in this PR: https://github.com/rust-lang/rust/pull/148602#issuecomment-3503497467
2025-12-05 11:46:41 +00:00
Jakub Beránek
74387157c7
Revert "Rollup merge of #149147 - chenyukang:yukang-fix-unused_assignments-macro-gen-147648, r=JonathanBrouwer"
This reverts commit 82a17b30d8, reversing
changes made to 5019bdaefe.
2025-12-04 21:17:40 +01:00
Matthias Krüger
82a17b30d8
Rollup merge of #149147 - chenyukang:yukang-fix-unused_assignments-macro-gen-147648, r=JonathanBrouwer
Fix unused_assignments false positives from macros

Fixes rust-lang/rust#147648
2025-12-04 08:46:18 +01:00
Boxy Uwu
76bd21ad66 account for safe target features in fndef<->closure and fndef<->fndef coerce-lubs 2025-12-03 14:55:41 +00:00
Oli Scherer
0ab78c1523 is_const_default_method is completely handled by the constness query 2025-12-03 12:38:24 +00:00
bors
4ad239f415 Auto merge of #142821 - cjgillot:jump-threading-single, r=saethlin
Compute jump threading opportunities in a single pass

The current implementation of jump threading walks MIR CFG backwards from each `SwitchInt` terminator. This PR replaces this by a single postorder traversal of MIR. In theory, we could do a full fixpoint dataflow analysis, but this has low returns as we forbid threading through a loop header.

The second commit in this PR modifies the carried state to a lighter data structure. The current implementation uses some kind of `IndexVec<ValueIndex, &[Condition]>`. This is needlessly heavy, as the state rarely ever carries more than a few `Condition`s. The first commit replaces this state with a simpler `&[Condition]`, and puts the corresponding `ValueIndex` inside `Condition`.

The three later commits are perf tweaks.

The sixth commit is the main change. Instead of carrying the goto target inside the condition, we maintain a set of conditions associated with each block, and their consequences in following blocks. Think: if this condition is fulfilled in this block, then that condition is fulfilled in that block. This makes the threading algorithm much easier to implement, without the extra bookkeeping of `ThreadingOpportunity` we had.

Later commits modify that algorithm to shrink the set of duplicated blocks. By propagating fulfilled conditions down the CFG, and trimming costly threads.
2025-12-01 23:44:49 +00:00
bendn
919e46f4d4
stabilize [T]::array_windows 2025-12-02 00:37:17 +07:00
Zalathar
ac437169ec coverage: Store branch spans in the expansion tree 2025-11-30 18:31:55 +11:00
Zalathar
61c923b765 coverage: Store fn_sig_span and body_span in the expansion tree 2025-11-30 18:31:55 +11:00
Stuart Cook
a57d7539cb
Rollup merge of #149317 - bjorn3:has_ffi_unwind_calls_inline_asm, r=petrochenkov
Handle inline asm in has_ffi_unwind_calls

This is required for the soundness of `options(may_unwind)`.

Extracted from https://github.com/rust-lang/rust/pull/149141.
2025-11-26 23:32:10 +11:00
bjorn3
d3c580db21 Handle inline asm in has_ffi_unwind_calls
This is required for the soundness of options(may_unwind)
2025-11-25 16:01:02 +00:00
zjumathcode
d8c9d70508 Fix comment wording in simplify_comparison_integral.rs
Signed-off-by: zjumathcode <pai314159@2980.com>
2025-11-25 14:16:14 +08:00
bors
e9acbd99d3 Auto merge of #147827 - saethlin:maybeuninit-codegen2, r=scottmcm
Fix MaybeUninit codegen using GVN

This is an alternative to https://github.com/rust-lang/rust/pull/142837, based on https://github.com/rust-lang/rust/pull/146355#discussion_r2421651968.

The general approach I took here is to aggressively propagate anything that is entirely uninitialized. GVN generally takes the approach of only synthesizing small types, but we need to generate large consts to fix the codegen issue.

I also added a special case to MIR dumps for this where now an entirely uninit const is printed as `const <uninit>`, because otherwise we end up with extremely verbose dumps of the new consts.

After GVN though, we still end up with a lot of MIR that looks like this:
```
StorageLive(_1);
_1 = const <uninit>;
_2 = &raw mut _1;
```
Which will break tests/codegen-llvm/maybeuninit-rvo.rs with the naive lowering. I think the ideal fix here is to somehow omit these `_1 = const <uninit>` assignments that come directly after a StorageLive, but I'm not sure how to do that. For now at least, ignoring such assignments (even if they don't come right after a StorageLive) in codegen seems to work.

Note that since GVN is based on synthesizing a `ConstValue`  which has a defined layout, this scenario still gets deoptimized by LLVM.
```rust
#![feature(rustc_attrs)]
#![crate_type = "lib"]
use std::mem::MaybeUninit;

#[unsafe(no_mangle)]
pub fn oof() -> [[MaybeUninit<u8>; 8]; 8] {
    #[rustc_no_mir_inline]
    pub fn inner<T: Copy>() -> [[MaybeUninit<T>; 8]; 8] {
        [[MaybeUninit::uninit(); 8]; 8]
    }

    inner()
}
```
This case can be handled correctly if enough inlining has happened, or it could be handled by post-mono GVN. Synthesizing `UnevaluatedConst` or some other special kind of const seems dubious.
2025-11-23 17:09:07 +00:00
bors
122cbd0438 Auto merge of #147804 - tmiasko:move-copy, r=cjgillot,saethlin
Turn moves into copies after copy propagation

Previously copy propagation presumed that there is further unspecified distinction between move operands and copy operands in assignments and propagated moves from assignments into terminators. This is inconsistent with current operational semantics.

Turn moves into copies after copy propagation to preserve existing behavior.

Fixes https://github.com/rust-lang/rust/issues/137936.
Fixes https://github.com/rust-lang/rust/issues/146423.

r? `@cjgillot`
2025-11-23 13:56:14 +00:00
Ben Kimock
1a4852c5fe Fix MaybeUninit codegen using GVN 2025-11-23 08:23:49 -05:00
bors
e0e204f3e9 Auto merge of #149096 - chenyukang:yukang-fix-unused-vars-148373, r=oli-obk
Skip unused variables warning for unreachable code

Fixes rust-lang/rust#148373

These warnings are not reported on stable branch, but are now reported on the beta.

I tried another solution to record whether a `local` is reachable in `find_dead_assignments`, but the code in this PR seems simpler.

r? `@cjgillot`
2025-11-23 04:14:38 +00:00
Matthias Krüger
cef578b3a9
Rollup merge of #149072 - chenyukang:yukang-fix-unused-148960, r=davidtwco
Fix the issue of unused assignment from MIR liveness checking

Fixes rust-lang/rust#148960
Fixes rust-lang/rust#148418

r? ``@davidtwco``

cc ``@cjgillot``

My first try on MIR related code, so it may not be the best fix.
2025-11-22 18:41:21 +01:00
Guillaume Gomez
60ed1ab0ec
Rollup merge of #148719 - Nadrieril:poly-drop-glue, r=saethlin
Allow unnormalized types in drop elaboration

I work on a [rustc driver](https://github.com/AeneasVerif/charon) that aims to extract the full polymorphic MIR of a crate. Currently the one thing I can't get is drop glue because it fails on unnormalizable types like the fields of `Cow` or `NonZero`.

This PR removes the one check for unnormalized types in drop elaboration. It's a `span_delay_bug` so only there to help catch mistakes. I think that's fine to remove? If something downstream relies on types being normalized the right approach is for MIR validation to check for normalized types, not that one random check.
2025-11-21 21:34:23 +01:00
yukang
f943606503 Fix unused_assignments false positives from macros 2025-11-21 12:19:48 +08:00
yukang
2c6b1d3430 Skip unused variables warning for unreachable code 2025-11-21 08:48:45 +08:00
Matthias Krüger
710720a827
Rollup merge of #149033 - ZuseZ4:autodiff-rlib, r=bjorn3
autodiff rlib handling

As I learned recently, we now apparently support rlib builds already in some cases.
With the last hint from saethlin this seems to now cover all cases. To be sure I'll add a few more testcases before I mark it as ready.

Once this PR lands, we should to the best of my knowledge, support autodiff in almost code locations, only vtable/dyn ptr remain unsupported for now.

r? ghost

closes: https://github.com/rust-lang/rust/issues/148856
closes: https://github.com/rust-lang/rust/issues/137520
2025-11-20 20:11:42 +01:00