717 Commits

Author SHA1 Message Date
bors 9ab01ae53c Auto merge of #155491 - ohadravid:faster-storage-in-copyprop-and-gvn, r=saethlin
Fix performance regression introduced in #142531 by excluding `Storage{Live,Dead}` from CGU size estimation



Fix performance regression introduced in rust-lang/rust#142531 ([rust-timer comment](https://github.com/rust-lang/rust/pull/142531#issuecomment-4273712294)) by excluding `Storage{Live,Dead}` from CGU size estimation.

Also, avoid unneeded work for storage removal in non-opt builds in CopyProp and GVN
by allocating local sets for the storage accounting only when `tcx.sess.emit_lifetime_markers()`. 

r? saethlin
2026-04-21 05:35:16 +00:00
bors c28e303778 Auto merge of #155552 - JonathanBrouwer:rollup-JKIpTuW, r=JonathanBrouwer
Rollup of 11 pull requests

Successful merges:

 - rust-lang/rust#154654 (Move `std::io::ErrorKind` to `core::io`)
 - rust-lang/rust#145270 (Fix an ICE observed with an explicit tail-call in a default trait method)
 - rust-lang/rust#154895 (borrowck: Apply `user_arg_index` nomenclature more broadly)
 - rust-lang/rust#155213 (resolve: Make sure visibilities of import declarations make sense)
 - rust-lang/rust#155346 (`single_use_lifetimes`: respect `anonymous_lifetime_in_impl_trait`)
 - rust-lang/rust#155517 (Add a test for Mach-O `#[link_section]` API inherited from LLVM)
 - rust-lang/rust#155549 (Remove some unnecessary lifetimes.)
 - rust-lang/rust#154248 (resolve :  mark repr_simd as internal)
 - rust-lang/rust#154772 (slightly optimize the `non-camel-case-types` lint)
 - rust-lang/rust#155541 (Add `#[rust_analyzer::prefer_underscore_import]` to the traits in `rustc_type_ir::inherent`)
 - rust-lang/rust#155544 (bootstrap: Make "detected modifications" for download-rustc less verbose)
2026-04-20 16:15:13 +00:00
Nicholas Nethercote 5e00b8e7d5 Remove some unnecessary lifetimes.
We have a number of structs with more lifetimes than necessary. This
commit removes them.

LLM disclosure: I asked Claude Code to check for unnecessary lifetimes
in all types with three or more lifetimes, and it produced a list of
candidates (half of which were invalid). I did the modifications for the
valid cases myself, and found a couple more cases along the way.
2026-04-20 19:25:51 +10:00
Jonathan Brouwer cccf996225 Rollup merge of #155264 - sayantn:amx-autocast, r=dianqk
Add autocast support for `x86amx`

Builds on rust-lang/rust#140763 by further adding autocasts for `x86amx` from/to vectors of size 8192 bits.

This also disables SIMD vector abi checks for the `"unadjusted"` abi because
 - This is primarily used to link with LLVM intrinsics, which don't actually lower to function calls with vector arguments. Even with other cg backends, this is true.
 - This ABI is internal and perma-unstable (and also super specific), so it is very unlikely that this will cause breakages.
 - (The primary reason) Without doing this we can't actually use 8192 bit long vectors to represent `x86amx`

> Why do we need a bypass for `x86amx`? Can't we use a `#[lang_item]` or something?

If `x86amx` was a normal LLVM type, this approach would've worked and I would also prefer it. But LLVM specifies that

> No instruction is allowed for this type. There are no arguments, arrays, pointers, vectors or constants of this type.

So we can't treat it like a normal type at all -- even if we add it like a lang-item, we would still have to special-case everywhere to check if we are passing to the correct LLVM intrinsic, and only then use the `x86amx` type. IMO this is needlessly complex, and way worse than this solution, which just adds it to the autocast list in cg_llvm

r? codegen
2026-04-20 08:14:10 +02:00
Adwin White 6279106e72 fix all errors 2026-04-20 00:18:28 +08:00
Ohad Ravid 846974e1b0 Don't count storage statements in size_estimate query 2026-04-19 11:05:17 +03:00
sayantn 1a28bc4529 Disable ABI checks for the unadjusted ABI 2026-04-14 03:25:02 +05:30
Folkert de Vries 6f428df8df preseve SIMD element type information
and provide it to LLVM for better optimization
2026-04-13 13:26:50 +02:00
Nicholas Nethercote 3ff4201fd1 Move rustc_middle::mir::mono to rustc_middle::mono
Because the things in this module aren't MIR and don't use anything
from `rustc_middle::mir`. Also, modules that use `mono` often don't use
anything else from `rustc_middle::mir`.
2026-04-07 08:33:54 +10:00
Nicholas Nethercote ff1795fe49 Remove Clone impl for StableHashingContext.
`HashStable::hash_stable` takes a `&mut Hcx`. In contrast,
`ToStableHashKey::to_stable_hash_key` takes a `&Hcx`. But there are
some places where the latter calls the former, and due to the mismatch a
`clone` call is required to get a mutable `StableHashingContext`.

