Commit Graph

4178 Commits

Author SHA1 Message Date
Jacob Pratt
6bd52be2ec Rollup merge of #160969 - Albab-Hasan:span-for-size-of-val-layout-errors, r=oli-obk
give layout errors from `size_of_val` and `align_of_val` a span

`size_and_align_of_dst` used the spanless `layout_of` so a `SizeOverflow` from `size_of_val` or `align_of_val` came out as

```
error: values of the type `[u8; 9223372036854775807]` are too big for the target architecture
```

and now points at the call:

```
error: values of the type `[u8; 9223372036854775807]` are too big for the target architecture
 --> src/lib.rs:5:53
  |
5 | pub fn check(x: *const Example) -> usize { unsafe { std::intrinsics::size_of_val(x) } }
  |                                                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
```

with `-Cdebuginfo=2` the error is hit earlier while describing the signature of the function so `get_function_signature` and `build_pointer_or_reference_di_node` forward the span `dbg_scope_fn` already computes same as https://github.com/rust-lang/rust/pull/145967 and https://github.com/rust-lang/rust/pull/146025 did for arrays and enums. the two revisions of the new test cover both.

this doesnt close https://github.com/rust-lang/rust/issues/25116. the vtable case in `tests/ui/limits/vtable.stderr` is emitted from a query keyed only on the type and the other builders in `debuginfo/metadata.rs` still drop spans.

cc @estebank who pointed at these two gaps on the issue.

r? @oli-obk
2026-08-13 18:16:24 -04:00
Jacob Pratt
89848b9239 Rollup merge of #159566 - Sa4dUs:offload-generics, r=ZuseZ4
Add support for generics in `offload`and remove `no_mangle` attribute

implements a 3rd pass where we collect kernel instantiations required by offload to work
also enforces consistent mangling for offload functions between host and device

closes: https://github.com/rust-lang/rust/issues/150985

r? @ZuseZ4
2026-08-12 20:17:30 -04:00
Marcelo Dominguez
55c63da345 Add tests remove extra mode and other fixes 2026-08-12 18:06:07 +03:00
Marcelo Dominguez
3daa8b3c70 fix 2026-08-12 18:06:07 +03:00
Marcelo Dominguez
a5a9f8cf4f Remove codegen and move manifest out of query 2026-08-12 18:06:07 +03:00
Marcelo Dominguez
4d52fe93a2 Add 3-pass compilation to support generics and remove no_mangle attr 2026-08-12 18:06:00 +03:00
Tim (Theemathas Chirananthavat)
6ce7842daf Remove MutatingUseContext::Retag
This variant was never constructed anywhere.
2026-08-12 17:48:07 +07:00
albab-hasan
eb750a765d give layout errors from size_of_val and align_of_val a span
`size_and_align_of_dst` asked for the pointee layout with the spanless `layout_of`, so a
`SizeOverflow` from these intrinsics printed a bare error with no location. it takes a span
now and both call sites pass the span of the

with `-Cdebuginfo=2` the same error comes froion signature,
which was spanless too. it now uses the span `dbg_scope_fn` already computes.
2026-08-12 13:32:45 +06:00
Jacob Pratt
2dabc21ee4 Rollup merge of #160924 - mejrs:split_cstore, r=JonathanBrouwer
split up `rustc_session`

Followup on https://github.com/rust-lang/rust/pull/160336 cc @JonathanBrouwer (feel free to review if you want)

The first commit splits out the `cstore` module from `rustc_session` into its own crate.

`rustc_session` actually never used it anywhere internally, and there are also several crates that only depend on `rustc_session` for it. So it is a natural candidate to split off.

The second commit is similar; `rustc_hir::definitions` is moved to `rustc_hir_id`; it is used nowhere in `rustc_hir`, except to implement an inherent method:

```rust
impl DefKind {
        pub fn def_path_data(self, name: Option<Symbol>) -> DefPathData { }
}
```

which is used (once) in rustc_middle, so the items in `rustc_hir::definitions` and this conversion function could be in many places. `rustc_hir_id` is the earliest and the easiest, so that's what I went with.

Together these allow `rustc_crate_store`, `rustc_hir` and `rustc_session` to compile in parallel.
Current graph:

