summary refs log tree commit diff
path: root/compiler/rustc_abi/src/layout.rs
AgeCommit message (Collapse)AuthorLines
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
2023-12-16Extract fn layout_of_enumJubilee Young-476/+496
2023-12-16Manually inline scalar_unitJubilee Young-7/+3
2023-12-16Hoist fn absentJubilee Young-12/+18
2023-12-15Annotate panic! reasons during enum layoutJubilee Young-6/+14
Add some reasons to the panics, and use more exhaustive matches.
2023-12-02Rename `LayoutCalculator::delay_bug` as `LayoutCalculator::delayed_bug`.Nicholas Nethercote-3/+3
To match with the previous commits.
2023-11-21Fix `clippy::needless_borrow` in the compilerNilstrieb-3/+3
`x clippy compiler -Aclippy::all -Wclippy::needless_borrow --fix`. Then I had to remove a few unnecessary parens and muts that were exposed now.
2023-11-05Make the randomize feature of rustc_abi additivehkalbasi-3/+2
2023-10-27fix failure to detect a too-big-type after adding paddingRalf Jung-0/+5
2023-10-04Remove unnecessary features from rustc_abiLukas Wirth-0/+1
2023-10-02Fix incorrect inlining of RangeInclusive::size_hintLukas Wirth-1/+1
2023-10-02Add VariantIdx backLukas Wirth-27/+55
2023-10-02Bring back generic FieldIdxLukas Wirth-84/+89
2023-10-02Unglob rustc_abi importsLukas Wirth-8/+10
2023-10-02Name some local variables more consistently.Nicholas Nethercote-6/+6
By making every `alt_foo` exactly match a `foo`.
2023-10-01Minor comment and whitespace tweaks.Nicholas Nethercote-32/+32
2023-08-29there seems to be no reason to treat ZST specially in these casesRalf Jung-12/+2
2023-08-29rustc_abi: audit uses of is_zst; fix a case of giving an enum insufficient ↵Ralf Jung-7/+18
alignment
2023-07-30inline format!() args up to and including rustc_middleMatthias Krüger-5/+3
2023-07-25abi: unsized field in union - assert to delay bugDavid Wood-1/+3
Unions cannot have unsized fields, and as such, layout computation for unions asserts that each union field is sized (as this would normally have halted compilation earlier). However, if a generator ends up with an unsized local - a circumstance in which an error will always have been emitted earlier, for example, if attempting to dereference a `&str` - then the generator transform will produce a union with an unsized field. Since #110107, later passes will be run, such as constant propagation, and can attempt layout computation on the generator, which will result in layout computation of `str` in the context of it being a field of a union - and so the aforementioned assertion would cause an ICE. It didn't seem appropriate to try and detect this case in the MIR body and skip this specific pass; tainting the MIR body or delaying a bug from the generator transform (or elsewhere) wouldn't prevent this either (as neither would prevent the later pass from running); and tainting when the deref of `&str` is reported, if that's possible, would unnecessarily prevent potential other errors from being reported later in compilation, and is very tailored to this specific case of getting a unsized type in a generator. Given that this circumstance can only happen when an error should have already been reported, the correct fix appears to be just changing the assert to a delayed bug. This will still assert if there is some circumstance where this occurs and no error has been reported, but it won't crash the compiler in this instance. Signed-off-by: David Wood <david@davidtw.co>
2023-07-14i686-windows: make requested alignment > 4 special case apply transitivelyErik Desjardins-22/+18
2023-07-10aarch64-linux: properly handle 128bit aligned aggregatesErik Desjardins-7/+50