`core::num::f16b` Rust's 16bit Brain Float
Implements the [RFC: f16b type](https://github.com/rust-lang/rfcs/pull/3983). Best reviewed commit by commit, happy to split into separate PRs if that is deemed easier to review. However the line count and surface area is, in my opinion, reasonably small.
Adds;
- ABI plumbing for the `f16b` along with `bfloat` lang item to work with LLVM, GCC is explicitly `unimplemented!(...)`
- `f16b` feature gate, page for `f16b` on libruscdoc and a `struct bf16` in `core::num`
- Tests
- Treat `f16b` as a scalar primitive for scalable vectors
Issues;
- [Tracking Issue](https://github.com/rust-lang/rust/issues/160630)
- [RFC](https://github.com/rust-lang/rfcs/pull/3983)
For whatever reason, rust-analyzer doesn't understand hygienic macros well
enough to properly resolve this function call, which leads to bogus type errors
appearing in rust-analyzer because it doesn't know that the function returns
`!` and therefore must diverge.
(For example, if `bug!(..);` with a trailing semicolon is used in the else
block of a let-else statement, rust-analyzer will complain about it even though
rustc is happy.)
If we specify the full path to the function, both rustc and rust-analyzer agree
that it diverges.
PR #161873 moved these macros from `rustc_middle` to `rustc_span`. In
doing so it made some undesirable changes.
- The internal `emit_producing_nothing` became public.
- It gave the macros different behaviour to function-based ICEs like
`dcx.bug(..)` or `dcx.struct_bug(..).emit()`.
- `ExplicitBug` is not used, so `report_ice` prints an extraneous,
unintended "the compiler unexpectedly panicked" message.
- It broke the interaction between `span_bug!` and
`-Ztrack-diagnostics`.
This commit adjusts things to avoid the undesirable changes. It required
moving `ExplicitBug` to `rustc_span`. Setting `diag.emitted_at` fixed
the `-Ztrack-diagnostics` problem, seen in the change from `callback.rs`
to `validate.rs` in `track7.stderr`.
`Box<dyn Any>` output now occurs again in a few tests because the panic
payload is `ExplicitBug` (which std doesn't know about) rather than
`String`. That might be worth addressing in the future but it would
require a different/additional mechanism and is beyond the scope of this
PR.
Rollup of 7 pull requests
Successful merges:
- rust-lang/rust#161873 (move bug and span_bug macros to rustc_span)
- rust-lang/rust#162584 (Use File::*lock*() in rustc_data_structures::flock when possible)
- rust-lang/rust#162704 (Parser: Uninterpolate when checking for const closures, try bikeshed blocks & in relevant diagnostic code)
- rust-lang/rust#162787 (Fix suggestions for names captured by formatting macros)
- rust-lang/rust#159562 (Windows: cache the stdio write mode for the duration of a lock session)
- rust-lang/rust#162813 (Pre lint port cleanups)
- rust-lang/rust#162822 (PassWrapper: adapt for removal of EABIVersion arg in LLVM 24)
Fix non-deterministic encoding of syntax contexts
Reiteration of rust-lang/rust#157409. Explanation can be found in comment for `encoding_indices` and in the issue.
Fixesrust-lang/rust#129094. Blocked by rust-lang/rust#161353.
r? @petrochenkov
_No llms used._
split `macroless_generic_const_args` in two
Two's a crowd! But One's a lonely.
Having `macroless_generic_const_args` apply to const items was quite annoying for users especially as we moved away from `type const` to just regular const items. We would quite commonly be "guessing wrong" with no easy way for users to opt out of `const ASSOC: usize = ...` being represented directly instead of an opaque body
I just swapped any failing tests over to using macroless_const_item_generic_const_args, didnt look through the whole set :>
We should probably bikeshed the feature name rn because it's currently inconsistent with what we wanted to rename all of the other gca features too :> Maybe this should be `gca_macroless_const_items`
cc rust-lang/rust#162540
r? khyperia
Implement arbitrary casts in custom mir
[See zulip](https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/extending.20custom.20MIR/with/613727602)
Implement custom casts using an enum in `intrinsics::mir` that closely matches the `CastKind` enum in the compiler.
We have 5 different ways to cast in custom MIR, 3 with functions (which hard code a cast kind), 1 implicit coerce (which only does subtyping i think), 1 with `as` (which does a few more). They are all different and the error messages don't tell you what to do. Some are (i think) not possible at all.
This came up [while testing miri](https://rust-lang.zulipchat.com/#narrow/channel/136281-t-opsem/topic/Valdity.20checks.20for.20references/near/613662285). We currently have to guess the casting syntax until we find the one that generates the MIR we want. This PR changes that by adding a custom mir operation that allows picking an arbitrary cast.
r? RalfJung
Refactor `HygieneEncodeContext`
Some refactorings around `HygieneEncodeContext` with minor perf improvements, the most notable thing is that `Lock`s were removed.
First part for rust-lang/rust#161450.
r? @petrochenkov
Put manual calls of Enzyme intrinsics behind a feature gate
r? bjorn3
fixesrust-lang/rust#161820
I created the internal feature gate without a tracking issue. `autodiff` didn’t seem like it was the right one.
Replace links to `github.com/rust-lang/rfcs` with links to the Rust RFC Book
I noticed many error codes link to Rust RFCs via the [source GitHub `.md` files](https://github.com/rust-lang/rfcs/tree/master/text) instead of linking to the [RFC Book](https://rust-lang.github.io/rfcs/). This PR updates those links to point to the RFC book - I also updated any other links to RFCs in the repo (not including subtrees) while I was at it.
Reflection refactor ptrs
Tracking issue rust-lang/rust#146922
Part of the [Refactoring to many methods](https://rust-lang.zulipchat.com/#narrow/channel/572285-goals.2Freflection/topic/Refactoring.20to.20many.20methods/with/592226560) reflection subgoal. See that for the full context. In short for various reasons we are moving from an enum `TypeKind` where the variants hold the types information to one that just tells you the type kind. Separate methods on `TypeId` provide a way to get to the data that used to be in the variant.
Since function pointers have a lot of fields it felt better to keep the `FnPtr` struct we have now then add an intrinsic for each field.
r? @oli-obk
Add intrinsics for integer minimum and maximum
I got inspired to do this when looking at `SliceOrd::compare` where I was reminded that `if a < b { a } else { b }` isn't great in MIR since it takes 4 BBs. Looking at the codegen side, it turns out we currently emit [42 lines of LLVM-IR including 4 `alloca`s](https://rust.godbolt.org/z/ha4h4nT3r) for `u16::max` (pre-optimization), which is also unnecessarily bad†.
But both LLVM and Cranelift have dedicated things for min & max:
- https://llvm.org/docs/LangRef.html#llvm-umax-intrinsic
- https://docs.rs/cranelift-codegen/latest/cranelift_codegen/ir/trait.InstBuilder.html#method.smin
so let's just use those directly!
This actually wouldn't have been worth doing originally, but a couple of things have happened to change that:
- Back in 1.0 there was only `cmp::min` & `cmp::max`, so there was no place to actually do this at all, but in 2017 they were added to `Ord` as overridable things https://github.com/rust-lang/rust/issues/25663#issuecomment-325799662
- LLVM originally used icmp+select for these, not a dedicated construct, but then added one and as of 2022 the intrinsic is fully usable https://www.npopov.com/2022/12/20/This-year-in-LLVM-2022.html#integer-minmax-intrinsics
- Before we had intrinsic fallback this would have been more annoying to support everywhere -- GCC, [128-bit numbers on cg_clif](https://github.com/bytecodealliance/wasmtime/issues/13790), CTFE, anything out-of-tree -- but now that we can write the obvious fallback we don't need to worry about that.
- The intrinsic would have helped less when it forced extra BBs and `alloca`s in codegen anyway, but [now](https://github.com/rust-lang/compiler-team/issues/970) we can keep the result in SSA without needing to make it a primitive.
† Admittedly we could clean up the gratuitous badness there without needing an intrinsic, but I like doing the intrinsic anyway because that's the only way to avoid it always being stuck in the non-SSA path from the multi-BB assignments. Even if we made it inlineable, GVN and such will still just give up on seeing the `x = if a < b { a } else { b }` because it's multiple assignments to the same Local, which is non-ideal for something primitive-like.
remove rustc_never_type_options attr remnants
While fuzzing I noticed we would now ICE in two places when encountering an empty or filled `#![rustc_never_type_options()]` attr:
compiler/rustc_passes/src/check_attr.rs:160:33: builtin attribute "rustc_never_type_options" not handled by `CheckAttrVisitor`
compiler/rustc_attr_parsing/src/validate_attr.rs:42:17: assertion failed: lint_attrs.contains(name)
So remove these two entries after which we will just error with `error: cannot find attribute`
r? @WaffleLapkin
While fuzzing I noticed we would now ICE in two places when encountering an empty or filled `#![rustc_never_type_options()]` attr:
compiler/rustc_passes/src/check_attr.rs:160:33: builtin attribute "rustc_never_type_options" not handled by `CheckAttrVisitor`
compiler/rustc_attr_parsing/src/validate_attr.rs:42:17: assertion failed: lint_attrs.contains(name)
So remove these two entries after which we will just error with `error: cannot find attribute`
Fix handling of weak keyword `pin`
Part of https://github.com/rust-lang/rust/issues/130494.
On main, we use `is_ident_named` to detect weak keyword `pin` which is incorrect since it doesn't account for whether the identifier in question is raw (`r#`) or not. Namely, `r#pin` should *never* be considered (yes, even if it's followed by the disambiguator `const` or `mut`). As it stands, (1) we accept more code than we should (2) we're prone to rightfully triggering internal assertions thus ICE'ing.
Just use `is_keyword`&co which do those checks (indeed, it's also used for weak keywords). Furthermore, move `Symbol` `sym::pin` to `kw::Pin` and officially mark it as weak. This doesn't have any semantic effect, it's still a `Symbol`, but it's more conventional.
For reference, on main we ICE with `assertion failed: self.eat_keyword(expr!(Pin))` on inputs like the following:
* `type X = &r#pin const ();` (type)
* `fn scope() { let _ = &r#pin mut (); }` (expr)
* `fn scope() { let &r#pin const (); }` (pat)
Moreover, on main we wrongfully accept code like `trait Trait { fn f(&r#pin mut self); }` (assuming the feature is enabled).
<sub>(No LLM was or will be used by me during the entire creation process of this PR)</sub>
On arm, only require fpregs instead of vfp2 to allow s0-s15, s0-s31, and d0-15 register classes
Add vfp2sp and fp64 unstable target features for arm as implied features of vfp2.
Fixesrust-lang/rust#159976Fixesrust-lang/rust#161826