Commit Graph

4131 Commits

Author SHA1 Message Date
James Barford-Evans
af2f1f375c use ConstExt for methods that do not yet exist in rustc_type_ir 2026-09-22 13:04:44 +01:00
Jonathan Brouwer
e1b8be29ff Rollup merge of #160859 - Jamesbarford:feat/fb16-pt1, r=folkertdev,tgross35
`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)
2026-09-21 15:19:23 +02:00
Jonathan Brouwer
2b1343d4a8 Rollup merge of #160679 - cezarbbb:staticlib-rename-coff, r=bjorn3
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
2026-09-21 15:19:22 +02:00
Jonathan Brouwer
a7be2941de Rollup merge of #163083 - nnethercote:rm-Diag-G, r=oli-obk
Remove `G` generic param from `Diag<'_, G>`

The benefits are outweighed by the costs. Details in invidual commits.

some minor earlier discussion about this change in https://github.com/rust-lang/rust/pull/162630#discussion_r3988468478
2026-09-21 15:19:21 +02:00
James Barford-Evans
c56a9917d8 Wire up f16b in backends 2026-09-21 08:57:52 +01:00
James Barford-Evans
cdde2f00b5 Add F16B to Float enum & wireup trivial matches 2026-09-21 08:57:51 +01:00
Nicholas Nethercote
30b8dfc353 Remove G generic param from Diag<'_, G>
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.)
2026-09-21 09:57:42 +10:00
Nicholas Nethercote
23ba1fae5f Convert create_err(e).emit() occurrences to emit_err(e) 2026-09-21 09:57:26 +10:00
bjorn3
27ed2eda12 Introduce LockedDir type 2026-09-18 12:10:15 +02:00
cezarbbb
f330047c2b Add COFF support to -Zstaticlib-rename-internal-symbols 2026-09-18 10:36:09 +08:00
Nicholas Nethercote
8515e12560 Remove global_backend_features query
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.
2026-09-16 15:29:44 +10:00
Nicholas Nethercote
81210c9d79 Change CodegenBackend::init to take &mut self
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.)
2026-09-16 15:29:44 +10:00
Nicholas Nethercote
51673f89e1 Split build_session
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.
2026-09-16 15:29:42 +10:00
mejrs
6aaabbb863 compiler: fix bug and span_bug imports 2026-09-15 16:20:18 +02:00
Jonathan Brouwer
305d36bc80 Rollup merge of #162630 - nnethercote:simplify-Diag-G, r=oli-obk
Simplify the `G` in `Diag<'a, G>`

The `EmissionGuarantee` trait isn't necessary, and just complicates things. Details in individual commits.

r? @oli-obk
2026-09-14 15:16:02 +02:00
Zalathar
df15f022ef Disconnect rustc_codegen_ssa from rustc_mir_transform
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.
2026-09-12 21:59:29 +10:00
Nicholas Nethercote
09bf6de39e Remove EmissionGuarantee
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.
2026-09-12 11:21:03 +10:00
Jonathan Brouwer
7cd747decf Rollup merge of #160023 - antoyo:ssa-indirect-return, r=workingjubilee
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.
2026-09-11 12:45:02 +02:00
Jacob Pratt
d971af8b59 Rollup merge of #162514 - nnethercote:simplify-diag-Levels, r=oli-obk
Simplify diagnostic levels

This PR separates diagnostic levels from subdiagnostic levels and does a few preliminary cleanups. Details in individual commits.