This commit changes `to_stable_hash_key` to instead take a `&mut Hcx`.
This eliminates the mismatch, the need for the clones, and the need for
the `Clone` impls.
2026-04-03 15:34:33 +11:00
Daria Sukhonina 1b68d921a7 Add typeck_root_def_id_local 2026-03-27 15:36:28 +03:00
John Kåre Alsaker bee28ef7b2 Remove MTLock 2026-03-12 14:37:51 +01:00
Jonathan Brouwer 707bf0961a Rollup merge of #152569 - oli-obk:rustc_layout_scalar_valid_range_end_end, r=davidtwco
Stop using rustc_layout_scalar_valid_range_* in rustc

*[View all comments](https://triagebot.infra.rust-lang.org/gh-comments/rust-lang/rust/pull/152569)*

Another step towards rust-lang/rust#135996

Required some manual impls, but we already do many manual impls for the newtype_index types, so it's not really a new maintenance burden.
2026-03-11 22:05:41 +01:00
bors b2fabe39bd Auto merge of #153673 - JonathanBrouwer:rollup-cGOKonI, r=JonathanBrouwer
Rollup of 7 pull requests

Successful merges:

 - rust-lang/rust#153560 (Introduce granular tidy_ctx's check in extra_checks)
 - rust-lang/rust#153666 (Add a regression test for rust-lang/rust#153599)
 - rust-lang/rust#153493 (Remove `FromCycleError` trait)
 - rust-lang/rust#153549 (tests/ui/binop: add annotations for reference rules)
 - rust-lang/rust#153641 (Move `Spanned`.)
 - rust-lang/rust#153663 (Remove `TyCtxt::node_lint` method and `rustc_middle::lint_level` function)
 - rust-lang/rust#153664 (Add test for rust-lang/rust#109804)
2026-03-11 05:12:10 +00:00
bors d1c79458b5 Auto merge of #153379 - TKanX:refactor/149164-simplify-autodiff-rlib, r=ZuseZ4
refactor(autodiff): Simplify Autodiff Handling of `rlib` Dependencies

### Summary:

Resolves the two FIXMEs left in rust-lang/rust#149033, per @bjorn3 guidance in [the discussion](https://github.com/rust-lang/rust/pull/149033#discussion_r2535465880).

Closes rust-lang/rust#149164 

r? @ZuseZ4
cc @bjorn3
2026-03-11 02:03:25 +00:00
Nicholas Nethercote c12ab08c14 Move Spanned.
It's defined in `rustc_span::source_map` which doesn't make any sense
because it has nothing to do with source maps. This commit moves it to
the crate root, a more sensible spot for something this basic.
2026-03-11 06:25:23 +11:00
David Wood db5e2dc248 abi: s/ScalableVector/SimdScalableVector
Renaming to remove any ambiguity as to what "vector" refers to in this
context
2026-03-10 11:52:22 +00:00
Josh Stone 32bae1353e Update cfg(bootstrap) 2026-03-07 10:42:02 -08:00
Oli Scherer ff7e604154 Stop using rustc_layout_scalar_valid_range_* in rustc 2026-03-07 15:36:56 +00:00
Tony Kan dd9922151f refactor(autodiff): Simplify rlib dep handling; use fn_ptr_ty in adjust_activity_to_abi, drop mono-collection & cross-crate-inline workarounds 2026-03-04 03:53:52 -08:00
bors 38c0de8dcb Auto merge of #153050 - JayanAXHF:refactor/change-is-type-const, r=BoxyUwU
refactor(mgca): Change `DefKind::Const` and `DefKind::AssocConst` to have a `is_type_const` flag



Addresses rust-lang/rust#152940 

- Changed `DefKind::Const` and `DefKind::AssocConst` to have a `is_type_const` flag.
- changed `is_type_const` query to check for this flag
- removed `is_rhs_type_const` query

r? @BoxyUwU
2026-02-28 18:27:06 +00:00
JayanAXHF efc150e5b3 refactor(mgca): Change DefKind::Const and DefKind::AssocConst to have a is_type_const flag
* refactor: add `is_type_const` flag to `DefKind::Const` and `AssocConst`
* refactor(cleanup) remove the `rhs_is_type_const` query
* style: fix formatting
* refactor: refactor stuff in librustdoc for new Const and AssocConst
* refactor: refactor clippy for the changes
* chore: formatting
* fix: fix test
* fix: fix suggestions
* Update context.rs

Co-authored-by: Boxy <rust@boxyuwu.dev>
* changed AssocKind::Const to store data about being a type const
2026-02-28 17:27:46 +00:00
Guillaume Gomez 2bb3b01af2 Replace TyCtxt::emit_node_span_lint with emit_diag_node_span_lint 2026-02-24 20:34:22 +01:00
Guillaume Gomez f02ce9648f Migrate rustc_monomorphize to use TyCtxt::emit_diag_node_span_lint 2026-02-24 20:12:43 +01:00
Nicholas Nethercote a3d590888b Remove impl IntoQueryParam<P> for &'a P.
`IntoQueryParam` is a trait that lets query callers be a bit sloppy with
the passed-in key.
- Types similar to `DefId` will be auto-converted to `DefId`. Likewise
  for `LocalDefId`.
- Reference types will be auto-derefed.

The auto-conversion is genuinely useful; the auto-derefing much less so.
In practice it's only used for passing `&DefId` to queries that accept
`DefId`, which is an anti-pattern because `DefId` is marked with
`#[rustc_pass_by_value]`.

This commit removes the auto-deref impl and makes the necessary sigil
adjustments. (I generally avoid using `*` to deref manually at call
sites, preferring to deref via `&` in patterns or via `*` in match
expressions. Mostly because that way a single deref often covers
multiple call sites.)
2026-02-22 17:58:54 +11:00
Kivooeo 964b63f42e if let guard stabilize 2026-02-16 12:24:15 +00:00
Stuart Cook 09720ec3d0 Rollup merge of #152329 - Zoxc:simple-parallel-macro, r=nnethercote
Simplify parallel! macro

This replaces the `parallel!` macro with a `par_fns` function.
2026-02-13 15:19:12 +11:00
John Kåre Alsaker 8c5ce26e43 Replace parallel! macro with par_fns function and rename join to par_join 2026-02-12 12:20:18 +01:00
Jonathan Brouwer 99c6009c45 Reformat existing messages 2026-02-08 23:07:58 +01:00
bors f889772d65 Auto merge of #152096 - bjorn3:mir_encoding_cleanups, r=oli-obk
Couple of cleanups and optimizations around MIR encoding
2026-02-05 15:30:48 +00:00
bors db3e99bbab Auto merge of #150605 - RalfJung:fallback-intrinsic-skip, r=mati865
skip codegen for intrinsics with big fallback bodies if backend does not need them

This hopefully fixes the perf regression from https://github.com/rust-lang/rust/pull/148478. I only added the intrinsics with big fallback bodies to the list; it doesn't seem worth the effort of going through the entire list.

Fixes https://github.com/rust-lang/rust/issues/149945
Cc @scottmcm @bjorn3
2026-02-04 17:12:58 +00:00
bjorn3 1e6f7845ed Avoid encoding optimized MIR for constructors
We only use mir_for_ctfe for them anyway in instance_mir. This does
prevent MIR inlining of constructor calls, but constructor calls that
are inlinable during MIR optimizations are rare anyway given that MIR
building already inlines all direct calls to constructors.
2026-02-04 16:00:33 +00:00
Jonathan Brouwer d457ffd4f4 Convert to inline diagnostics in rustc_monomorphize 2026-02-03 22:44:22 +01:00
Jonathan Brouwer 5cccc7ca02 Rollup merge of #151441 - Keith-Cancel:mgca3, r=BoxyUwU
Fix ICE: Don't try to evaluate type_consts when eagerly collecting items

This fixes https://github.com/rust-lang/rust/issues/151246

The change is pretty straightforward if the Monomorphization strategy is eager which `-Clink-dead-code=true` sets. This then would lead to the existing code to try and evaluate a `type const` which does not have a body to evaluate leading to an ICE. The change is pretty straight forward just skip over type consts.

This also seems like a sensible choice to me since a MonoItem can only be a Fn, Static, or Asm. A type const is none of the aforementioned.

And even if it was added to the MonoItems list it would then later fail this check:
https://github.com/rust-lang/rust/blob/fe98ddcfcfb6f185dbf4adeaf439d8a756da0273/compiler/rustc_monomorphize/src/collector.rs#L438-L440
Since that explicitly checks that the MonoItem's `DefKind` is static and not anything else.

One more change is the addition of a simple test of the example code from https://github.com/rust-lang/rust/issues/151246 that checks that code compiles successfully with `-Clink-dead-code=true`.

The only other change was to make the guard checks a little easier to read by making the logic more linear instead of one big if statement.

r? @BoxyUwU
@rustbot label +F-associated_const_equality +F-min_generic_const_args
2026-01-22 13:35:42 +01:00
Mark Rousskov 3dc7a1f33b Bump stage0 2026-01-21 20:03:56 -05:00
Keith-Cancel 7635702d06 Don't try to evaluate type_consts when eagerly collecting items.
Update compiler/rustc_monomorphize/src/collector.rs

Add FIXME(mgca) comment to potentially re-investigate in the future.

Co-Authored-By: Boxy <rust@boxyuwu.dev>
2026-01-21 04:38:53 -08:00
Jonathan Brouwer e668836c92 Fix capitalization of error messages 2026-01-18 22:40:55 +01:00
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
Matthias Krüger 3481c0d3cb Rollup merge of #150569 - check_static_initializer_acyclic, r=workingjubilee
Ensure that static initializers are acyclic for NVPTX

NVPTX does not support cycles in static initializers (see rust-lang/rust#146787). LLVM produces an error when attempting to generate code for such constructs, like self-referential structs.

To avoid LLVM UB, we emit a post-monomorphization error on the Rust side before reaching codegen.

This is achieved by analyzing a subgraph of the "mono item graph" that only contains statics.
1. Calculate the strongly connected components (SCCs) of the graph.
2. Check for cycles (more than one node in an SCC or one node that references itself).
2026-01-08 16:25:30 +01:00
kulst 630c7596e9 Ensure that static initializers are acyclic for NVPTX
NVPTX does not support cycles in static initializers. LLVM produces an error when attempting to codegen such constructs (like self referential structs).

To not produce LLVM UB we instead emit a post-monomorphization error on
Rust side before reaching codegen.

This is achieved by analysing a subgraph of the "mono item graph" that
only contains statics:
1. Calculate the strongly connected components (SCCs) of the graph
2. Check for cycles (more than one node in a SCC or exactly one node
   which references itself)
2026-01-06 17:00:21 +01:00
Folkert de Vries 76d0843f8d naked functions: emit .private_extern on macos 2026-01-06 16:48:04 +01:00
Ralf Jung 57e44f5046 skip codegen for intrinsics with big fallback bodies if backend does not need them 2026-01-02 23:14:02 +01:00
Esteban Küber 9f566f2463 Don't use matches! when == suffices
In the codebase we sometimes use `matches!` for values that can actually just be compared. Replace them with `==`.
2025-12-26 20:28:19 +00:00
David Wood 5f27abdbc8 mono: require target feature for scalable vectors
Scalable vector types only work with the relevant target features
enabled, so require this for any function with the types in its
signature.
2025-12-16 11:01:26 +00:00
Flakebi a9b147259b Allow vector types for amdgpu
The amdgpu target uses vector types in various places. The vector types
can be used on all architectures, there is no associated target feature
that needs to be enabled.

The largest vector type found in LLVM intrinsics is `v32i32`
(`[32 x i32]`) for mfma intrinsics. Note that while this intrinsic is
only supported on some architectures, the vector type itself is
supported on all architectures.
2025-12-14 17:03:51 +01:00
bors 3f4dc1e02d Auto merge of #146348 - jdonszelmann:eiiv3, r=lcnr,oli-obk
Externally implementable items

Supersedes https://github.com/rust-lang/rust/pull/140010
Tracking issue: https://github.com/rust-lang/rust/issues/125418

Getting started:

```rust
#![feature(eii)]

#[eii(eii1)]
pub fn decl1(x: u64)
// body optional (it's the default)
{
    println!("default {x}");
}

// in another crate, maybe
#[eii1]
pub fn decl2(x: u64) {
    println!("explicit {x}");
}

fn main() {
    decl1(4);
}
```

- tiny perf regression, underlying issue makes multiple things in the compiler slow, not just EII, planning to solve those separately.
- No codegen_gcc support, they don't have bindings for weak symbols yet but could
- No windows support yet for weak definitions

This PR merges the implementation of EII for just llvm + not windows, doesn't yet contain like a new panic handler implementation or alloc handler. With this implementation, it would support implementing the panic handler in terms of EII already since it requires no default implementation so no weak symbols

The PR has been open in various forms for about a year now, but I feel that having some implementation merged to build upon
2025-12-14 04:20:26 +00:00
Jana Dönszelmann 5768b234de use our own alternative to STD_INTERNAL_SYMBOL and make sure we mangle EIIs properly 2025-12-12 12:14:54 +01:00
Urgau 5da3de7527 Move users of span_to_embeddable_string to span_to_diagnostic_string
This is done in order to simplify the filename overhaul and those places
don't need to the embeddable path anyway.
2025-12-12 07:32:25 +01: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
Boxy Uwu 76bd21ad66 account for safe target features in fndef<->closure and fndef<->fndef coerce-lubs 2025-12-03 14:55:41 +00:00