<img width="825" height="617" alt="image" src="https://github.com/user-attachments/assets/aa954265-0057-4596-a7c4-38290937fb74" />

Graph after this pr:

<img width="853" height="572" alt="image" src="https://github.com/user-attachments/assets/9bcd16f8-897c-4990-920b-249500b2e78e" />
2026-08-11 21:18:31 -04:00
Jacob Pratt
8f07b6204f Rollup merge of #160620 - mati865:no-no-pie-windows, r=bjorn3
Do not pass `-no-pie` on Windows

The warning can be seen with a simple example:
```
❯ cargo new /tmp/hello -q
❯ cargo rustc --target x86_64-pc-windows-gnullvm -q -- -C target-feature=+crt-static
warning: linker stderr: clang: argument unused during compilation: '-no-pie' [-Wunused-command-line-argument]
  |
  = note: `#[warn(linker_messages)]` on by default
```
2026-08-11 21:18:23 -04:00
mejrs
b588ef3b37 Move rustc_session cstore module to its own crate 2026-08-11 17:12:12 +02:00
mejrs
196dd2a174 Fix up lang_items import paths 2026-08-09 15:20:29 +02:00
Jonathan Brouwer
98621aa995 Rename rustc_middle/error.rs to diagnostics.rs 2026-08-08 14:58:18 +02:00
Jonathan Brouwer
615aa922c8 Rollup merge of #160445 - rabindra789:fix/msvc-localized-linker-output, r=ChrisDenton
codegen: classify localized MSVC linker progress as linker_info

Fixes rust-lang/rust#159133.

`report_linker_output` currently recognizes only a small set of English `link.exe` progress messages as informational. When the linker output is localized, equivalent progress messages are instead emitted through the `linker_messages` lint.

Instead of matching specific English strings, classify MSVC linker output based on locale-independent `LNK####` diagnostic codes.Lines without an `LNK####` code are routed to `linker_info`, while diagnostics continue to be emitted through `linker_messages`. The existing `LNK6004` incremental-link exception is preserved.

Testing

- Added a run-make regression test for localized `link.exe` progress output.
- Verified the existing MSVC linker-info tests continue to pass.
2026-08-08 00:38:29 +02:00
Jonathan Brouwer
6a3b9acf14 Rollup merge of #160530 - RalfJung:internal-target-features, r=nnethercote
refactor handling of target features in Session

`Session` currently contains two lists of target features: `target_features`, which is also exposed in `cfg`, and `unstable_target_features`, which is used internally to communicate between various parts of the compiler which target features are *actually* available, including some that we don't have plans to put in `cfg`, namely "forbidden" target features. The `unstable_target_features` list is *not* equivalent to what nightly code sees in `cfg(target_features)` as the latter excludes "forbidden" target features. Both lists are computed by `fn cfg_target_features` even though one of them is never used for `cfg`. It's all kind of messy.

This PR refactors that: `fn cfg_target_features` is replaced by `fn internal_target_features` which computes all enabled Rust target features (including "forbidden" ones -- which are really more like "internal-only" ones so the 2nd commit renames them). We then compute `cfg(target_features)` from that. The session only stores one list, `internal_target_features`, which corresponds to the previous `unstable_target_features`.

To simplify computing `internal_target_features` I also refactored `parse_rust_feature_list` to better distinguish actual Rust target features from unknown target features that we are just grandfathering in. I also made `implied_target_features` not rebuild the same hash map over and over again. And I got rid of a bunch of silly temporary vectors and iterations over all Rust target features.
2026-08-08 00:38:22 +02:00
Jonathan Brouwer
4eeee3b756 Rollup merge of #150885 - farao:main, r=saethlin,joboet
Revive L4Re target

This revives the target for the L4Re OS. It changes the way, linking is done and adds aarch64 support and documentation including a maintainer for the target.

The update of the libc crate is necessary since only in 0.2.179 and higher is the fixed support for L4Re on uclibc.
2026-08-08 00:38:20 +02:00
bors
ae45457594 Auto merge of #160160 - ChayimFriedman2:if-empty-opt, r=TaKO8Ki
Optimize handling of solver errors



