Structurally prevent zero-count `BackendRepr::SimdVector`s
This is already *supposed* to be impossible in layout, but this emphasizes that better. This PR makes no behaviour changes; just `BackendLaneCount` instead of `u64` in https://doc.rust-lang.org/nightly/nightly-rustc/rustc_abi/enum.BackendRepr.html
Ironically I was inspired to do this as part of [looking at making `Simd<T, 0>` *work*](https://rust-lang.zulipchat.com/#narrow/channel/257879-project-portable-simd/topic/Allow.20N.3D.3D0.3F/with/613345298), but importantly if that's going to happen I think it should be `BackendRepr::Memory` like other ZSTs, *not* a `BackendRepr::ScalarVector` that would need to carry around a useless LLVM value in `OperandValue::Immediate` (where it's not even clear what the LLVM type of that value would be).
Report "capacity overflow" for oversized Rc<[T]>/Arc<[T]>
Fixesrust-lang/rust#136797.
Building an Rc<[T]>/Arc<[T]> whose header + payload layout exceeds
isize::MAX unwrapped a LayoutError and panicked with "called
Result::unwrap() on an Err value: LayoutError". Vec and Box report
"capacity overflow" here; this makes Rc/Arc do the same.
Used an inline panic!("capacity overflow") rather than raw_vec's
capacity_overflow(), since that helper is cfg'd out under
no_global_oom_handling while these two layout fns still compile there.
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
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
Rollup of 22 pull requests
Successful merges:
- rust-lang/rust#160100 (Add "system" option to `override-allocator` directive)
- rust-lang/rust#160220 (Refactor: shrink region ext traits)
- rust-lang/rust#159675 (rustc: Support `--jobs` options for limiting parallelism in various parts of the compiler)
- rust-lang/rust#159999 (Fix invalidation of stdlib in bootstrap when using non-LLVM codegen backends)
- rust-lang/rust#160233 (Bubble bad path error while parsing field to avoid unecessary second error)
- rust-lang/rust#160272 (rustc_metadata: Move native library search code to `rustc_codegen_ssa`)
- rust-lang/rust#154202 (rustfmt: Format `cfg_select!`)
- rust-lang/rust#159520 (Suggest `Vec<T>` instead of `[T]`)
- rust-lang/rust#159710 (Add rustdoc/cargo PGO profiles to reproducible artifacts)
- rust-lang/rust#160034 (Move "macro only" check for `#[allow_internal_unsafe/unstable]` to attribute parser)
- rust-lang/rust#160066 (rustc_middle: lint attribute cleanups)
- rust-lang/rust#160085 (Remove various superfluous lint attributes)
- rust-lang/rust#160113 (Coalesce `rustc_on_unimplemented` attributes and lint malformed filters)
- rust-lang/rust#160119 (fix query cycle in `coroutine_hidden_types` for the next solver)
- rust-lang/rust#160147 (tests: Remove `-Zthreads` options from tests in `ui/parallel-rustc`)
- rust-lang/rust#160157 (Remove outdated comments from `va_list.rs`)
- rust-lang/rust#160159 (More accurately check for interior mutability in `invalid_reference_casting` lint)
- rust-lang/rust#160208 (rustdoc: Fix crash when trying to list attributes on an opaque type)
- rust-lang/rust#160244 (Rename splat to rustc_splat in error messages)
- rust-lang/rust#160246 (dont fire `unused_mut` on `&pin mut self`)
- rust-lang/rust#160247 (Configure backport nominations for rustfmt)
- rust-lang/rust#160274 (renovate: update lock files weekly)
dont fire `unused_mut` on `&pin mut self`
`SelfKind::Pinned` in `Param::from_self` was setting the binding mutability to `mutbl`, so `&pin mut self` produced a mutable binding and triggered `unused_mut` spuriously. the `mut` qualifies the pin reference, not the binding. same as `SelfKind::Region` which uses `Mutability::Not`.
fixes https://github.com/rust-lang/rust/issues/142077
r? @petrochenkov
Rename splat to rustc_splat in error messages
Tracking issue: https://github.com/rust-lang/rust/issues/153629
This PR renames "splat attribute" to "\`rustc_splat\` attribute" in error messages (and some comments).
It was meant to be part of rust-lang/rust#159817 but I missed it.
The search and replace command I used was:
```sh
fastmod --extensions rs --fixed-strings 'splat attribute' '`rustc_splat` attribute'
```
This doesn't need to be backported, because those error messages only appear on nightly.
Part of rust-lang/rust#159428
rustdoc: Fix crash when trying to list attributes on an opaque type
Fixes https://github.com/rust-lang/rust/issues/160107.
It's crashing because we're using `get_attrs` on an `OpaqueTy` which cannot have attributes and therefore crashed. So instead, I check ahead of calling this function in the path where this can happen instead of doing it in `convert_render_type_id` on all `RenderTypeId::DefId`.
r? @notriddle
More accurately check for interior mutability in `invalid_reference_casting` lint
This PR replaces the `Freeze` trait check in the `invalid_reference_casting` lint by a recursive type check.
The check was not enough to determine if a type has "interior mutability", as `Freeze` is proxy for "has *some* interior mutability", not "fully covered by interior mutability".
As requested in https://github.com/rust-lang/rust/pull/159960#issuecomment-5090709661
Remove outdated comments from `va_list.rs`
Since rust-lang/rust#150436 codegen backends haven't needed to implement `va_copy` or `va_end` as they are implemented using intrinsic fallback bodies, so the comments on the `#[inline]` annotations are no longer relevant. I've left the `#[inline]` annotations themselves as they seem worthwhile since `va_copy` and `va_end` are a memcpy and a no-op respectively.
tests: Remove `-Zthreads` options from tests in `ui/parallel-rustc`
The number of threads is now passed by compiletest through `--parallel-frontend-threads=N` in parallel testing runs.
If it becomes necessary, we'll be able to set a larger number of threads or iterations for the `ui/parallel-rustc` tests specifically.
r? @jieyouxu
fix query cycle in `coroutine_hidden_types` for the next solver
Fixes https://github.com/rust-lang/trait-system-refactor-initiative/issues/282
When computing assumptions for coroutine hidden types, we are required to prove the `Send` bound on the same coroutine type again thus the query cycle.
We can just disable the higher-ranked-assumptions feature for the next solver.
r? @ShoyuVanilla
cc @lcnr
Move "macro only" check for `#[allow_internal_unsafe/unstable]` to attribute parser
Part of rust-lang/rust#131229 which is the parent issue of rust-lang/rust#153101
@JonathanBrouwer
Add rustdoc/cargo PGO profiles to reproducible artifacts
I forgot to do this in the previous PRs.
I wanted to wait for https://github.com/rust-lang/rust/pull/159642, but that's a bit stuck because of CI time, so let's not wait, to avoid missing reproducible artifacts in our builds.
rustfmt: Format `cfg_select!`
tracking issue: https://github.com/rust-lang/rust/issues/115585
Implementing `cfg_select!` formatting here in `rust-lang/rust` so that the feature can get out to nightly quicker.
The previous PR (rust-lang/rust#144323) is a bit old at this point and I felt like I could simplify the implementation so I've opted to reimplement the formatting instead of building off the previous PR.
I've tried to break the PR up into logical commits and I think this would be best reviewed one commit at a time.
---
Previous PR:
* https://github.com/rust-lang/rust/pull/144323
See also:
* https://github.com/rust-lang/style-team/issues/201
Bubble bad path error while parsing field to avoid unecessary second error
Noticed while looking at rust-lang/rust#92685. Add test for the case in that ticket.
Fix invalidation of stdlib in bootstrap when using non-LLVM codegen backends
This was quite the detective hunt. Antoyo reached out to me that when using the GCC codegen backend by default (`--set rust.codegen-backends=["gcc"]`), the stdlib is invalidated after every rebuild.
I did some digging, and found out this:
- The `Builder::cargo` step manually invalidates the target directory if any of the used codegen backends is dirty, because apparently the used codegen backend is not tracked by `-Zbinary-dep-depinfo` yet.
- It does so by getting all paths from `<sysroot>/lib/rustlib/<target>/codegen-backends` via the `Builder::codegen_backends` function, and if any such path is newer than the output directory, the output directory is deleted.
- The intention was for this function to return codegen backends, i.e. `.so/.dll` files. However, since the GCC codegen backend has additional dependencies (libgccjit), the `codegen-backends` contains a `lib` subdirectory. And bootstrap was checking the mtime of this *directory*, which was always considered dirty.
So I changed the function to only return the actual codegen backends, which fixes the issue. In theory, we should also be checking all the nested contents of the `lib` directory, i.e. the libgccjit dylibs, but I think that if they change, the GCC codegen backend itself should also change, in the vast majority of cases, so I consider this to be a worthy fix in the meantime.
CC @antoyo @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
Refactor: shrink region ext traits
- Removes `RegionUtilitiesExt`.
- Ports, where trivially simple, methods from the extension traits to `rustc_type_ir`.
- Cleans up imported crates where possible.
It seems `EarlyParamRegion` could possibly move to `rust_type_ir`?
r? @lcnr
Add "system" option to `override-allocator` directive
This allows a per-target `override-allocator` to revert to the system allocator even if there is a global rule specifying a different allocator.
Remap `jemalloc = false` to `override-allocator = "system"` instead of mapping it to "override-allocator is unset"; this restores the correct precedence behaviour of this directive.
This also allows `Config::override_allocator()` to always resolve the directive to a definite value, rather than needing it to be wrapped in an `Option`, which simplifies some other code.
Finally, print a more specific warning when `jemalloc` is set, telling users the appropriate setting to use for `override-allocator` depending on whether `jemalloc` is set to true or false.
Fixes https://github.com/rust-lang/rust/issues/160084
`SelfKind::Pinned` in `Param::from_self` was setting the binding mutability
to `mutbl`, so `&pin mut self` produced a mutable binding and triggered
`unused_mut` spuriously. the `mut` qualifies the pin reference, not the
binding -- same as `SelfKind::Region` which uses `Mutability::Not`.
fixes https://github.com/rust-lang/rust/issues/142077
This is already *supposed* to be impossible in layout, but this emphasizes that better.
Ironically I was inspired to do this as part of looking at making `Simd<T, 0>` *work*, but importantly if that's going to happen I think it should be `BackendRepr::Memory` like other ZSTs, *not* a `BackendRepr::ScalarVector` that would need to carry around a useless LLVM value in `OperandValue::Immediate` (where it's not even clear what the LLVM type of that value would be).
Always use short ty path for call with missing arguments suggestion
Mitigate having too long of a suggestion when there are many arguments missing by not printing the full path of the expected types.
```
error[E0061]: this function takes 5 arguments but 0 arguments were supplied
--> $DIR/verbose-suggestion-for-missing-fn-args.rs:5:5
|
LL | my_very_long_function_name_with_lots_of_args();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-- multiple arguments are missing
|
note: function defined here
--> $DIR/verbose-suggestion-for-missing-fn-args.rs:8:4
|
LL | fn my_very_long_function_name_with_lots_of_args(
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | _first_long_param: bool,
| -----------------------
LL | _second_long_param: HashMap<Arc<String>, Vec<BTreeSet<usize>>>,
| --------------------------------------------------------------
LL | _third_long_param: usize,
| ------------------------
LL | _fourth_long_param: String,
| --------------------------
LL | _fifth_long_param: Mutex<Option<VecDeque<Arc<String>>>>,
| -------------------------------------------------------
help: provide the arguments
|
LL | my_very_long_function_name_with_lots_of_args(/* bool */, /* HashMap<Arc<String>, Vec<BTreeSet<usize>>> */, /* usize */, /* String */, /* Mutex<Option<VecDeque<Arc<String>>>> */);
| +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
```
Partially address rust-lang/rust#101242. More work is needed to close that ticket, but this is an easy stop gap.
interpret: rename validate_operand → validate_place
A long time ago this worked on `OpTy`, but it got changed to `PlaceTy` at some point. Let's update the method names to match their signature.
r? @oli-obk