r? @oli-obk
2026-09-11 00:03:10 -04:00
Nicholas Nethercote
6331ab69b4 Introduce Sublevel for errors
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.
2026-09-11 06:46:46 +10:00
Jonathan Brouwer
3532a4cefb Rollup merge of #162542 - xingxue-ibm:gate-elf-code-for-elf, r=khyperia
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.
2026-09-10 22:34:00 +02:00
Antoni Boucher
a714a9e8df Improve the new indirect return API 2026-09-09 11:29:11 -04:00
Fractal Fir(Michał Kostrubiec)
74bba56ab9 Apply suggestions from code review
Co-authored-by: Jubilee <workingjubilee@gmail.com>
2026-09-09 11:14:31 -04:00
FractalFir
e6b7dc8152 Ported cg_gcc to the new cg_ssa version 2026-09-09 11:14:31 -04:00
FractalFir
cca9f306f0 Refactored the handling of the indirect return pointer in cg_ssa to allow for more correct ABI handling in cg_gcc 2026-09-09 11:14:31 -04:00
Xing Xue
1e18d10e2b Gate ELF code in metadata.rs for ELF only. 2026-09-09 11:01:27 -04:00
Jonathan Brouwer
82ffd1cc73 Rollup merge of #162453 - nnethercote:min-DiagCtxt-methods, r=oli-obk
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
2026-09-09 15:01:30 +02:00
Jonathan Brouwer
16f306cb78 Rollup merge of #162309 - sgasho:offload-clang-linker-wrapper, r=ZuseZ4
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
2026-09-08 18:19:36 +02:00
Nicholas Nethercote
d571cae83e 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.
2026-09-08 15:25:09 +10:00
Jonathan Brouwer
f04af2086f Rollup merge of #160197 - susitsm:restrict-inline-asm-cookies, r=petrochenkov
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.

Fixes rust-lang/rust#150451

r? bjorn3
2026-09-07 17:08:07 +02:00
sgasho
f9017b1630 add rpath 2026-09-06 14:35:53 +00:00
Stuart Cook
eaa6c852f5 Rollup merge of #161940 - alexcrichton:wasip3, r=davidtwco
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
2026-09-05 23:04:49 +10:00
Matyas Susits
970cb98f0e Disable inline asm line info cookies when llvm bitcode is saved or LTO is enabled
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.
2026-09-05 11:52:40 +02:00
sgasho
c321d90e6f offload: automate manual clang-linker-wrapper step 2026-09-04 16:59:41 +00:00
Ralf Jung
e7c3734a6a make closure-like types act like MaybeDangling 2026-09-04 16:35:10 +02:00
Ralf Jung
2fa835fc72 make -Ctarget-feature warnings more explicitly FCWs 2026-09-04 08:22:14 +02:00
Alex Crichton
66d9e739ff 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
2026-09-03 07:27:00 -07:00
Jonathan Brouwer
198bd21de8 Rollup merge of #161971 - hanna-kruppe:rm-flag-satfpcast, r=RalfJung
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.
2026-09-01 21:26:14 +02:00
Jonathan Brouwer
bcaa514284 Rollup merge of #162097 - mejrs:instrumentfnattr, r=JonathanBrouwer
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".
2026-09-01 13:27:46 +02:00
Jonathan Brouwer
dbfa398db0 Rollup merge of #162075 - mejrs:track_caller_closure_gating, r=JonathanBrouwer
Move track_caller on closures gating to attribute parsing

I noticed this while reviewing rust-lang/rust#161958
2026-09-01 13:27:45 +02:00
mejrs
8717cbaa84 Deduplicate InstrumentFnAttr 2026-08-31 20:48:05 +02:00
mejrs
e18a0126ea Move track_caller on closures gating to attribute parsing 2026-08-31 19:12:19 +02:00
Folkert de Vries
178eb4b50f attach naked function target features to module assembly 2026-08-31 00:25:34 +02:00
Hanna Kruppe
c7d949d9ea Remove -Zsaturating-float-casts flag
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.
2026-08-29 13:50:44 +02:00
Jonathan Brouwer
8e3d555214 Rollup merge of #159103 - aapoalas:reborrow/fix-borrowed-place, r=oli-obk
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
2026-08-28 10:15:37 +02:00
Aapo Alasuutari
5686e56377 fix(reborrow): recursive implementation
* 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>
2026-08-27 20:03:59 +00:00
Jonathan Brouwer
f7f990ffbe Rollup merge of #161701 - mati865:dlltool-helper-rename, r=bjorn3
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
2026-08-26 17:23:21 +02:00
Ralf Jung
de2780a2a2 rename rust_target_features query to make it clear that these are *all* target features 2026-08-25 08:10:45 +02:00
Mateusz Mikuła
8f302fb281 Rename dlltool helper function 2026-08-24 23:33:09 +02:00
Jonathan Brouwer
3cc643bd77 Rollup merge of #160132 - folkertdev:pad-i32-count, 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).
2026-08-24 15:06:55 +02:00