- Check for the empty case in `collect_remaining_errors()`.
- Instead of representing trait errors as `Vec<Error>`, use a special type

   This has multiple advantages:

    - Performance. The new type is 1/3 the size of `Vec` (being equivalent in layout to `Option<ThinVec>`) and can be kept in a register.
    - Type safety. We mark the type `#[must_use]`, and thinks requiring errors take `ThinVec`, which requires unwrapping the type and verifying there is indeed an error. We still provide conversions to slices, `ThinVec`, and iteration, because some code needs this and I saw no benefit in changing it, but we deliberately do not provide `Deref<Target = [E]>` or things like that.
2026-08-07 06:00:49 +00:00
Ralf Jung
e5004d09b0 ensure that we never toggle internal target features via the attribute 2026-08-06 16:49:57 +02:00
Ralf Jung
6253cca669 rename 'forbidden' target features to 'internal-only' 2026-08-06 16:49:57 +02:00
rabindra789
a1b86a7edf codegen: classify localized MSVC linker progress as linker_info
link.exe progress messages (e.g. "Creating library ...") are detected
by matching their English text, which fails when the English language
pack is not installed and the output is localized despite VSLANG=1033.
Since all actual warnings and errors carry a locale-independent LNK####
code, classify every line without one as linker_info instead of
linker_messages.

Diagnostics are recognized by their structured form, `LINK : warning
LNK####:`: the code must be followed by a `:` that is the second colon
in the line, so the matcher cannot accidentally hit file names.

