about summary refs log tree commit diff
path: root/compiler/rustc_codegen_ssa
AgeCommit message (Collapse)AuthorLines
2024-03-24Rollup merge of #122937 - Zalathar:unbox, r=oli-obkMatthias Krüger-7/+7
Unbox and unwrap the contents of `StatementKind::Coverage` The payload of coverage statements was historically a structure with several fields, so it was boxed to avoid bloating `StatementKind`. Now that the payload is a single relatively-small enum, we can replace `Box<Coverage>` with just `CoverageKind`. This patch also adds a size assertion for `StatementKind`, to avoid accidentally bloating it in the future. ``@rustbot`` label +A-code-coverage
2024-03-23Add+Use `mir::BinOp::Cmp`Scott McMurray-0/+31
2024-03-23Rollup merge of #122879 - maurer:callsite-instances, r=workingjubileeJubilee-15/+39
CFI: Strip auto traits off Virtual calls We already use `Instance` at declaration sites when available to glean additional information about possible abstractions of the type in use. This does the same when possible at callsites as well. The primary purpose of this change is to allow CFI to alter how it generates type information for indirect calls through `Virtual` instances. This is needed for the "separate machinery" version of my approach to the vtable issues (#122573), because we need to respond differently to a `Virtual` call to the same type as a non-virtual call, specifically [stripping auto traits off the receiver's `Self`](https://github.com/rust-lang/rust/pull/122573/commits/54b15b0c36d4638167732a0542ed0e34ecf17d7c) because there isn't a separate vtable for `Foo` vs `Foo + Send`. This would also make a more general underlying mechanism that could be used by rcvalle's [proposed drop detection / encoding](https://github.com/rust-lang/rust/pull/116404/commits/edcd1e20a1a69a8590d8ca47b31634854a40e3fb) if we end up using his approach, as we could condition out on the `def_id` in the CFI code rather than requiring the generating code to explicitly note whether it was calling drop.
2024-03-23Fixed bad formattingAdam Gastineau-4/+2
2024-03-23Fixed builds with modified libcAdam Gastineau-3/+3
2024-03-23CFI: Use Instance at callsitesMatthew Maurer-15/+39
We already use `Instance` at declaration sites when available to glean additional information about possible abstractions of the type in use. This does the same when possible at callsites as well. The primary purpose of this change is to allow CFI to alter how it generates type information for indirect calls through `Virtual` instances.
2024-03-23refactor check_{lang,library}_ub: use a single intrinsic, put policy into ↵Ralf Jung-2/+1
library
2024-03-23Auto merge of #122582 - scottmcm:swap-intrinsic-v2, r=oli-obkbors-2/+90
Let codegen decide when to `mem::swap` with immediates Making `libcore` decide this is silly; the backend has so much better information about when it's a good idea. Thus this PR introduces a new `typed_swap` intrinsic with a fallback body, and replaces that fallback implementation when swapping immediates or scalar pairs. r? oli-obk Replaces #111744, and means we'll never need more libs PRs like #111803 or #107140
2024-03-23rename MIR int2ptr casts to match library nameRalf Jung-1/+1
2024-03-23Unbox and unwrap the contents of `StatementKind::Coverage`Zalathar-7/+7
The payload of coverage statements was historically a structure with several fields, so it was boxed to avoid bloating `StatementKind`. Now that the payload is a single relatively-small enum, we can replace `Box<Coverage>` with just `CoverageKind`. This patch also adds a size assertion for `StatementKind`, to avoid accidentally bloating it in the future.
2024-03-22Auto merge of #122852 - compiler-errors:raw-ptr, r=lcnrbors-15/+7
Remove `TypeAndMut` from `ty::RawPtr` variant, make it take `Ty` and `Mutability` Pretty much mechanically converting `ty::RawPtr(ty::TypeAndMut { ty, mutbl })` to `ty::RawPtr(ty, mutbl)` and its fallout. r? lcnr cc rust-lang/types-team#124
2024-03-22Auto merge of #122580 - saethlin:compiler-builtins-can-panic, r=pnkfelixbors-11/+57
"Handle" calls to upstream monomorphizations in compiler_builtins This is pretty cooked, but I think it works. compiler-builtins has a long-standing problem that at link time, its rlib cannot contain any calls to `core`. And yet, in codegen we _love_ inserting calls to symbols in `core`, generally from various panic entrypoints. I intend this PR to attack that problem as completely as possible. When we generate a function call, we now check if we are generating a function call from `compiler_builtins` and whether the callee is a function which was not lowered in the current crate, meaning we will have to link to it. If those conditions are met, actually generating the call is asking for a linker error. So we don't. If the callee diverges, we lower to an abort with the same behavior as `core::intrinsics::abort`. If the callee does not diverge, we produce an error. This means that compiler-builtins can contain panics, but they'll SIGILL instead of panicking. I made non-diverging calls a compile error because I'm guessing that they'd mostly get into compiler-builtins by someone making a mistake while working on the crate, and compile errors are better than linker errors. We could turn such calls into aborts as well if that's preferred.
2024-03-22Programmatically convert some of the pat ctorsMichael Goulet-3/+3
2024-03-22Ty::new_ref and Ty::new_ptr stop using TypeAndMutMichael Goulet-8/+3
2024-03-22Eagerly convert some ctors to use their specialized ctorsMichael Goulet-4/+1
2024-03-22Don't emit an error about failing to produce a file with a specific nameMichael Baikov-1/+1
If user never gave an explicit name
2024-03-22Codegen const panic messages as function callsMark Rousskov-4/+2
This skips emitting extra arguments at every callsite (of which there can be many). For a librustc_driver build with overflow checks enabled, this cuts 0.7MB from the resulting binary.
2024-03-21Auto merge of #122830 - matthiaskrgr:rollup-uk2by3f, r=matthiaskrgrbors-7/+0
Rollup of 8 pull requests Successful merges: - #122402 (Make `#[diagnostic::on_unimplemented]` format string parsing more robust) - #122644 (pattern analysis: add a custom test harness) - #122733 (Strip placeholders from hidden types before remapping generic parameter) - #122752 (Interpolated cleanups) - #122771 (add some comments to hir::ModuleItems) - #122793 (Implement macro-based deref!() syntax for deref patterns) - #122810 (Remove `target_override`) - #122827 (Remove unnecessary braces from `bug`/`span_bug`) r? `@ghost` `@rustbot` modify labels: rollup
2024-03-20Add a testBen Kimock-4/+8
2024-03-21Remove `CodegenBackend::target_override`.Nicholas Nethercote-7/+0
Backend and target selection is a mess: the target can override the backend (via `Target::default_codegen_backend`), *and* the backend can override the target (via `CodegenBackend::target_override`). The code that handles this is ugly. It calls `build_target_config` twice, once before getting the backend and once again afterward. It also must check that both overrides aren't triggering at the same time. This commit removes the latter override. It's used in rust-gpu but @eddyb said via Zulip that removing it would be ok. This simplifies the code greatly, and will allow some nice follow-up refactorings.
2024-03-20Update comment and remove special-case for Wasm targets which is ↵Douglas Young-7/+1
incompatible with response-file changes
2024-03-20Use MSVC-style escaping when passing a response/@ file to lld on windowsDouglas Young-6/+11
LLD parses @ files like the command arguments on the platform it's on, so on windows it needs to follow the MSVC style to work correctly. Otherwise builds can fail if the linker command gets too long and the build path contains spaces.
2024-03-19Rollup merge of #122691 - veera-sivarajan:bugfix-121099, r=AmanieuMatthias Krüger-17/+29
Fix ICE: `global_asm!()` Don't Panic When Unable to Evaluate Constant Fixes #121099 A bit of an inelegant fix but given that the error is created only after call to `const_eval_poly()` and that the calling function cannot propagate the error anywhere else, the error has to be explicitly handled inside `mono_item.rs`. r? `@Amanieu`
2024-03-19Remove all checks of `IntrinsicDef::must_be_overridden` except for the ↵Oli Scherer-4/+0
actual overrides in codegen
2024-03-19Make ptr_guaranteed_cmp a rustc_intrinsic and favor its body over backends ↵Oli Scherer-7/+0
implementing it
2024-03-18Support for visionOSAdam Gastineau-1/+9
2024-03-19Auto merge of #122055 - compiler-errors:stabilize-atb, r=oli-obkbors-1/+1
Stabilize associated type bounds (RFC 2289) This PR stabilizes associated type bounds, which were laid out in [RFC 2289]. This gives us a shorthand to express nested type bounds that would otherwise need to be expressed with nested `impl Trait` or broken into several `where` clauses. ### What are we stabilizing? We're stabilizing the associated item bounds syntax, which allows us to put bounds in associated type position within other bounds, i.e. `T: Trait<Assoc: Bounds...>`. See [RFC 2289] for motivation. In all position, the associated type bound syntax expands into a set of two (or more) bounds, and never anything else (see "How does this differ[...]" section for more info). Associated type bounds are stabilized in four positions: * **`where` clauses (and APIT)** - This is equivalent to breaking up the bound into two (or more) `where` clauses. For example, `where T: Trait<Assoc: Bound>` is equivalent to `where T: Trait, <T as Trait>::Assoc: Bound`. * **Supertraits** - Similar to above, `trait CopyIterator: Iterator<Item: Copy> {}`. This is almost equivalent to breaking up the bound into two (or more) `where` clauses; however, the bound on the associated item is implied whenever the trait is used. See #112573/#112629. * **Associated type item bounds** - This allows constraining the *nested* rigid projections that are associated with a trait's associated types. e.g. `trait Trait { type Assoc: Trait2<Assoc2: Copy>; }`. * **opaque item bounds (RPIT, TAIT)** - This allows constraining associated types that are associated with the opaque without having to *name* the opaque. For example, `impl Iterator<Item: Copy>` defines an iterator whose item is `Copy` without having to actually name that item bound. The latter three are not expressible in surface Rust (though for associated type item bounds, this will change in #120752, which I don't believe should block this PR), so this does represent a slight expansion of what can be expressed in trait bounds. ### How does this differ from the RFC? Compared to the RFC, the current implementation *always* desugars associated type bounds to sets of `ty::Clause`s internally. Specifically, it does *not* introduce a position-dependent desugaring as laid out in [RFC 2289], and in particular: * It does *not* desugar to anonymous associated items in associated type item bounds. * It does *not* desugar to nested RPITs in RPIT bounds, nor nested TAITs in TAIT bounds. This position-dependent desugaring laid out in the RFC existed simply to side-step limitations of the trait solver, which have mostly been fixed in #120584. The desugaring laid out in the RFC also added unnecessary complication to the design of the feature, and introduces its own limitations to, for example: * Conditionally lowering to nested `impl Trait` in certain positions such as RPIT and TAIT means that we inherit the limitations of RPIT/TAIT, namely lack of support for higher-ranked opaque inference. See this code example: https://github.com/rust-lang/rust/pull/120752#issuecomment-1979412531. * Introducing anonymous associated types makes traits no longer object safe, since anonymous associated types are not nameable, and all associated types must be named in `dyn` types. This last point motivates why this PR is *not* stabilizing support for associated type bounds in `dyn` types, e.g, `dyn Assoc<Item: Bound>`. Why? Because `dyn` types need to have *concrete* types for all associated items, this would necessitate a distinct lowering for associated type bounds, which seems both complicated and unnecessary compared to just requiring the user to write `impl Trait` themselves. See #120719. ### Implementation history: Limited to the significant behavioral changes and fixes and relevant PRs, ping me if I left something out-- * #57428 * #108063 * #110512 * #112629 * #120719 * #120584 Closes #52662 [RFC 2289]: https://rust-lang.github.io/rfcs/2289-associated-type-bounds.html
2024-03-18Fix ICE: `global_asm!()` Don't Panic When Unable to Evaluate ConstantVeera-17/+29
A bit of an inelegant fix but given that the error is created only after call to `const_eval_poly()` and that the calling function cannot propagate the error anywhere else, the error has to be explicitly handled inside `mono_item.rs`.
2024-03-18Rollup merge of #122567 - erikdesjardins:noname, r=oli-obkMatthias Krüger-1/+0
Remove fixme about LLVM basic block naming ~This may be a small perf win.~ Originally, this PR implemented the fixme, but it didn't have any measurable perf improvement. r? ``@ghost``
2024-03-18Avoid various uses of `Option<Span>` in favor of using `DUMMY_SP` in the few ↵Oli Scherer-8/+5
cases that used `None`
2024-03-17Let codegen decide when to `mem::swap` with immediatesScott McMurray-2/+90
Making `libcore` decide this is silly; the backend has so much better information about when it's a good idea. So introduce a new `typed_swap` intrinsic with a fallback body, but replace that implementation for immediates and scalar pairs.
2024-03-17make PassMode::Cast consistently copy between Rust/ABI representationErik Desjardins-3/+29
Previously, we did this slightly incorrectly for return values, and didn't do it at all for arguments.
2024-03-16Handle calls to upstream monomorphizations in compiler_builtinsBen Kimock-8/+50
2024-03-16revert changes and just delete the fixmeErik Desjardins-15/+6
Avoiding the naming didn't have any meaningful perf impact.
2024-03-15avoid naming LLVM basic blocks when fewer_names is trueErik Desjardins-7/+15
2024-03-15Auto merge of #121297 - michaelwoerister:set-pdb-alt-path, r=wesleywiserbors-0/+9
link.exe: Don't embed full path to PDB file in binary. This PR makes `rustc` unconditionally pass `/PDBALTPATH:%_PDB%` to MSVC-style linkers, causing the linker to only embed the filename of the PDB in the binary instead of the full path. This will help implement the [trim-paths RFC](https://github.com/rust-lang/rust/issues/111540) for `*-msvc` targets. Passing `/PDBALTPATH:%_PDB%` to the linker is already done by many projects that need reproducible builds and [debugger's should still be able to find the PDB](https://learn.microsoft.com/cpp/build/reference/pdbpath) if it is in the same directory as the binary. r? `@ghost` Fixes https://github.com/rust-lang/rust/issues/87825
2024-03-15Rollup merge of #121207 - chriswailes:z-external-clangrt, r=michaelwoeristerMatthias Krüger-10/+19
Add `-Z external-clangrt` This adds the unstable `-Z external-clangrt` flag that will prevent rustc from emitting linker paths for the in-tree LLVM sanitizer runtime library.
2024-03-14Rollup merge of #122212 - erikdesjardins:byval-align2, r=wesleywiserMatthias Krüger-23/+39
Copy byval argument to alloca if alignment is insufficient Fixes #122211 "Ignore whitespace" recommended.
2024-03-14Rollup merge of #117118 - bzEq:aix-linker, r=wesleywiserMatthias Krüger-10/+16
[AIX] Remove AixLinker's debuginfo() implementation AIX ld's `-s` option doesn't perfectly fit` debuginfo()`'s semantics and may unexpectedly remove metadata in shared libraries. Remove the implementation of `AixLinker` and suggest user to use `strip` utility instead.
2024-03-14Restore correct version of comment and fix logic bugChris Wailes-5/+5
2024-03-14Rollup merge of #122287 - RalfJung:simd-static-assert, r=pnkfelixMatthias Krüger-4/+5
add test ensuring simd codegen checks don't run when a static assertion failed stdarch relies on this to ensure that SIMD indices are in bounds. I would love to know why this works, but I can't figure out where codegen decides to not codegen a function if a required-const does not evaluate. `@oli-obk` `@bjorn3` do you have any idea?
2024-03-14link.exe: don't embed full path to PDB file in binary.Michael Wörister-0/+9
2024-03-13Split a complex conditional into separate statementsChris Wailes-14/+22
2024-03-13Add `-Z external-sanitizer-runtime`Chris Wailes-0/+1
This adds the unstable `-Z external-sanitizer-runtime` flag that will prevent rustc from emitting linker paths for the in-tree LLVM sanitizer runtime library.
2024-03-13Auto merge of #121421 - saethlin:smarter-mono, r=oli-obkbors-1/+20
Avoid lowering code under dead SwitchInt targets The objective of this PR is to detect and eliminate code which is guarded by an `if false`, even if that `false` is a constant which is not known until monomorphization, or is `intrinsics::debug_assertions()`. The effect of this is that we generate no LLVM IR the standard library's unsafe preconditions, when they are compiled in a build where they should be immediately optimized out. This mono-time optimization ensures that builds which disable debug assertions do not grow a linkage requirement against `core`, which compiler-builtins currently needs: https://github.com/rust-lang/rust/issues/121552 This revives the codegen side of https://github.com/rust-lang/rust/pull/91222 as planned in https://github.com/rust-lang/rust/issues/120848.
2024-03-13Auto merge of #122220 - saethlin:ppc-can-into-atomicptr, r=oli-obkbors-41/+11
Only generate a ptrtoint in AtomicPtr codegen when absolutely necessary This special case was added in this PR: https://github.com/rust-lang/rust/pull/77611 in response to this error message: ``` Intrinsic has incorrect argument type! void ({}*)* `@llvm.ppc.cfence.p0sl_s` in function rust_oom LLVM ERROR: Broken function found, compilation aborted! [RUSTC-TIMING] std test:false 20.161 error: could not compile `std` ``` But when I tried searching for more information about that intrinsic I found this: https://github.com/llvm/llvm-project/issues/55983 which is a report of someone hitting this same error and a fix was landed in LLVM, 2 years after the above Rust PR.
2024-03-12Avoid lowering code under dead SwitchInt targetsBen Kimock-1/+20
2024-03-12sess: stabilize relro-levelDavid Wood-1/+1
Signed-off-by: David Wood <david@davidtw.co>
2024-03-12Auto merge of #121644 - oli-obk:unique_static_innards2, r=RalfJung,nnethercotebors-4/+4
Ensure nested allocations in statics neither get deduplicated nor duplicated This PR generates new `DefId`s for nested allocations in static items and feeds all the right queries to make the compiler believe these are regular `static` items. I chose this design, because all other designs are fragile and make the compiler horribly complex for such a niche use case. At present this wrecks incremental compilation performance *in case nested allocations exist* (because any query creating a `DefId` will be recomputed and never loaded from the cache). This will be resolved later in https://github.com/rust-lang/rust/pull/115613 . All other statics are unaffected by this change and will not have performance regressions (heh, famous last words) This PR contains various smaller refactorings that can be pulled out into separate PRs. It is best reviewed commit-by-commit. The last commit is where the actual magic happens. r? `@RalfJung` on the const interner and engine changes fixes https://github.com/rust-lang/rust/issues/79738
2024-03-12Change `DefKind::Static` to a struct variantOli Scherer-2/+2