`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)
Staticlib rename internal symbols: add COFF support
Follow-up to rust-lang/rust#156950.
`-Zstaticlib-rename-internal-symbols` now also works on COFF targets (Windows). Renaming only rewrites symbol names, so unlike hide it needs no visibility concept.
COFF objects keep their string table at the end of the file, so renames append the new names there and patch the 4-byte length prefix plus each symbol's name offset in place. Both regular and bigobj objects are handled; on i686 a leading underscore is stripped when matching against the exported set. The archive format differs (GNU ar on windows-gnu, COFF on windows-msvc) but the members are always COFF objects, so the existing archive code is unchanged.
Supported on ELF, Apple, and COFF targets. `-Zstaticlib-hide-internal-symbols` remains ELF/Apple-only and still warns on Windows.
A run-make test `staticlib-rename-internal-symbols-coff` mirrors the existing ELF and Mach-O tests.
r? @bjorn3
It encodes the `emit` behaviour, one of:
- `BugAbort`: Abort as a bug.
- `FatalAbort`: Abort as a fatal error.
- `ErrorGuaranteed`: Return an `ErrorGuaranteed` (the default).
- `()`: return `()`.
This is useful but `Diag` is very widely used and it's arguably not
useful enough to be worth the generic parameter. This commit removes it.
Benefits:
- Many fewer generic parameters, including many functions where the
genericity is entirely uninteresting. This includes every
`Diagnostic::into_diag` and `Subdiagnostic::add_to_diag`. Removes the
need for the comment about `<G>` on `trait Diagnostic`.
- No `PhantomData` in `Diag`.
- Makes bootstrapping a bit faster.
The downside is there is no longer a single `emit` method.
- Getting a `!` return type requires calling `emit_bug` or `emit_fatal`.
This only affects a few call sites.
- Getting an `ErrorGuaranteed` return type requires calling `emit_err`.
This affects a lot of call sites. (It arguably makes call sites more
self-documenting.)
- Using the wrong `emit_*` on a diagnostic causes a runtime abort, which
previously couldn't occur. Seems unlikely, but it's not impossible.
- Note: If no particular return type is needed, `emit` can be used for
any diagnostic. (Bug/fatal diagnostics will still trigger abort.)
It's now possible to get the backend features (a `Vec<String>`) when the
codegen backend is started, pass it back through `CodegenBackendInit`,
and just store it in the `Session`. This removes the need for the query.
Also:
- `WriteBackendMethods::target_machine_factory` no longer needs the
`target_features` parameter, because it's now available through the
`sess` parameter.
- `CodegenContext` no longer needs the `backend_features` field because
we can use `sess.global_backend_features` instead.
- `CodegenBackend::provide` is now a no-op for all the in-tree backends.
I haven't removed it because out-of-tree backends still rely on it.
It currently takes `&self`, which is a bit strange for an `init` method.
As a result, the Cranelift and GCC backends have to use types with
interior mutability.
This commit changes it to `&mut self`. Benefits:
- The Cranelift backend can use `Option` instead of `OnceCell` to
indicate uninit vs. init.
- The GCC backend can avoid `Mutex`, and use `bool` instead of
`AtomicBool`, which makes things much simpler. The commit also
restructures `GccCodegenBackend` to mirror `CraneliftCodegenBackend`:
just contain an `Option<BackendConfig>`, which makes the uninit vs.
init distinction foolproof. (E.g. no need to set `lto_supported` to
false and then later overwrite it with the real value.) As part of
this the `LockedTargetInfo` type is renamed `SharedTargetInfo` because
that better matches its new internals. (All this compiles both with
and without the "master" feature set.)
Session creation is currently awkward: we build a mostly-initialized
session, then use it to initialize a codegen backend, and then use the
codegen backend to finish initializing the session.
And it's not just awkward: within the Cranelift backend's `init` method
`sess.lto()` is called, which consults `sess.thin_lto_supported`,
*before* that field has been properly set! In practice it had no effect
but it's worth fixing.
This commit cleans up this mess. It introduces `EarlySession`, which
contains just four `Session` fields, the ones that are needed for
codegen backend initialization. It is now a field within `Session`, and
`Session` derefs to `EarlySession` to avoid changing a zillion
`sess.target`/`sess.opts`/etc. occurrences. `EarlySession` is passed to
`init`, which returns a `CodegenBackendInit` that contains the
backend-specific information needed to build a `Session`. (It replaces
the `replaced_intrinsics`, `fallback_intrinsics`, and
`thin_lto_supported` methods.) The `Session` can then be built in a
single step. No more `Session`/`CodegenBackend` initialization
intermingling.
A few functions that previously took a `Session` now take something
else, e.g. a `Target`. Some `Session` methods are now `EarlySession`
methods. And a new `early_lto` method is used for Cranelift's LTO check.
Simplify the `G` in `Diag<'a, G>`
The `EmissionGuarantee` trait isn't necessary, and just complicates things. Details in individual commits.
r? @oli-obk
The direct dependency from `rustc_codegen_ssa` to `rustc_mir_transform` allowed
codegen to reuse some MIR-transform code for identifying unnecessary landing
pads.
However, we can achieve the same result by calling through a hook on `TyCtxt`,
eliminating the crate dependency.
It's a trait that is used to give `Diag::emit` different return types
depending on the `G` in `Diag<'_, G>`. It works, but it's overkill.
There are only four different `G` types in practice (`BugAbort`,
`FatalAbort`, `ErrorGuaranteed`, and `()`) and having inherent `emit`
methods for each of those four concrete `Diag<'_, G>` types is good
enough.
This commit makes that change. This removes `EmissionGuarantee`
trait bounds from many places, which is nice.
Refactor the way cg_ssa handles indirect returns (returns via `sret`) — Take 2
This continues the work that @FractalFir done in rust-lang/rust#144976.
**I managed to make this work, so this confirms the original approach works and is ready to merge.**
r? workingjubilee
(assigning the same reviewer as the original PR)
# The problem
The current way `cg_ssa` handles `PassMode::Indirect` is fundamentally incompatible with the requirements of the GCC backend. This is currently worked around in a very brittle way, that breaks on ARM.
In order to function correctly, `cg_gcc` requires the `sret`(indirect return) pointer to be treated in a special way.
# The solution
This PR separates the `sret` pointer from all the other arguments, allowing each backend to decide how it wants to handle that pointer. This will allow GCC to do it's own thing, while changing nothing on the LLVM side. Currently, the PR just makes both backends preappend the sret arg, mimicking the previous behaviour.
The PR is based on this [zulip suggestion](https://rust-lang.zulipchat.com/#narrow/channel/421156-gsoc/topic/Project.3A.20Bootstrap.20of.20rustc.20with.20rustc_codegen_gcc/near/526487725).
# Assumptions I made.
The PR makes certain assumptions about the ABI handling.
1. No LLVM intrinsic returns via sret. [According to my sources](https://rust-lang.zulipchat.com/#narrow/channel/182449-t-compiler.2Fhelp/topic/Can.20LLVM.20intrinsics.20return.20via.20PassMode.3A.3AIndirect.3F), this is always true.
2. Tail calls don't currently return via `sret`. From [asking about](https://rust-lang.zulipchat.com/#narrow/channel/182449-t-compiler.2Fhelp/topic/Can.20tail.20calls.20return.20indirectly.28via.20a.20pointer.29.3F/near/532984507), it seems like the tail call handling does not currently support indirect returns. So, I did not add support for that.
3. TLS shims don't perform indirect returns, and asserts and drops also don't perform indirect returns(since they return nothing) - those assumptions seemed reasonable.
4. Inline assembly calls don't use indirect returns. I *assumed* functions like `inline_asm_call` will not need the `sret` handling code. I am not 100% sure about this, tough.
Simplify diagnostic levels
This PR separates diagnostic levels from subdiagnostic levels and does a few preliminary cleanups. Details in individual commits.
r? @oli-obk
Currently `Level` is used for both diagnostics and subdiagnostics. But
both diagnostics and subdiagnostics only use some of the levels. This
commit introduces `Sublevel` to tighten up the representation and
prevent impossible combinations.
Gate ELF code in metadata.rs for ELF only
This PR gates ELF specific code for `BinaryFormat::Elf`. With this change, fallback for PowerPC64 on AIX is no longer needed.
---------
Assisted-by: IBM Bob
The issue was discovered by IBM Bob while checking changes for other things, and I personally verified the bug. Although the fix is trivial, I ran it through IBM Bob to make sure I wasn’t missing anything.
Minimize `DiagCtxt` methods
We have `DiagCtxt`, `DiagCtxtInner`, and `DiagCtxtHandle`. They're all necessary, but the method placement is inconsistent. This commit establishes a clearer rule: methods should *not* go on `DiagCtxt` whenever possible.
Benefits:
- Simpler rule for deciding where to put a method.
- `impl Deref for DiagCtxtHandle` can be removed, including its non-standard double-reference `&&'a DiagCtxt` return value. This makes it impossible to accidentally discard a taint target by calling `handle` on a `DiagCtxtHandle`.
- Catches some places where we were calling `dcx.handle()` when `dcx` was already a handle.
r? @oli-obk
offload: automate manual clang-linker-wrapper step
automate manual clang-linker-wrapper step from https://rustc-dev-guide.rust-lang.org/offload/usage.html
extract bitcode from device.bin and then wraps it into the host module.
needs some refactoring.
r? @ZuseZ4
We have `DiagCtxt`, `DiagCtxtInner`, and `DiagCtxtHandle`. They're all
necessary, but the method placement is inconsistent. This commit
establishes a clearer rule: methods should *not* go on `DiagCtxt`
whenever possible.
Benefits:
- Simpler rule for deciding where to put a method.
- `impl Deref for DiagCtxtHandle` can be removed, including its
non-standard double-reference `&&'a DiagCtxt` return value.
This makes it impossible to accidentally discard a taint target by
calling `handle` on a `DiagCtxtHandle`.
- Catches some places where we were calling `dcx.handle()` when `dcx`
was already a handle.
Restrict LLVM inline asm location cookie usage. Fixes#150451
The parallel frontend makes the cookies nondeterministic in their current form, resulting in nondeterministic outputs when bitcode is emitted or LTO is used.
Causes minor diagnostic regression for inline asm in release builds. See rust-lang/rust#150451 for details.
Fixesrust-lang/rust#150451
r? bjorn3
Promote `wasm32-wasip3` to a tier 2 target
This commit updates documentation, configuration, etc, within the compiler to promote the `wasm32-wasip3` target to tier 2. This means that precompiled binaries will be made available in `rustup` for usage. This target MCP for this change is [rust-lang/compiler-team/100][mcp].
This target requires LLVM 23 which rustc recently has updated to, and then additionally requires wasi-sdk-34 which additionally uses LLVM 23 which was also updated recently. With these ingredients in place the ABI for `wasm32-wasip3` is all lined up and ready to go. These changes were all necessary to bring cooperative threading to the target in the future, but that's not quite ready in the ecosystem yet.
I've locally been testing this target and it's done well so far, but I suspect this'll need subsequent bug fixes here and there as other new issues crop up. I don't expect anything major will be necessary, however.
[mcp]: https://github.com/rust-lang/compiler-team/issues/1001
The parallel frontend makes the cookies nondeterministic in their
current form, resulting in nondeterministic outputs when bitcode is
emitted or LTO is used.
Causes minor diagnostic regression for inline asm in release builds.
This commit updates documentation, configuration, etc, within the
compiler to promote the `wasm32-wasip3` target to tier 2. This means
that precompiled binaries will be made available in `rustup` for usage.
This target MCP for this change is [rust-lang/compiler-team/100][mcp].
This target requires LLVM 23 which rustc recently has updated to, and
then additionally requires wasi-sdk-34 which additionally uses LLVM 23
which was also updated recently. With these ingredients in place the ABI
for `wasm32-wasip3` is all lined up and ready to go. These changes were
all necessary to bring cooperative threading to the target in the
future, but that's not quite ready in the ecosystem yet.
I've locally been testing this target and it's done well so far, but I
suspect this'll need subsequent bug fixes here and there as other new
issues crop up. I don't expect anything major will be necessary,
however.
[mcp]: https://github.com/rust-lang/compiler-team/issues/1001
Remove -Zsaturating-float-casts flag
I added this flag back in 2017 (rust-lang/rust#45205) to enable benchmarking of the saturating semantics when it was newly implemented and still experimental. But saturation has been the official semantics for float<->int `as` casts for years now. A flag for turning it off no longer serves any purpose, it's just `-Zplease-miscompile-casts` now.
Deduplicate `InstrumentFnAttr`
cc @pmur
Instead of having a `Default` variant (which can't be specified in the attribute, it only does on/off), use an Option to model "no attribute used".
I added this flag back in 2017 to enable benchmarking of the saturating
semantics when it was newly implemented and still experimental. But
saturation has been the official semantics for float<->int `as` casts
for years now. A flag for turning it off no longer serves any purpose,
it's just `-Zplease-miscompile-casts` now.
fix(reborrow): recursive implementation
If Reborrow finds '&'a mut T' fields where 'a is the Reborrowed type's first lifetime parameter (currently the only lifetime that is allowed to reborrow) then it inserts a Deref and borrow of the T, and likewise if it finds a 'T: Reborrow' field then the field type is recursed into.
This makes Reborrow always produce the correct borrow checking logic at the cost of most probably being inconsiderately expensive. The thinking is that performance will be a followup consideration.
r? @oli-obk
* Implement Reborrow as a recursive operation
If Reborrow finds '&'a mut T' fields then it inserts
a Deref and borrow of the T, and likewise if it finds a
'T: Reborrow' field then the field type is recursed into.
This makes Reborrow always produce the correct borrow checking logic at
the cost of most probably being inconsiderately expensive. The thinking
is that performance will be a followup consideration.
* PhantomDeref
* Simpler deref test
* Add more PhantomDeref unreachability assertions
* Write out lifetime omission
* Document ProjectionElem::PhantomDeref
* Comment half of reborrow tests
* fix PhantomDeref conflicting with AccessDepth::Shallow
* Recheck CoerceShared in borrowck TypeChecker to ensure its lifetimes make sense
* Fix rebase
* Changes... but where to?
* Typo fix
* Improve comment
* Use fully_perform_op to evaluate CoerceShared trait in borrowck
* More CoerceShared comment
* Comment rest of Reborrow tests
Co-authored-by: Oli Scherer <github35764891676564198441@oli-obk.de>
Rename dlltool helper function
It doesn't check for MinGW toolchain (`windows-gnu` or `windows-gnullvm`), but `windows-gnu` only. All the callsites use that helper to decide whether dlltool should be used.
r? @bjorn3
make `pad_i32` of `PassMode::cast` an integer
so that we can specify more than one i32 of padding. This PR only adds the functionality but does not yet use it: there should be no functional changes.
This is needed for the ABI of `Complex<{ float }>` on 32-bit powerpc. Other mechanisms, e.g. using `PassMode::prefixed` don't appear to work.
More discussion is in [#t-compiler/help > power complex abi](https://rust-lang.zulipchat.com/#narrow/channel/182449-t-compiler.2Fhelp/topic/power.20complex.20abi/with/613294420).