The one code-bearing informational line, LNK6004 ("performing full
link"), keeps the exception that was previously handled by matching its
English text.
2026-08-06 20:15:40 +05:30
Ralf Jung
8bb9f279a9 refactor handling of target features in Session 2026-08-06 14:45:53 +02:00
Marius Melzer
f2dd93228a L4Re: Repair build and move to rustc linking
Fixes the builds of rustc and library/std for the L4Re target OS.
A major change was done in linking binaries: The need for the L4Bender
tool was removed and linking parameters are now fully configured in the
rustc target config.
2026-08-06 13:13:18 +02:00
Jonathan Brouwer
592096bca8 Rollup merge of #160398 - moulins:layout-is-variant-uninhabited, r=oli-obk
rustc_abi: Add `LayoutData::is_variant_uninhabited` method

This is a cheaper alternative to `TyAndLayout::for_variant(_, idx).is_uninhabited()`, which avoids the extra work done by `TyAndLayout::for_variant`.

EDIT: Let me expand on the motivation from this [comment](https://github.com/rust-lang/rust/pull/160398#issuecomment-5167761369):

`TyAndLayout::for_variant` is a curious API: the resulting layout doesn't represent a Rust type in the strict sense (not even `pattern_type!(Enum is Variant { .. })`; instead, it only describes the "variant-specific" fields, and fields shared between variants (e.g. the enum tag or coroutine captures) are entirely missing.

As such, I believe alternative APIs should be used instead to clarify intent, when possible. This PR deals with the simplest cases, and a future PR will add `TyAndLayout::variant_field(self, cx, variant_idx, field_idx)` to deal with the next-most common case of only needing a variant layout for field lookups.
2026-08-06 12:41:07 +02:00
Mateusz Mikuła
2697924576 Do not pass -no-pie on Windows 2026-08-06 11:47:29 +02:00
Chayim Refael Friedman
5491ec85e2 Instead of representing trait errors as Vec<Error>, use a special type
This has multiple advantages:

 - Performance. The new type is 1/3 the size of `Vec` (being equivalent in layout to `Option<ThinVec>`) and can be kept in a register.
 - Type safety. We mark the type `#[must_use]`, and thinks requiring errors take `ThinVec`, which requires unwrapping the type and verifying there is indeed an error. We still provide conversions to slices, `ThinVec`, and iteration, because some code needs this and I saw no benefit in changing it, but we deliberately do not provide `Deref<Target = [E]>` or things like that.
2026-08-06 07:18:55 +03:00
Jonathan Brouwer
7431f9754d Rollup merge of #160558 - davidtwco:sve-revert-no-dbginfo-for-locals, r=lqd
Revert "codegen_ssa: no dbginfo for scalable vec local w/ `-O0`"

This partially reverts commit ebe72104f0 (it keeps the tests), from rust-lang/rust#158088. The workaround in that patch is no longer necessary with the upgrade to LLVM 23 in rust-lang/rust#158734. I've confirmed that the stdarch tests also continue passing with this patch applied.

r? @lqd
2026-08-05 21:55:48 +02:00
Moulins
fee8922aa3 rustc_abi: Add LayoutData::is_variant_uninhabited method
This is a cheaper alternative to `TyAndLayout::for_variant(_, idx).is_uninhabited()`
2026-08-05 15:38:43 +02:00
Jonathan Brouwer
900f0bcb32 Rollup merge of #159225 - bjorn3:split_incr_comp_session, r=oli-obk
Split IncrCompSession out of Session

This will allow introducing a separate incr comp session dir for the post LTO artifacts in the future. In addition it statically encodes the lifetime of the incr comp session rather than requiring an enum behind a mutex stored in the Session.

Based on https://github.com/rust-lang/rust/pull/159000
Part of https://github.com/rust-lang/compiler-team/issues/908
2026-08-05 13:36:11 +02:00
Jonathan Brouwer
d734ccbb8d Rollup merge of #160387 - petrochenkov:backlimit, r=bjorn3
rustc_codegen_ssa: Correctly apply the static `--jobs-backend` limit to backend parallelism

Follow up to https://github.com/rust-lang/rust/pull/159675.

r? @bjorn3
2026-08-05 13:36:06 +02:00
David Wood
bf44b2c8ec Revert "codegen_ssa: no dbginfo for scalable vec local w/ -O0"
This reverts commit ebe72104f0.
2026-08-05 11:26:31 +01:00
Vadim Petrochenkov
54877b4f7c rustc_codegen_ssa: Correctly apply the static --jobs-backend limit to backend parallelism 2026-08-04 23:35:06 +03:00
Jonathan Brouwer
2d3ce685f6 Rollup merge of #160024 - amirHdev:fix-resume-personality, r=davidtwco
Fix mono reachability with no-op landing pads

the landing pad filtering used regular MIR successors when the initial traversal used monomorphized one
fixes rust-lang/rust#159980
2026-08-04 18:35:35 +02:00
Jonathan Brouwer
4182867eb9 Rollup merge of #160457 - RalfJung:llvm-target-feature, r=folkertdev
implement -Zllvm-target-feature

Implements https://github.com/rust-lang/rust/issues/157753
2026-08-04 18:35:29 +02:00
Ralf Jung
c82207c46e improve error message on missing target feature prefix 2026-08-04 11:25:59 +02:00
Jakub Beránek
3ee6e30969 Rollup merge of #160449 - Kobzol:filesearch-lookup-fix, r=petrochenkov
Fix lookup of object files

I broke this in https://github.com/rust-lang/rust/pull/158823. I wanted to optimize the potentially O(n^2) object file lookup, but didn't realize that we have to search all search paths here, not only files that we already prefiltered for the lib prefixes.

r? @petrochenkov

Fixes: https://github.com/rust-lang/rust/issues/160446
2026-08-04 11:10:32 +02:00
Jakub Beránek
07e1398046 Fix lookup of object files 2026-08-03 18:45:53 +02:00
bjorn3
1a3d919258 Deny multiple EII impls on a single item
This allows implementing EIIs that don't have a default impl without the
involvement of symbol aliases by simply changing the mangled symbol name
of the implementation, which would make them trivially compatible with
all backends and targets. This change will be left to a followup PR.
2026-08-03 11:04:23 +02:00
Jacob Pratt
f1113e0edb Rollup merge of #160306 - saethlin:panic-runtimes-dont-share, r=bjorn3
Don't use exported generics from conditional dependencies (panic runtimes and profiler-builtins)

This is a fix for https://github.com/rust-lang/rust/issues/159682.

This seems like a generalized footgun for writing FFI plugins? But at least right now, a very specific change to the crates we often swap around seems prudent.
2026-08-03 00:44:31 -04:00
Jonathan Brouwer
f650e5c0fe Rollup merge of #160318 - Zalathar:thorin, r=Mark-Simulacrum
Bump thorin-dwp (0.10), gimli (0.33), and object (0.38.1)

Originally, the hope was that this would reduce duplication of `object` within the compiler.

In practice, it turns out that this merely bumps the object major-version-set from {0.36, 0.37} to {0.37, 0.38}.

(The holdout for object@0.37 is `ar_archive_writer`, which does have a newer release available. But that would end up pulling in object@0.39 instead.)

There is still an object@0.36 entry in Cargo.lock, but that comes via `ui_test` which is a dev-dependency for clippy and miri.
2026-08-02 21:56:04 +02:00
Jonathan Brouwer
f66fc9873b Rollup merge of #160189 - cjgillot:codegen_stmt_debuginfo, r=TaKO8Ki
Move codegen_stmt_debuginfo to debuginfo.rs

This is the more consistent file to put it, and allows to reduce some visibilities.
2026-08-02 16:19:32 +02:00
Ben Kimock
601ee8e55d Don't use exported generics from conditional dependencies 2026-08-01 14:34:31 -04:00
Jonathan Brouwer
9956011498 Rollup merge of #160012 - RalfJung:deref-validity, r=oli-obk
miri: ensure validity of references and pointers we dereference and cast

Conceptually, when we evaluate the place expression `*place`, there are two steps that happen:
- perform a (typed) load from `place`, which yields a value of pointer/ref type
- construct a new place from that value

Since this is a typed load, we have to ensure that the value satisfies the validity invariant. We forgot to do that, which led to Miri missing a bunch of UB. This PR fixes that by adding the missing checks.

Triggering this UB is a bit non-trivial: you cannot just store an invalid value into `place` using regular assignment (that would already be caught as part of the assignment). However, you can take a raw pointer to `place` and then use that to mutate the contents of `place` in a way that its validity invariant no longer holds. For example:
```rust
fn main() {
    let mut x = &();
    // Overwrite `x` with null.
    unsafe { (&raw mut x).cast::<usize>().write(0) };
    let _val = *x; //~ERROR: null reference
}
```
This program clearly (IMO) should have UB, and has UB in MiniRust, but Miri accepted that program before this PR. The same applies to references that are invalid because they are unaligned (even if we end up only accessing a 1-aligned field, i.e. the rest of the place expression evaluates just fine), and to references that are invalid because they are not dereferenceable (even if we end up projecting to a zero-sized field, i.e., the rest of the place expression evaluates just fine).

Even raw pointers have this problem: a raw pointer can be invalid if its vtable pointer is wrong, and we did not check that.

And finally, this also affects `Box`, and this is where things get tricky. `Box` derefs are not even present any more in the MIR Miri sees; they have been replaced by derefs of the underlying raw pointer. But that means we have no way to know that we should check all those things. So to fix that I adjusted the ElaborateBoxDerefs to emit a new special kind of cast that's almost a transmute but also checks `Box` validity.

Fixes https://github.com/rust-lang/miri/issues/5226
Fixes https://github.com/rust-lang/unsafe-code-guidelines/issues/617
Cc @rust-lang/opsem
2026-08-01 15:56:37 +02:00
Zalathar
83d6b9657d Bump thorin-dwp (0.10), gimli (0.33), and object (0.38.1) 2026-08-01 20:18:15 +10:00
Ralf Jung
fcf68f21cf introduce a new CastKind for ElaborateBoxDerefs 2026-08-01 09:27:16 +02:00
Jacob Pratt
ad93b9a0be Rollup merge of #159245 - BorrowSanitizer:codegen-emit-retag-5, r=saethlin
Emit retags in codegen to support BorrowSanitizer (part 5)

Tracking issue: rust-lang/rust#154760
[Zulip Thread](https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/Staging.20for.20emitting.20retags.20in.20codegen/with/592364811)

This is one of several PRs that add experimental support for emitting retags as function calls in codegen.

This PR adds support for emitting global arrays that specify the ranges of interior mutable and pinned data. For example,
```rust
fn cell(x: &(i32, Cell<i32>)) { ... }
```
This program will have IR similar to the following:
```llvm
@anon.0 = unnamed_addr constant [16 x i8] c"\04...\04..."
define void @cell(ptr %0)  {
start:
  %x = call ptr @__rust_retag_reg(ptr %0, i64 8, i8 1, ptr @anon.0, ptr null)
  ...
}
```
The last four bytes at offset four are interior mutable.

Users can disable this behavior by passing `no-precise-im` or `no-precise-pin` as options to  `-Zcodegen-emit-retag`. In that case, the last two parameters to the retag intrinsic will always be null pointers.

BorrowSanitizer will be able to switch to using nightly once this is merged. Thank you @saethlin for reviewing these PRs!

Note: we still do not support retagging SIMD types, since cg-ssa does not support `insertelement`.

Related: rust-lang/rust#158100

Cc: @RalfJung
r? @saethlin
2026-07-31 22:25:10 -04:00
bors
6c04025a8a Auto merge of #158823 - Kobzol:flatten-search-paths, r=petrochenkov
Flatten all -L search paths into a single list of files



This is an optimization that mostly targets the new [Cargo build dir layout](https://rust-lang.github.io/rust-project-goals/2025h2/cargo-build-dir-layout.html).

Before, Cargo usually used to pass rustc a single `-L` path to a directory containing potentially a large number of `.rlib` or other dependency paths. Rustc is optimized for this, and does a preprocessing step, where it preloads all files from this directory into a sorted vector, in which it then performs binary search to look for files having a given prefix and postfix.

With the new build dir layout, this changes, and Cargo will pass potentially many (even hundreds, if your crate has many dependencies) `-L` directories, where each directory will usually have only 1-2 files. This is not ideal for the current rustc search implementation, because the old preprocessing isn't really worth it when the `-L` directory typically only has a single file, and because rustc will do a lot of work per each `-L` directory in the lookup phase, including some quadratic (O(n^2)) work.

With the `large-workspace` stress test from rustc-perf, where the final binary has ~1000 total and ~500 direct dependencies:
- With the old build dir layout, rustc does 4274 calls to `FilesIndex::query`
- With the new build dir layout, it does `1938314` calls to `FilesIndex::query`. Not ideal :)

This PR modifies the logic so that instead of going through all `-L` directories one by one when we are looking for a specific dependency, we pre-gather all files from all passed `-L` directories at the start, and sort them all together. Then, in the lookup phase, instead of performing <number of -L dirs> * 4 (.rmeta, .rlib, etc.) searched, we only perform the 4 searches across all files. This gets rid of the O(n^2) behavior.

Further improvements could be made, e.g. sort the files just once and then filter it for for both host and target filesearchs. I alsothought about pre-filtering the files further, e.g. based on their `kind`,  but that is not worth it in usual situations, where ~all of the deps will be `.rlib`s or `.rmeta`s anyway. What might work is pre-filtering based on their actual names (we strip known prefixes from them and then search based on the names alone, in a hashmap or something?), but that can be a follow-up.

Diff vs parent. of https://github.com/rust-lang/rust/pull/159857: https://perf.rust-lang.org/compare.html?start=1a833e16546c2eb012758ddd499964fd8afee29e&end=6514e2707b7e90fecbc570eeaa36f3780a9b02b4&stat=instructions%3Au
2026-07-31 22:09:50 +00:00
Jonathan Brouwer
a06a96e280 Rollup merge of #160272 - petrochenkov:metamove, r=nnethercote
rustc_metadata: Move native library search code to `rustc_codegen_ssa`

https://github.com/rust-lang/rust/issues/138243 was partially implemented, so we can do this now.
2026-07-31 16:02:27 +02:00
Jonathan Brouwer
2eb8d7053c Rollup merge of #159675 - petrochenkov:jjj, r=bjorn3
rustc: Support `--jobs` options for limiting parallelism in various parts of the compiler

`--jobs-frontend` for the frontend, `--jobs-backend` for the backend, `--jobs-linker` for the linker, and `-j`/`--jobs` for the overall limit.
See the added docs for more details.
Part of https://github.com/rust-lang/compiler-team/issues/1005.

Any suspicious option combinations are prohibited for now.
r? @bjorn3 @Zoxc
2026-07-31 16:02:23 +02:00
Jakub Beránek
55500ae2e7 Preprocess and sort files from all search paths into one large list 2026-07-31 13:43:49 +02:00
Vadim Petrochenkov
15d80dc813 rustc_metadata: Move native library search code to rustc_codegen_ssa 2026-07-31 12:46:23 +03:00