about summary refs log tree commit diff
path: root/compiler/rustc_abi/src
AgeCommit message (Collapse)AuthorLines
2025-07-12Simplify codegen for niche-encoded variant testsScott McMurray-1/+34
2025-07-07Auto merge of #143182 - xdoardo:more-addrspace, r=workingjubileebors-36/+259
Allow custom default address spaces and parse `p-` specifications in the datalayout string Some targets, such as CHERI, use as default an address space different from the "normal" default address space `0` (in the case of CHERI, [200 is used](https://www.cl.cam.ac.uk/techreports/UCAM-CL-TR-877.pdf)). Currently, `rustc` does not allow to specify custom address spaces and does not take into consideration [`p-` specifications in the datalayout string](https://llvm.org/docs/LangRef.html#langref-datalayout). This patch tries to mitigate these problems by allowing targets to define a custom default address space (while keeping the default value to address space `0`) and adding the code to parse the `p-` specifications in `rustc_abi`. The main changes are that `TargetDataLayout` now uses functions to refer to pointer-related informations, instead of having specific fields for the size and alignment of pointers in the default address space; furthermore, the two `pointer_size` and `pointer_align` fields in `TargetDataLayout` are replaced with an `FxHashMap` that holds info for all the possible address spaces, as parsed by the `p-` specifications. The potential performance drawbacks of not having ad-hoc fields for the default address space will be tested in this PR's CI run. r? workingjubilee
2025-07-07compiler: Parse `p-` specs in datalayout string, allow definition of custom ↵Edoardo Marangoni-36/+259
default data address space
2025-07-05use `div_ceil` instead of manual logicFolkert de Vries-2/+1
2025-07-03Remove PointerLike traitMichael Goulet-11/+1
2025-06-28move discr=varid check to layout_sanity_checkFlorian Sextl-3/+3
2025-06-28fix docs of FakeBorrowKindFlorian Sextl-5/+5
2025-06-28improve TagEncoding docsFlorian Sextl-12/+21
2025-06-25compiler: Trim the misleading C from ExternAbi::CCmse*Jubilee Young-6/+6
2025-06-24Add rust-invalid ABIMichael Goulet-0/+5
2025-06-20compiler: Rename LayoutS to LayoutData in commentsZachary S-8/+8
2025-06-12add `extern "custom"` functionsFolkert de Vries-0/+10
2025-06-08compiler: add Deref to AbiAlign to ease transitionJubilee Young-1/+9
We will want to remove many cases of `.abi`, including `.abi.thing`, so this may simplify future PRs and certainly doesn't hurt. We omit DerefMut because mutation is much rarer and localized.
2025-06-08Remove rustc's notion of "preferred" alignment AKA `__alignof`Jubilee Young-61/+53
In PR 90877 T-lang decided not to remove `intrinsics::pref_align_of`. However, the intrinsic and its supporting code 1. is a nightly feature, so can be removed at compiler/libs discretion 2. requires considerable effort in the compiler to support, as it necessarily complicates every single site reasoning about alignment 3. has been justified based on relevance to codegen, but it is only a requirement for C++ (not C, not Rust) stack frame layout for AIX, in ways Rust would not consider even with increased C++ interop 4. is only used by rustc to overalign some globals, not correctness 5. can be adequately replaced by other rules for globals, as it mostly affects alignments for a few types under 16 bytes of alignment 6. has only one clear benefactor: automating C -> Rust translation for GNU extensions like `__alignof` 7. such code was likely intended to be `alignof` or `_Alignof`, because the GNU extension is a "false friend" of the C keyword, which makes the choice to support such a mapping very questionable 8. makes it easy to do incorrect codegen in the compiler by its mere presence as usual Rust rules of alignment (e.g. `size == align * N`) do not hold with preferred alignment The implementation is clearly damaging the code quality of the compiler. Thus it is within the compiler team's purview to simply rip it out. If T-lang wishes to have this intrinsic restored for c2rust's benefit, it would have to use a radically different implementation that somehow does not cause internal incorrectness. Until then, remove the intrinsic and its supporting code, as one tool and an ill-considered GCC extension cannot justify risking correctness. Because we touch a fair amount of the compiler to change this at all, and unfortunately the duplication of AbiAndPrefAlign is deep-rooted, we keep an "AbiAlign" type which we can wean code off later.
2025-06-07Rollup merge of #142140 - workingjubilee:sort-extern-abi-variants, r=bjorn3Guillaume Gomez-36/+63
compiler: Sort and doc ExternAbi variants My personal brainworms found this ordering made the most sense while writing the CanonAbi PR. It is *an* ordering, at least, unlike the current mess. There has been no particular reason for the previous order ever since rust-lang/rust#136901, despite the comment I delete here. I just didn't change it. Because I feel weird just fussing with variant ordering in the source definition, I also documented a bunch to the best of my ability.
2025-06-06compiler: Remove superfluous renaming import of ExternAbiJubilee Young-3/+1
2025-06-06compiler: Sort and doc ExternAbi variantsJubilee Young-33/+62
2025-06-06Rollup merge of #142103 - scottmcm:fieldidx-in-interp, r=oli-obkGuillaume Gomez-2/+9
Update `InterpCx::project_field` to take `FieldIdx` As suggested by Ralf in https://github.com/rust-lang/rust/pull/142005#discussion_r2125839015
2025-06-06Update compiler/rustc_abi/src/layout/ty.rsscottmcm-1/+1
Co-authored-by: Ralf Jung <post@ralfj.de>
2025-06-05Update `InterpCx::project_field` to take `FieldIdx`Scott McMurray-2/+9
As suggested by Ralf in 142005.
2025-06-05canon_abi: make to_erased_extern_abi just a detail in formattingRalf Jung-13/+6
2025-06-03Change `tag_field` to `FieldIdx` in `Variants::Multiple`Scott McMurray-5/+5
It was already available as a generic parameter anyway, and it's not like we'll ever put a tag in the 5-billionth field.
2025-06-03compiler: use CanonAbi for entry_abiJubilee Young-1/+1
makes entry_abi a lowering of the ABI string, so now it can be ```json "entry_abi": "C", "entry_abi": "win64", "entry_abi": "aapcs", ```
2025-05-31compiler: add CanonAbiJubilee Young-7/+149
2025-04-13Initial `UnsafePinned`/`UnsafeUnpin` impl [Part 1: Libs]Sky-4/+4
2025-04-09Remove redundant wordstimesince-1/+1
2025-04-06remove compiler support for `extern "rust-intrinsic"` blocksSkgland-3/+1
2025-03-29`BackendRepr::is_signed`: comment why this may panicsLieselotte-1/+2
2025-03-15Use {Decodable,Encodable}_NoContext in type_irMichael Goulet-7/+25
2025-03-13Auto merge of #137152 - saethlin:bss-const-allocs, r=wesleywiserbors-2/+2
Add a .bss-like scheme for encoded const allocs This check if all bytes are zero feel like it should be too slow, and instead we should have a flag that we track, but that seems hard. Let's see how this perfs first. Also we can probably stash the "it's all zero actually" flag inside one of the other struct members that's already not using an entire byte. This optimization doesn't fire all that often, so it's possible that by sticking it in the varint length field, this PR actually makes rmeta size worse.
2025-03-11Remove `#![warn(unreachable_pub)]` from all `compiler/` crates.Nicholas Nethercote-1/+0
It's no longer necessary now that `-Wunreachable_pub` is being passed.
2025-03-10Revert "Use workspace lints for crates in `compiler/` #138084"许杰友 Jieyou Xu (Joe)-0/+1
Revert <https://github.com/rust-lang/rust/pull/138084> to buy time to consider options that avoids breaking downstream usages of cargo on distributed `rustc-src` artifacts, where such cargo invocations fail due to inability to inherit `lints` from workspace root manifest's `workspace.lints` (this is only valid for the source rust-lang/rust workspace, but not really the distributed `rustc-src` artifacts). This breakage was reported in <https://github.com/rust-lang/rust/issues/138304>. This reverts commit 48caf81484b50dca5a5cebb614899a3df81ca898, reversing changes made to c6662879b27f5161e95f39395e3c9513a7b97028.
2025-03-09Rollup merge of #138158 - moulins:move-layout-to-rustc_abi, r=workingjubileeMatthias Krüger-101/+614
Move more layouting logic to `rustc_abi` Move all `LayoutData`-constructing code to `rustc_abi`: - Infaillible operations get a new `LayoutData` constructor method; - Faillible ones get a new method on `LayoutCalculator`.
2025-03-08Move coroutine layout logic to `rustc_abi`Moulins-0/+350
2025-03-08Move SIMD layout logic to `rustc_abi`Moulins-12/+98
2025-03-08Remove most manual LayoutData creations and move them to `rustc_abi`Moulins-94/+171
...either as: - methods on LayoutCalculator, for faillible operations; - constructors on LayoutData, for infaillible ones.
2025-03-08Remove `#![warn(unreachable_pub)]` from all `compiler/` crates.Nicholas Nethercote-1/+0
(Except for `rustc_codegen_cranelift`.) It's no longer necessary now that `unreachable_pub` is in the workspace lints.
2025-03-06Rollup merge of #137805 - RalfJung:layout-debug-print, r=NoratriebMichael Goulet-1/+1
adjust Layout debug printing to match the internal field name The field got renamed a while ago, but the debug printing was not updated to match.
2025-03-04compiler: add `ExternAbi::is_rustic_abi`Jubilee Young-0/+11
2025-02-28rename BackendRepr::Vector → SimdVectorRalf Jung-20/+24
2025-02-28adjust Layout debug printing to match the internal field namesRalf Jung-1/+1
2025-02-23Rollup merge of #137334 - compiler-errors:edition-2024-fresh-2, ↵Jacob Pratt-1/+1
r=saethlin,traviscross Greatly simplify lifetime captures in edition 2024 Remove most of the `+ Captures` and `+ '_` from the compiler, since they are now unnecessary with the new edition 2021 lifetime capture rules. Use some `+ 'tcx` and `+ 'static` rather than being overly verbose with precise capturing syntax.
2025-02-23Rollup merge of #137256 - workingjubilee:untangle-vector-abi-assumptions, ↵Matthias Krüger-59/+73
r=bjorn3,RalfJung compiler: untangle SIMD alignment assumptions There were a number of puzzling assumptions being made about SIMD types and their layout that I have corrected in this diff. These are mostly no-op edits in actual fact, but they do subtly alter a pair of checks in our invariant-checking and union layout computation that rested on those peculiar assumptions. Those unfortunately stand in the way of any further actual fixes. I submit this for review, even though it's not clearly motivated without its followups, because it should still be possible to independently conclude whether this is correct.
2025-02-22Greatly simplify lifetime captures in edition 2024Michael Goulet-1/+1
2025-02-22Fix binding mode problemsMichael Goulet-9/+9
2025-02-20compiler: split vector_align into cabi and llvmlikeJubilee Young-10/+15
Introduce a pair of functions that actually describe what they do, because it wasn't clear the alignment is sometimes a forgery.
2025-02-20compiler: `BackendRepr::inherent_{size,align} -> scalar_{size,align}`Jubilee Young-40/+50
This pair of fn was introduced to perform invariant checks for scalars. Their current behavior doesn't mesh as well with checking SIMD types, so change the name of the fn to reflect their actual use-case and refactor the corresponding checks. Also simplify the returns from Option<AbiAndPrefAlign> to Option<Align>, because every site was mapping away the "preferred" alignment anyways.
2025-02-20compiler: Align::max_for_offset -> Align::max_aligned_factorJubilee Young-9/+8
No functional changes.
2025-02-20Adjust LayoutData::uninhabited doc comment.zachs18-2/+2
Co-authored-by: Jubilee <workingjubilee@gmail.com>
2025-02-20Remove `BackendRepr::Uninhabited`, replaced with an `uninhabited: bool` ↵Zachary S-32/+28
field in `LayoutData`. Also update comments that refered to BackendRepr::Uninhabited.