tests: accept noundef in a couple more places
LLVM 24 got smarter and is able to mark some more things noundef, which showed up in some of our test checks.
@rustbot label: +llvm-main
Improve suggestion for lifetime preceding type in generics
Closesrust-lang/rust#59325
Specifically, this fixes cases like the 2nd example in the issue, where a lifetime precedes a type in generic args:
`Foo<'static T1>` and suggests either adding a reference, i.e. `Foo<&'static T1>` or a comma, i.e. `Foo<'static, T1>`.
In a case like `Foo<'static mut T1>`, only `Foo<&'static mut T1>` is suggested.
reflection: fix ICE when TypeId::info called on ADT
We are refactoring from a large enum where the fields of the variants contain all the reflection info to a flat enum containing only the type kind (struct/bool/array etc). While we removed the fields of Struct, Enum and Union we forgot to take out the const eval code writing into those fields. That gave an ICE. This fixes that.
add `ignore-compare-mode-next-solver` to all next-solver tests
Adds `//@ ignore-compare-mode-next-solver (explicit revisions)` to all next-solver revision tests. Used an LLM to automate this and did a self-review. Can recommend only looking at `.rs` files.
Add a single-entry parent `SpanData` cache
For use in encoding, decoding, and stable hashing. It's a decent performance win on a number of benchmarks.
r? @oli-obk
avoid trivial `fn map_bound` validations
when compiling `zerocopy` a lot of time is spent simply checking the bound vars in `Clause::kind` because it does
```rust
self.0.internee.map_bound(|kind| match kind {
PredicateKind::Clause(clause) => clause,
_ => unreachable!(),
})
```
let's make performance with `debug_assertions` a bit better:
`zerocopy` with `-Znext-solver`:
```
16884862 counts
( 1) 12189626 (72.2%, 72.2%): Binder::map_bound called at compiler/rustc_middle/src/ty/predicate.rs:174:25
( 2) 1853971 (11.0%, 83.2%): Binder::map_bound called at compiler/rustc_type_ir/src/binder.rs:89:14
( 3) 1443803 ( 8.6%, 91.7%): Binder::map_bound called at compiler/rustc_type_ir/src/inherent.rs:493:14
( 4) 572570 ( 3.4%, 95.1%): Binder::map_bound called at compiler/rustc_type_ir/src/predicate.rs:234:14
( 5) 272733 ( 1.6%, 96.7%): Binder::map_bound called at compiler/rustc_type_ir/src/inherent.rs:507:14
( 6) 184934 ( 1.1%, 97.8%): Binder::map_bound called at compiler/rustc_middle/src/ty/predicate.rs:523:14
( 7) 183998 ( 1.1%, 98.9%): Binder::map_bound called at compiler/rustc_type_ir/src/predicate.rs:251:14
```
`zerocopy` with `-Znext-solver=no`
```
13476410 counts
( 1) 9906183 (73.5%, 73.5%): Binder::map_bound called at compiler/rustc_middle/src/ty/predicate.rs:174:25
( 2) 2107825 (15.6%, 89.1%): Binder::map_bound called at compiler/rustc_type_ir/src/binder.rs:89:14
( 3) 376524 ( 2.8%, 91.9%): Binder::map_bound called at compiler/rustc_type_ir/src/inherent.rs:493:14
( 4) 321976 ( 2.4%, 94.3%): Binder::map_bound called at compiler/rustc_type_ir/src/predicate.rs:251:14
( 5) 262305 ( 1.9%, 96.3%): Binder::map_bound called at compiler/rustc_middle/src/ty/predicate.rs:523:14
( 6) 84143 ( 0.6%, 96.9%): Binder::map_bound called at compiler/rustc_infer/src/infer/outlives/verify.rs:49:47
( 7) 83876 ( 0.6%, 97.5%): Binder::map_bound called at compiler/rustc_infer/src/traits/mod.rs:183:24
```
compiling `std`:
```
32803629 counts
( 1) 12234204 (37.3%, 37.3%): Binder::map_bound called at compiler/rustc_type_ir/src/binder.rs:89:14
( 2) 9624749 (29.3%, 66.6%): Binder::map_bound called at compiler/rustc_middle/src/ty/predicate.rs:174:25
( 3) 3805442 (11.6%, 78.2%): Binder::map_bound called at compiler/rustc_type_ir/src/inherent.rs:493:14
( 4) 2542468 ( 7.8%, 86.0%): Binder::map_bound called at compiler/rustc_type_ir/src/predicate.rs:234:14
( 5) 1229480 ( 3.7%, 89.7%): Binder::map_bound called at compiler/rustc_middle/src/ty/predicate.rs:523:14
( 6) 1176716 ( 3.6%, 93.3%): Binder::map_bound called at compiler/rustc_type_ir/src/predicate.rs:251:14
( 7) 385823 ( 1.2%, 94.5%): Binder::map_bound called at compiler/rustc_type_ir/src/inherent.rs:507:14
```
Could spend more effort to avoid the validation in trivial `Binder::fold_with`, but that's not worth it I think.
cc https://rust-lang.zulipchat.com/#narrow/channel/364551-t-types.2Ftrait-system-refactor/topic/casual.20chat.20and.20support/near/628479010
intrinsics: Rename `abort` to `abort_immediate`
The semantics of `intrinsics::abort()` are closer to what we have unstably as `abort_immediate()` than to `process::abort()` or `libc::abort()`. Rename it to make more clear that the intrinsic is more of an intentional crash with platform-specific behavior than what `libc::abort()` tries to be (i.e. raising `SIGABRT`).
If desired, a new intrinsic like `abort_gracefully` could be introduced that performs platform-specific behavior. This would more cleanly unblock https://github.com/rust-lang/rust/pull/149780.
See also discussion at the tracking issue for `immediate_abort` https://github.com/rust-lang/rust/issues/154601.
preserve overflow in builtin Field candidates
preserve overflow from the builtin Field candidate instead of treating it as `NoSolution`
the Sized requirements are now evaluated inside the candidate probe and coherence correctly rejects overlapping impls when evaluation overflows.
fixesrust-lang/rust#162125
Docs - type guarantees update
**Content:**
- Pin::map_unchecked | Safety section update
- String::reserve, String::reserve_exact | Panic section update
- Saturating | Introduce Layout section
- Fix typos
**Questions:**
1. This proposes to update String reserve methods docs:
> Panics if the new capacity overflows [`usize`].
->
> Panics if the new capacity exceeds [`isize::MAX`] bytes.
There are a few other types that are based on Vec and offer similar reserve API (like BinaryHeap).
Should they be updated, too?
ACP: ~~https://github.com/rust-lang/libs-team/issues/482~~ [not required]
Update the minimum external LLVM to 22
With this change, we'll have stable support for LLVM 22 and 23.
For reference, the previous increase to LLVM 21 was rust-lang/rust#153684.
cc @rust-lang/wg-llvm @durin42
r? nikic
explicitly handle tests that pass with -Znext-solver
these are all UI tests which pass with the new solver and fail with old. Using explicit revisions here.
Editing some of them to actually test what they should 😁
We are refactoring from a large enum where the fields of the variants
contain all the reflection info to a flat enum containing only the type
kind (struct/bool/array etc). While we removed the fields of Struct,
Enum and Union we forgot to take out the const eval code writing into
those fields. That gave an ICE. This fixes that.
The semantics of `intrinsics::abort()` are closer to what we have
unstably as `abort_immediate()` than to `process::abort()` or
`libc::abort()`. Rename it to make more clear that the intrinsic is more
of an intentional crash with platform-specific behavior than what
`libc::abort()` tries to be (i.e. raising `SIGABRT`).
Remove variants from `feature-gate-autodiff-use` test
Both the stable and nightly variants were the same; the test didn't actually test what it thought, because compiletest enables `RUSTC_BOOTSTRAP=1` unconditionally.
CC @ZuseZ4
r? jieyouxu
Rename `rustc_driver::run_compiler` to `compiler_entrypoint`
Having two `run_compiler` functions has always been confusing and not necessary at all, as they perform fairly different functions. Even more so because `rustc_driver::run_compiler` calls to `rustc_interface::run_compiler`. So it seems like a recursive function when it really isn't.
fix `ValidateBoundVars`
`ControlFlow::Break` is just wrong. We want to visit later types even if we skip the current one.
The `t.outer_exclusive_binder() <= self.binder_index` check is more subtle. See the flag computation
29df41c471/compiler/rustc_type_ir/src/flags.rs (L217-L218)
It is the exclusive binder. The first binder for which there exist no bound vars. This is subtle and was found while asking an LLM to help with perrrrf, only for me to then be confused for 10 min while checking whether this is right :<
r? types
Reorganise reflection intrinsics
Trivial refactor moving some things around.
We got a fair amount of intrinsics for reflection now with more on the way. At this point it's worth it to reorganize things a little. This prefixes them with `type_id_` (`TypeId` is the entry point for _nearly_ all of reflection) and moves their declaration into its own module (`core::intrinsics::reflection`).
Possible contentious is the move of the `type_id` intrinsic which has existed for a while and was previously at `core::intrinsics::type_id`. It is still unstable and as far as I am aware intrinsics should really not be relied upon by users.
I've decided to leave the `field_representing_field` (name, offset, actual_type_of) where they are since those where not created for reflection and will be changed in the future (see: https://github.com/rust-lang/rust/issues/162127).
r? oli-obk
Several small span improvements
Limit changes:
- Increase `MAX_CTXT`: it is currently `0b0111_1111_1111_1110` (~15 bits). But it only needs to be distinguishable from `CTXT_INTERNED_MARKER` (all 1s). So we can increase it to `0b1111_1111_1111_1110` (~16 bits). The old limit is rarely reached; the `uom` crate is an exception (it has 39k contexts) and we see a 1-2% instruction count reduction when building it. (This value was incorrectly reduced from ~16 bits to ~15 bits in e525e4f10a by me; apologies!)
Renamings:
- Rename `MAX_CTXT` as `MAX_CTXT_OR_PARENT` because it also relates to the parent field.
- Remove the `BASE_` prefix from `BASE_LEN_INTERNED_MARKER` because it doesn't mean anything.
Comments:
- Update parts of the comment that predate the addition of the `parent` field, such as the frequency measurements. (In incremental builds, 20-40% internment due to non-root context and non-zero parent is common.)
- Slightly clarify the meanings of the fields in the different forms, and add a paragraph quickly explaining which specific values distinguish the four forms.
r? @petrochenkov
Fix `TypeOutlives` fast-path
> Oh, the fast path is scuffed here. So, I feel fairly confident that we can encounter cases where stalled_on is wrong due to region vars without there being a bug, as in, your change is correct and desirable, but this specific test is just a bug in the fast path:
>
> `<MaybeVerify as Service<?infer>>::Future: 'static` should simply not be considered stalled. What's the cost of either entirely removing this trivially_stalled_on fast path or fixing it to bail when encountering non-rigid aliases
>
> This change is correct. Please separately do a PR to fix the type-outlives fastpath 😊
_Originally posted by @lcnr in https://github.com/rust-lang/rust/issues/162782#issuecomment-5920951094_
The first perf-run result is for always returning `Outcome::NoFastPath` on any infer var and the second one is for the current HEAD.
We shouldn't stall the outlives goal if the goal contains a non-rigid alias even though the goal contains a non-region infer. Non-fast path will normalize that non-rigid alias and that make the evaluation progress, and I think in theory the fast path shouldn't make observable difference outside the solver.
I'm not entirely sure on disabling fast path only in the presence of non-rigid opaques instead of disabling it entirely for non-region infer, but..
- It's no-less-correct than the status quo
- It roughly matches the actual non-fast path:
dba8825fe5/compiler/rustc_next_trait_solver/src/solve/mod.rs (L128-L129)
- The later has some perf impact hard to ignore for `typenum`
I couldn't conjure up any case fixed by this PR other than the one in https://github.com/rust-lang/rust/pull/162782😅
r? lcnr
Fix rustdoc ICE caused by mishandling of ambiguity errors
Fixesrust-lang/rust#162557
```rust
pub trait Service<Request> {
type Future;
}
pub trait ZebraService<Request>: Service<Request> {}
impl<MaybeVerify, Request> ZebraService<Request> for MaybeVerify where
MaybeVerify: Service<Request, Future: 'static>
{
}
pub struct Verifier;
impl Service<()> for Verifier {
type Future = &'static ();
}
```
In the above minimization of the issue, when we try to check whether the blanket impl can be applied to `Verifier`,
a8a1e6fd9d/src/librustdoc/clean/blanket_impl.rs (L42-L67)
We make fresh args for the where-clause and skip normalization for it.
So, we have `<?MaybeVerify as Service<?Request>>::Future: 'static` bound to check. But it immediately evaluated into ambiguity due to stalled on infer vars in the fast path as the obligation contains the infer vars.
But due https://github.com/rust-lang/rust/pull/162182 we evaluated it directly in the solver without `stalled_on` and this time it succeeded because we can normalize the alias into a concrete type `&'static ()` and it outlives the static region.
So, I think it's very iffy to call `InferCtxt::evaluate_obligation` on a non-rigid alias and we should eagerly normalize it in `L67` from the above rustdoc code.
But it may break something in rustdoc as normalizations inside it is pretty messy in general 🫠 So, I guess in another PR with crater runs.
r? lcnr
Add mul_add_relaxed methods for floating-point types
Implements mul_add_relaxed for f16, f32, f64, and f128, which computes (self * a) + b with relaxed precision semantics. Unlike mul_add which guarantees a fused operation, this variant allows the compiler to choose between fused or separate operations based on target performance.
This fills the gap between the precision-guaranteed mul_add and the fully-optimizable algebraic operators, providing target-specific optimization while maintaining reasonable floating-point semantics.
Tracking issue: https://github.com/rust-lang/rust/issues/151770
try-job: dist-i586-gnu-i586-i686-musl
Emit llvm dereferenceable in more cases on newer LLVM versions
On llvm >= 23 emit `dereferenceable` even without `nofree`, since https://github.com/llvm/llvm-project/pull/204795 makes `dereferenceable` act "at a point" / not imply `nofree`.
Additionally restrict `dereferenceable` to `&Freeze` / `&mut Unpin` / `Box<Unpin, _>` only (this is only relevant for `llvm >= 23` as otherwise `!Freeze`/`!Unpin` suppress `nofree` and as such `dereferenceable`).
r? nikic
I thought this will be a bit harder change, but since your refactoring in rust-lang/rust#156281 it's actually trivial ^^'
Draft because I don't think this can be tested prior to LLVM update. I'm also not sure if the version check I did is the appropriate one...
cc @RalfJung
Having two `run_compiler` functions has always been confusing and not necessary at all, as they perform fairly different functions. Even more so because `rustc_driver::run_compiler` calls to `rustc_interface::run_compiler`. So it seems like a recursive function when it really isn't.