summary refs log tree commit diff
path: root/compiler/rustc_abi/src/lib.rs
AgeCommit message (Collapse)AuthorLines
2025-02-11compiler: remove rustc_abi::lookup and AbiUnsupportedJubilee Young-5/+8
These can be entirely replaced by the FromStr implementation.
2025-02-11compiler: remove AbiDatasJubilee Young-8/+5
These were a way to ensure hashes were stable over time for ExternAbi, but simply hashing the strings is more stable in the face of changes. As a result, we can do away with them.
2025-02-11compiler: narrow scope of nightly cfg in rustc_abiJubilee Young-5/+1
2025-02-09compiler: gate `extern "{abi}"` in ast_loweringJubilee Young-3/+1
By moving this stability check into AST lowering, we effectively make it impossible to accidentally miss, as it must happen to generate HIR. Also, we put the ABI-stability code next to code that actually uses it! This allows code that wants to reason about backend ABI implementations to stop worrying about high-level concerns like syntax stability, while still leaving it as the authority on what ABIs actually exist. It also makes it easy to refactor things to have more consistent errors. For now, we only apply this to generalize the existing messages a bit.
2025-02-08Rustfmtbjorn3-4/+7
2025-01-10Foo<T> != Foo<U> under layout randomizationThe 8472-0/+39
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-30compiler: Add a statement-of-intent to `rustc_abi`Jubilee Young-0/+32
2024-12-18make no-variant types a dedicated Variants variantRalf Jung-4/+6
2024-12-18Variants::Single: do not use invalid VariantIdx for uninhabited enumsRalf Jung-4/+4
2024-12-01fix safe-transmute handling of enumsRalf Jung-1/+5
2024-11-30improve TagEncoding::Niche docs and sanity checkRalf Jung-5/+19
2024-11-22Auto merge of #130867 - michirakara:steps_between, r=dtolnaybors-1/+1
distinguish overflow and unimplemented in Step::steps_between
2024-11-21distinguish overflow and unimplemented in Step::steps_betweenmichirakara-1/+1
2024-11-08pointee_info_at: fix logic for recursing into enumsRalf Jung-4/+12
2024-10-30compiler: Lift `rustc_target::spec::abi::Abi` to `rustc_abi::ExternAbi`Jubilee Young-0/+8
2024-10-29compiler: `rustc_abi::Abi` => `BackendRepr`Jubilee Young-46/+66
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-0/+5
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-0/+5
This reduces the need of the compiler to peek on the fields of LayoutS.
2024-10-27compiler: Rename LayoutS to LayoutDataJubilee Young-7/+7
The last {UninternedType}S is in captivity. The galaxy is at peace.
2024-10-21Make rustc_abi compile on stable againLukas Wirth-4/+12
2024-10-11compiler: Wire `{TyAnd,}Layout` into `rustc_abi`Jubilee Young-1/+7
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-7/+4
2024-09-21Auto merge of #127546 - workingjubilee:5-level-paging-exists, r=saethlinbors-6/+4
Correct outdated object size limit The comment here about 48 bit addresses being enough was written in 2016 but was made incorrect in 2019 by 5-level paging, and then persisted for another 5 years before being noticed and corrected. The bolding of the "exclusive" part is merely to call attention to something I missed when reading it and doublechecking the math. try-job: i686-msvc try-job: test-various
2024-09-21compiler: Precisely name units of object sizeJubilee-3/+3
Co-authored-by: Ralf Jung <post@ralfj.de>
2024-09-20compiler: reuse {un,}signed_fit in get_type_suggestion (nfc)Jubilee Young-0/+22
no need for a weird macro when a self-explanatory `match` will do.
2024-09-19Correct outdated object size limitJubilee Young-6/+4
The comment here about 48 bit addresses being enough was written in 2016 but was made incorrect in 2019 by 5-level paging, and then persisted for another 5 years before being noticed and corrected.
2024-09-16layout computation: eagerly error for unexpected unsized fieldsLukas Markeffsky-1/+9
2024-09-14compiler: Document AbiAndPrefAlignJubilee Young-0/+8
2024-08-31inhibit layout randomization for BoxThe 8472-4/+11
2024-08-27ABI compat check: detect unadjusted ABI mismatchesRalf Jung-1/+3
2024-08-16Add `warn(unreachable_pub)` to several crates.Nicholas Nethercote-0/+1
It requires no additonal changes to these crates, but will prevent unnecessary `pub`s in the future.
2024-08-01interpret: simplify pointer arithmetic logicRalf Jung-3/+3
2024-07-29Reformat `use` declarations.Nicholas Nethercote-4/+3
The previous commit updated `rustfmt.toml` appropriately. This commit is the outcome of running `x fmt --all` with the new formatting options.
2024-07-16Fix unsafe_op_in_unsafe_fn in compilerMichael Goulet-2/+2
2024-07-04Rollup merge of #123043 - GoldsteinE:fix/repr-c-dead-branches, r=oli-obkMatthias Krüger-1/+1
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-1/+1
See https://github.com/rust-lang/unsafe-code-guidelines/issues/500.
2024-06-25Auto merge of #126326 - eggyal:ununsafe-StableOrd, r=michaelwoeristerbors-3/+5
Un-unsafe the `StableOrd` trait Whilst incorrect implementations of this trait can cause miscompilation, they cannot cause memory unsafety in rustc. [Discussed on Zulip](https://rust-lang.zulipchat.com/#narrow/stream/182449-t-compiler.2Fhelp/topic/Policy.20of.20.60unsafe.60.20within.20the.20compiler). cc [MCP 533](https://github.com/rust-lang/compiler-team/issues/533), #105175, `@michaelwoerister` r? `@Nilstrieb`
2024-06-22Ensure careful consideration is given by implsAlan Egerton-2/+4
Added an associated `const THIS_IMPLEMENTATION_HAS_BEEN_TRIPLE_CHECKED` to the `StableOrd` trait to ensure that implementors carefully consider whether the trait's contract is upheld, as incorrect implementations can cause miscompilations.
2024-06-12Un-unsafe the `StableOrd` traitAlan Egerton-2/+2
Whilst incorrect implementations of this trait can cause miscompilation, they cannot cause memory unsafety in rustc.
2024-06-12Use `tidy` to sort crate attributes for all compiler crates.Nicholas Nethercote-1/+3
We already do this for a number of crates, e.g. `rustc_middle`, `rustc_span`, `rustc_metadata`, `rustc_span`, `rustc_errors`. For the ones we don't, in many cases the attributes are a mess. - There is no consistency about order of attribute kinds (e.g. `allow`/`deny`/`feature`). - Within attribute kind groups (e.g. the `feature` attributes), sometimes the order is alphabetical, and sometimes there is no particular order. - Sometimes the attributes of a particular kind aren't even grouped all together, e.g. there might be a `feature`, then an `allow`, then another `feature`. This commit extends the existing sorting to all compiler crates, increasing consistency. If any new attribute line is added there is now only one place it can go -- no need for arbitrary decisions. Exceptions: - `rustc_log`, `rustc_next_trait_solver` and `rustc_type_ir_macros`, because they have no crate attributes. - `rustc_codegen_gcc`, because it's quasi-external to rustc (e.g. it's ignored in `rustfmt.toml`).
2024-05-21don't inhibit random field reordering on repr(packed(1))Ralf Jung-11/+4
2024-05-18Temporarily revert to NonZeroUsize in rustc-abi to fix building on stableLaurențiu Nicola-2/+2
2024-05-11Make `index_by_increasing_offset` return one item for primitivesScott McMurray-1/+6
2024-05-11Unify `Rvalue::Aggregate` paths in cg_ssaScott McMurray-1/+1
2024-05-10Rollup merge of #124797 - beetrees:primitive-float, r=davidtwcoMatthias Krüger-12/+38
Refactor float `Primitive`s to a separate `Float` type Now there are 4 of them, it makes sense to refactor `F16`, `F32`, `F64` and `F128` out of `Primitive` and into a separate `Float` type (like integers already are). This allows patterns like `F16 | F32 | F64 | F128` to be simplified into `Float(_)`, and is consistent with `ty::FloatTy`. As a side effect, this PR also makes the `Ty::primitive_size` method work with `f16` and `f128`. Tracking issue: #116909 `@rustbot` label +F-f16_and_f128
2024-05-08Use generic `NonZero`.Markus Reiter-2/+2
2024-05-06Refactor float `Primitive`s to a separate `Float` typebeetrees-12/+38
2024-05-03Rollup merge of #124555 - Zalathar:init-coverage, r=nnethercoteMatthias Krüger-0/+2
coverage: Clean up creation of MC/DC condition bitmaps This PR improves the code for creating and initializing [MC/DC](https://en.wikipedia.org/wiki/Modified_condition/decision_coverage) condition bitmap variables, as introduced by #123409 and modified by #124255. - The condition bitmap variables are now created eagerly at the start of per-function codegen, via a new `init_coverage` method in `CoverageInfoBuilderMethods`. This avoids having to retroactively create the bitmaps while doing codegen for an individual coverage statement. - As a result, we can now create and initialize those bitmaps using existing safe APIs, instead of having to perform our own unsafe call to `llvm::LLVMBuildAlloca`. - This PR also tweaks the way we count the number of condition bitmaps needed, by tracking the total number of bitmaps needed (max depth + 1), instead of only tracking the maximum depth. This reduces the potential for subtle off-by-one confusion.
2024-05-01Align: add bytes_usize and bits_usizeRalf Jung-0/+10
2024-05-01coverage: Set up MC/DC bitmaps without additional unsafe codeZalathar-0/+2
Because this now always takes place at the start of the function, we can just use the normal `alloca` method and then initialize each bitmap immediately. This patch also moves bitmap setup out of the `mcdc_parameters` method, because there is no longer any particular reason for it to be there.