about summary refs log tree commit diff
path: root/compiler/rustc_abi/src/layout.rs
AgeCommit message (Collapse)AuthorLines
2025-09-29Rollup merge of #147134 - workingjubilee:remove-explicit-abialign-deref, ↵Stuart Cook-3/+3
r=Zalathar remove explicit deref of AbiAlign for most methods Much of the compiler calls functions on Align projected from AbiAlign. AbiAlign impls Deref to its inner Align, so we can simplify these away. Also, it will minimize disruption when AbiAlign is removed. For now, preserve usages that might resolve to PartialOrd or PartialEq, as those have odd inference.
2025-09-28remove explicit deref of AbiAlign for most methodsJubilee Young-3/+3
Much of the compiler calls functions on Align projected from AbiAlign. AbiAlign impls Deref to its inner Align, so we can simplify these away. Also, it will minimize disruption when AbiAlign is removed. For now, preserve usages that might resolve to PartialOrd or PartialEq, as those have odd inference.
2025-09-27compiler: remove AbiAlign inside TargetDataLayoutJubilee Young-34/+31
This maintains AbiAlign usage in public API and most of the compiler, but direct access of these fields is now in terms of Align only.
2025-08-13Remove TmpLayout in layout_of_enumZachary S-30/+9
2025-07-29Reuse `sign_extend` helperOli Scherer-2/+2
2025-07-29Pick the largest niche even if the largest niche is wrapped aroundOli Scherer-24/+58
2025-07-24Remove dead code and extend test coverage and diagnostics around itOli Scherer-10/+2
We lost the following comment during refactorings: The current code for niche-filling relies on variant indices instead of actual discriminants, so enums with explicit discriminants (RFC 2363) would misbehave.
2025-06-20compiler: Rename LayoutS to LayoutData in commentsZachary S-6/+6
2025-06-08Remove rustc's notion of "preferred" alignment AKA `__alignof`Jubilee Young-13/+7
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-03Change `tag_field` to `FieldIdx` in `Variants::Multiple`Scott McMurray-2/+2
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-04-13Initial `UnsafePinned`/`UnsafeUnpin` impl [Part 1: Libs]Sky-4/+4
2025-03-08Move coroutine layout logic to `rustc_abi`Moulins-0/+30
2025-03-08Move SIMD layout logic to `rustc_abi`Moulins-12/+85
2025-03-08Remove most manual LayoutData creations and move them to `rustc_abi`Moulins-52/+23
...either as: - methods on LayoutCalculator, for faillible operations; - constructors on LayoutData, for infaillible ones.
2025-02-28rename BackendRepr::Vector → SimdVectorRalf Jung-4/+8
2025-02-20compiler: `BackendRepr::inherent_{size,align} -> scalar_{size,align}`Jubilee Young-14/+23
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-20Remove `BackendRepr::Uninhabited`, replaced with an `uninhabited: bool` ↵Zachary S-11/+12
field in `LayoutData`. Also update comments that refered to BackendRepr::Uninhabited.
2025-02-16Move hashes from rustc_data_structure to rustc_hashes so they can be shared ↵Ben Kimock-1/+1
with rust-analyzer
2025-02-15Replace some u64 hashes with Hash64Ben Kimock-4/+5
2025-01-10exclude unsizable tail from randomization seed calculationThe 8472-13/+9
2025-01-10Foo<T> != Foo<U> under layout randomizationThe 8472-2/+35
previously field ordering was using the same seed for all instances of Foo, now we pass seed values through the layout tree so that not only the struct itself affects layout but also its fields
2024-12-18make no-variant types a dedicated Variants variantRalf Jung-9/+10
2024-12-18Variants::Single: do not use invalid VariantIdx for uninhabited enumsRalf Jung-7/+7
2024-10-29compiler: `rustc_abi::Abi` => `BackendRepr`Jubilee Young-51/+53
The initial naming of "Abi" was an awful mistake, conveying wrong ideas about how psABIs worked and even more about what the enum meant. It was only meant to represent the way the value would be described to a codegen backend as it was lowered to that intermediate representation. It was never meant to mean anything about the actual psABI handling! The conflation is because LLVM typically will associate a certain form with a certain ABI, but even that does not hold when the special cases that actually exist arise, plus the IR annotations that modify the ABI. Reframe `rustc_abi::Abi` as the `BackendRepr` of the type, and rename `BackendRepr::Aggregate` as `BackendRepr::Memory`. Unfortunately, due to the persistent misunderstandings, this too is now incorrect: - Scattered ABI-relevant code is entangled with BackendRepr - We do not always pre-compute a correct BackendRepr that reflects how we "actually" want this value to be handled, so we leave the backend interface to also inject various special-cases here - In some cases `BackendRepr::Memory` is a "real" aggregate, but in others it is in fact using memory, and in some cases it is a scalar! Our rustc-to-backend lowering code handles this sort of thing right now. That will eventually be addressed by lifting duplicated lowering code to either rustc_codegen_ssa or rustc_target as appropriate.
2024-10-28Rollup merge of #132255 - workingjubilee:layout-is-🏚️, r=compiler-errorsJubilee-2/+2
Add `LayoutS::is_uninhabited` and use it Use accessors for the things that accessors are good at: reducing everyone's need to be nosy and peek at the internals of every data structure.
2024-10-28compiler: Add `is_uninhabited` and use LayoutS accessorsJubilee Young-2/+2
This reduces the need of the compiler to peek on the fields of LayoutS.
2024-10-27compiler: Rename LayoutS to LayoutDataJubilee Young-21/+21
The last {UninternedType}S is in captivity. The galaxy is at peace.
2024-10-21Make rustc_abi compile on stable againLukas Wirth-0/+2
2024-10-20compiler: Reject impossible reprs during enum layoutJubilee Young-0/+9
2024-10-19compiler: Adopt rust-analyzer impls for `LayoutCalculatorError`Jubilee Young-1/+26
2024-10-11compiler: Wire `{TyAnd,}Layout` into `rustc_abi`Jubilee Young-0/+4
This finally unites TyAndLayout, Layout, and LayoutS into the same crate, as one might imagine they would be placed. No functional changes.
2024-09-22Reformat using the new identifier sorting from rustfmtMichael Goulet-1/+1
2024-09-18Get rid of niche selection's dependence on fields's orderAdwin White-9/+4
2024-09-17get rid of an old hackLukas Markeffsky-1/+5
For structs that cannot be unsized, the layout algorithm sometimes moves unsized fields to the end of the struct, which circumvented the error for unexpected unsized fields and returned an unsized layout anyway. This commit makes it so that the unexpected unsized error is always returned for structs that cannot be unsized, allowing us to remove an old hack and fixing some old ICE.
2024-09-17assert that unexpectedly unsized fields are sized in the param envLukas Markeffsky-27/+34
2024-09-16layout computation: eagerly error for unexpected unsized fieldsLukas Markeffsky-918/+939
2024-08-31inhibit layout randomization for BoxThe 8472-4/+7
2024-07-29Reformat `use` declarations.Nicholas Nethercote-5/+4
The previous commit updated `rustfmt.toml` appropriately. This commit is the outcome of running `x fmt --all` with the new formatting options.
2024-07-04Rollup merge of #123043 - GoldsteinE:fix/repr-c-dead-branches, r=oli-obkMatthias Krüger-2/+2
Disable dead variant removal for `#[repr(C)]` enums. This prevents removing dead branches from a `#[repr(C)]` enum (they now get discriminants allocated as if they were inhabited). Implementation notes: ABI of something like ```rust #[repr(C)] enum Foo { Foo(!), } ``` is still `Uninhabited`, but its layout is now computed as if all the branches were inhabited. This seemed to me like a proper way to do it, especially given that ABI sanity check explicitly asserts that type-level uninhabitedness implies ABI uninhabitedness. This probably needs some sort of FCP (given that it changes `#[repr(C)]` layout, which is a stable guarantee), but I’m not sure how to call for one or which team is the most relevant. See https://github.com/rust-lang/unsafe-code-guidelines/issues/500.
2024-06-28Disable dead variant removal for `#[repr(C)]` enums.Goldstein-2/+2
See https://github.com/rust-lang/unsafe-code-guidelines/issues/500.
2024-05-21don't inhibit random field reordering on repr(packed(1))Ralf Jung-4/+6
2024-05-18Temporarily revert to NonZeroUsize in rustc-abi to fix building on stableLaurențiu Nicola-4/+3
2024-05-08Use generic `NonZero`.Markus Reiter-3/+4
2024-04-28Rename `inihibit_union_abi_opt()` to `inihibits_union_abi_opt()`Gurinder Singh-1/+1
The present tense makes it read more naturally at use site i.e. "this repr _inhibits_ optimizations"
2024-03-13Auto merge of #121668 - erikdesjardins:commonprim, r=scottmcm,oli-obkbors-6/+28
Represent `Result<usize, Box<T>>` as ScalarPair(i64, ptr) This allows types like `Result<usize, std::io::Error>` (and integers of differing sign, e.g. `Result<u64, i64>`) to be passed in a pair of registers instead of through memory, like `Result<u64, u64>` or `Result<Box<T>, Box<U>>` are today. Fixes #97540. r? `@ghost`
2024-03-05Change message type in bug functions.Nicholas Nethercote-2/+5
From `impl Into<DiagnosticMessage>` to `impl Into<Cow<'static, str>>`. Because these functions don't produce user-facing output and we don't want their strings to be translated.
2024-02-28simplify common prim computationErik Desjardins-16/+9
2024-02-27allow using scalarpair with a common prim of ptr/ptr-sized-intErik Desjardins-6/+35
2024-02-26fix some references to no-longer-existing ReprOptions.layout_seedRalf Jung-1/+1
2023-12-16Extract fn layout_of_structJubilee Young-102/+130