about summary refs log tree commit diff
path: root/compiler/rustc_abi
AgeCommit message (Collapse)AuthorLines
2023-04-02Use `&IndexSlice` instead of `&IndexVec` where possibleScott McMurray-3/+3
All the same reasons as for `[T]`: more general, less pointer chasing, and `&mut IndexSlice` emphasizes that it doesn't change *length*.
2023-03-28Move `mir::Field` → `abi::FieldIdx`Scott McMurray-0/+26
The first PR for https://github.com/rust-lang/compiler-team/issues/606 This is just the move-and-rename, because it's plenty big-and-bitrotty already. Future PRs will start using `FieldIdx` more broadly, and concomitantly removing `FieldIdx::new`s.
2023-03-25Refactor: `VariantIdx::from_u32(0)` -> `FIRST_VARIANT`Scott McMurray-11/+24
Since structs are always `VariantIdx(0)`, there's a bunch of files where the only reason they had `VariantIdx` or `vec::Idx` imported at all was to get the first variant. So this uses a constant for that, and adds some doc-comments to `VariantIdx` while I'm there, since it doesn't have any today.
2023-02-23Unify validity checks into a single queryNilstrieb-8/+0
Previously, there were two queries to check whether a type allows the 0x01 or zeroed bitpattern. I am planning on adding a further initness to check, truly uninit for MaybeUninit, which would make this three queries. This seems overkill for such a small feature, so this PR unifies them into one.
2023-02-17Rollup merge of #107592 - workingjubilee:use-16-bit-enum-on-16-bit-targets, ↵Matthias Krüger-1/+3
r=WaffleLapkin Default `repr(C)` enums to `c_int` size This is what ISO C strongly implies this is correct, and many processor-specific ABIs imply or mandate this size, so "everyone" (LLVM, gcc...) defaults to emitting enums this way. However, this is by no means guaranteed by ISO C, and the bare-metal Arm targets show it can be overridden, which rustc supports via `c-enum-min-bits` in a target.json. The override is a flag named `-fshort-enums` in clang and gcc, but introducing a CLI flag is probably unnecessary for rustc. This flag can be used by non-Arm microcontroller targets, like AVR and MSP430, but it is not enabled for them by default. Rust programmers who know the size of a target's enums can use explicit reprs, which also lets them match C23 code. This change is most relevant to 16-bit targets: AVR and MSP430. Most of rustc's targets use 32-bit ints, but ILP64 does exist. Regardless, rustc should now correctly handle enums for both very small and very large targets. Thanks to William for confirming MSP430 behavior, and to Waffle for better style and no-core `size_of` asserts. Fixes rust-lang/rust#107361 Fixes rust-lang/rust#77806
2023-02-16Default repr(C) enums to c_int sizeJubilee Young-1/+3
This is what ISO C strongly implies this is correct, and many processor-specific ABIs imply or mandate this size, so "everyone" (LLVM, gcc...) defaults to emitting enums this way. However, this is by no means guaranteed by ISO C, and the bare-metal Arm targets show it can be overridden, which rustc supports via `c-enum-min-bits` in a target.json. The override is a flag named `-fshort-enums` in clang and gcc, but introducing a CLI flag is probably unnecessary for rustc. This flag can be used by non-Arm microcontroller targets, like AVR and MSP430, but it is not enabled for them by default. Rust programmers who know the size of a target's enums can use explicit reprs, which also lets them match C23 code. This change is most relevant to 16-bit targets: AVR and MSP430. Most of rustc's targets use 32-bit ints, but ILP64 does exist. Regardless, rustc should now correctly handle enums for both very small and very large targets. Thanks to William for confirming MSP430 behavior, and to Waffle for better style and no-core size_of asserts. Co-authored-by: William D. Jones <thor0505@comcast.net> Co-authored-by: Waffle Maybe <waffle.lapkin@gmail.com>
2023-02-15Rollup merge of #107163 - mikebenfield:parameters-pr, r=TaKO8KiDylan DPC-87/+130
Remove some superfluous type parameters from layout.rs. Specifically remove V, which can always be VariantIdx, and F, which can always be Layout.
2023-02-06also do not add noalias on not-Unpin BoxRalf Jung-2/+2
2023-02-06make PointerKind directly reflect pointer typesRalf Jung-15/+6
The code that consumes PointerKind (`adjust_for_rust_scalar` in rustc_ty_utils) ended up using PointerKind variants to talk about Rust reference types (& and &mut) anyway, making the old code structure quite confusing: one always had to keep in mind which PointerKind corresponds to which type. So this changes PointerKind to directly reflect the type. This does not change behavior.
2023-01-31PointeeInfo is advisory onlyRalf Jung-0/+2
2023-01-22abi: add `AddressSpace` field to `Primitive::Pointer`Erik Desjardins-10/+14
...and remove it from `PointeeInfo`, which isn't meant for this. There are still various places (marked with FIXMEs) that assume all pointers have the same size and alignment. Fixing this requires parsing non-default address spaces in the data layout string, which will be done in a followup.
2023-01-22rustc_abi: remove Primitive::{is_float,is_int}Erik Desjardins-12/+0
there were fixmes for this already i am about to remove is_ptr (since callers need to properly distinguish between pointers in different address spaces), so might as well do this at the same time
2023-01-21Remove some superfluous type parameters from layout.rs.Michael Benfield-87/+130
Specifically remove V, which can always be VariantIdx, and F, which can always be Layout.
2023-01-17Rollup merge of #104505 - WaffleLapkin:no-double-spaces-in-comments, r=jackh726Matthias Krüger-2/+2
Remove double spaces after dots in comments Most of the comments do not have double spaces, so I assume these are typos.
2023-01-17Remove double spaces after dots in commentsMaybe Waffle-2/+2
2023-01-14Removed various double spaces in compiler source comments.André Vennberg-1/+1
2022-12-18Auto merge of #105446 - erikdesjardins:vt-size, r=nikicbors-0/+12
Add 0..=isize::MAX range metadata to size loads from vtables This is the (much belated) size counterpart to #91569. Inspired by https://rust-lang.zulipchat.com/#narrow/stream/187780-t-compiler.2Fwg-llvm/topic/Range.20metadata.20for.20.60size_of_val.60.20and.20other.20isize.3A.3AMAX.20limits. This could help optimize layout computations based on the size of a dyn trait. Though, admittedly, adding this to vtables wouldn't be as beneficial as adding it to slice len, which is used much more often. Miri detects this UB already: https://github.com/rust-lang/rust/blob/b7cc99142ad0cfe47e2fe9f7a82eaf5b672c0573/compiler/rustc_const_eval/src/interpret/traits.rs#L119-L121 (In fact Miri goes further, [assuming a 48-bit address space on 64-bit platforms](https://github.com/rust-lang/rust/blob/9db224fc908059986c179fc6ec433944e9cfce50/compiler/rustc_abi/src/lib.rs#L312-L331), but I don't think we can assume that in an optimization.)
2022-12-12minor code cleanupsMatthias Krüger-6/+3
2022-12-10compiler: remove unnecessary imports and qualified pathsKaDiWa-1/+0
2022-12-08Add 0..=isize::MAX range metadata to size loads from vtablesErik Desjardins-0/+12
2022-12-06Auto merge of #105175 - michaelwoerister:add-stable-ord-trait, r=nagisabors-0/+7
Add StableOrd trait as proposed in MCP 533. The `StableOrd` trait can be used to mark types as having a stable sort order across compilation sessions. Collections that sort their items in a stable way can safely implement HashStable by hashing items in sort order. See https://github.com/rust-lang/compiler-team/issues/533 for more information.
2022-12-03Rollup merge of #105050 - WaffleLapkin:uselessrefign, r=jyn514Matthias Krüger-5/+5
Remove useless borrows and derefs They are nothing more than noise. <sub>These are not all of them, but my clippy started crashing (stack overflow), so rip :(</sub>
2022-12-02Add StableOrd trait as proposed in MCP 533.Michael Woerister-0/+7
The StableOrd trait can be used to mark types as having a stable sort order across compilation sessions. Collections that sort their items in a stable way can safely implement HashStable by hashing items in sort order.
2022-12-01Remove useless borrows and derefsMaybe Waffle-5/+5
2022-11-30Extract llvm datalayout parsing out of spec modulehkalbasi-0/+96
2022-11-25Simplify and document range layout computationOli Scherer-13/+11
2022-11-24move things from rustc_target::abi to rustc_abihkalbasi-0/+2370