about summary refs log tree commit diff
path: root/compiler/rustc_target/src/abi/mod.rs
AgeCommit message (Collapse)AuthorLines
2023-11-22Replace `no_ord_impl` with `orderable`.Nicholas Nethercote-0/+2
Similar to the previous commit, this replaces `newtype_index`'s opt-out `no_ord_impl` attribute with the opt-in `orderable` attribute.
2023-11-22Replace `custom_encodable` with `encodable`.Nicholas Nethercote-0/+2
By default, `newtype_index!` types get a default `Encodable`/`Decodable` impl. You can opt out of this with `custom_encodable`. Opting out is the opposite to how Rust normally works with autogenerated (derived) impls. This commit inverts the behaviour, replacing `custom_encodable` with `encodable` which opts into the default `Encodable`/`Decodable` impl. Only 23 of the 59 `newtype_index!` occurrences need `encodable`. Even better, there were eight crates with a dependency on `rustc_serialize` just from unused default `Encodable`/`Decodable` impls. This commit removes that dependency from those eight crates.
2023-10-31Enums in offset_of: update based on est31, scottmcm & llogiq reviewGeorge Bateman-17/+12
2023-10-31Support enum variants in offset_of!George Bateman-8/+16
2023-10-02Implement Deref<LayoutS> for LayoutLukas Wirth-0/+7
2023-10-02Add VariantIdx backLukas Wirth-4/+21
2023-10-02Move FieldIdx and Layout to rustc_targetLukas Wirth-0/+82
2023-10-02Bring back generic FieldIdxLukas Wirth-2/+2
2023-09-19rustc_target/riscv: Fix passing of transparent unions with only one non-ZST ↵msizanoen-0/+8
member This ensures that `MaybeUninit<T>` has the same ABI as `T` when passed through an `extern "C"` function. Fixes https://github.com/rust-lang/rust/issues/115481.
2023-09-15special case `TyAndLayout` debug implBoxy-1/+12
2023-09-12add helper method for finding the one non-1-ZST fieldRalf Jung-0/+21
2023-08-08offset_of: guard against invalid use (with unsized fields)Ralf Jung-1/+6
2023-07-21Revert "Auto merge of #113166 - moulins:ref-niches-initial, r=oli-obk"David Tolnay-5/+1
This reverts commit 557359f92512ca88b62a602ebda291f17a953002, reversing changes made to 1e6c09a803fd543a98bfbe1624d697a55300a786.
2023-07-21Auto merge of #113922 - matthiaskrgr:rollup-90cj2vv, r=matthiaskrgrbors-21/+0
Rollup of 4 pull requests Successful merges: - #113887 (new solver: add a separate cache for coherence) - #113910 (Add FnPtr ty to SMIR) - #113913 (error/E0691: include alignment in error message) - #113914 (rustc_target: drop duplicate code) r? `@ghost` `@rustbot` modify labels: rollup
2023-07-21rustc_target: drop duplicate codeDavid Rheinsberg-21/+0
Drop duplicate helper methods on `Layout`, which are already implemented on `LayoutS`. Note that `Layout` has a `Deref` implementation to `LayoutS`, so all accessors are automatically redirected. The methods are identical and have been copied to `rustc_abi` in: commit 390a637e296ccfaac4c6abd1291b0523e8a8e00b Author: hamidreza kalbasi <hamidrezakalbasi@protonmail.com> Date: Mon Nov 7 00:36:11 2022 +0330 move things from rustc_target::abi to rustc_abi This commit left behind the original implementation. Drop it now. Signed-off-by: David Rheinsberg <david@readahead.eu>
2023-07-21Don't treat ref. fields with non-null niches as `dereferenceable_or_null`Moulins-1/+5
2023-04-21offset_ofDrMeepster-0/+15
2023-02-15Rollup merge of #107163 - mikebenfield:parameters-pr, r=TaKO8KiDylan DPC-46/+2
Remove some superfluous type parameters from layout.rs. Specifically remove V, which can always be VariantIdx, and F, which can always be Layout.
2023-01-22rustc_abi: remove Primitive::{is_float,is_int}Erik Desjardins-1/+1
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-46/+2
Specifically remove V, which can always be VariantIdx, and F, which can always be Layout.
2022-12-18A few small cleanups for `newtype_index`Nilstrieb-2/+1
Remove the `..` from the body, only a few invocations used it and it's inconsistent with rust syntax. Use `;` instead of `,` between consts. As the Rust syntax gods inteded.
2022-12-18Use `#[derive]` instead of custom syntax in all `newtype_index`Nilstrieb-1/+1
2022-11-24move things from rustc_target::abi to rustc_abihkalbasi-1518/+4
2022-11-24move some layout logic to rustc_target::abi::layouthkalbasi-7/+144
2022-11-24make rustc_target usable outside of rustchkalbasi-34/+93
2022-11-13add is_sized method on Abi and Layout, and use itRalf Jung-0/+10
2022-10-05change might_permit_raw_init to fully detect LLVM UB, but not more than thatRalf Jung-69/+1
2022-09-08translations(rustc_session): migrate TargetDataLayout::parseLuis Cardoso-26/+37
2022-09-07Change name of "dataful" variant to "untagged"Michael Benfield-2/+2
This is in anticipation of a new enum layout, in which the niche optimization may be applied even when multiple variants have data.
2022-08-02Auto merge of #92268 - jswrenn:transmute, r=oli-obkbors-1/+2
Initial implementation of transmutability trait. *T'was the night before Christmas and all through the codebase, not a miri was stirring — no hint of `unsafe`!* This PR provides an initial, **incomplete** implementation of *[MCP 411: Lang Item for Transmutability](https://github.com/rust-lang/compiler-team/issues/411)*. The `core::mem::BikeshedIntrinsicFrom` trait provided by this PR is implemented on-the-fly by the compiler for types `Src` and `Dst` when the bits of all possible values of type `Src` are safely reinterpretable as a value of type `Dst`. What this PR provides is: - [x] [support for transmutations involving primitives](https://github.com/jswrenn/rust/tree/transmute/src/test/ui/transmutability/primitives) - [x] [support for transmutations involving arrays](https://github.com/jswrenn/rust/tree/transmute/src/test/ui/transmutability/arrays) - [x] [support for transmutations involving structs](https://github.com/jswrenn/rust/tree/transmute/src/test/ui/transmutability/structs) - [x] [support for transmutations involving enums](https://github.com/jswrenn/rust/tree/transmute/src/test/ui/transmutability/enums) - [x] [support for transmutations involving unions](https://github.com/jswrenn/rust/tree/transmute/src/test/ui/transmutability/unions) - [x] [support for weaker validity checks](https://github.com/jswrenn/rust/blob/transmute/src/test/ui/transmutability/unions/should_permit_intersecting_if_validity_is_assumed.rs) (i.e., `Assume::VALIDITY`) - [x] visibility checking What isn't yet implemented: - [ ] transmutability options passed using the `Assume` struct - [ ] [support for references](https://github.com/jswrenn/rust/blob/transmute/src/test/ui/transmutability/references.rs) - [ ] smarter error messages These features will be implemented in future PRs.
2022-07-31reorder fields in Laout debug outputRalf Jung-6/+7
2022-07-27Initial (incomplete) implementation of transmutability trait.Jack Wrenn-1/+2
This initial implementation handles transmutations between types with specified layouts, except when references are involved. Co-authored-by: Igor null <m1el.2027@gmail.com>
2022-07-22do not mark interior mutable shared refs as dereferenceableRalf Jung-3/+7
2022-07-22rename PointerKind::Shared → SharedMutable to indicate this is NOT the ↵Ralf Jung-1/+1
usual shared reference
2022-07-14Use constant eval to do strict validity checks5225225-23/+15
2022-06-06Auto merge of #97684 - RalfJung:better-provenance-control, r=oli-obkbors-0/+5
interpret: better control over whether we read data with provenance The resolution in https://github.com/rust-lang/unsafe-code-guidelines/issues/286 seems to be that when we load data at integer type, we implicitly strip provenance. So let's implement that in Miri at least for scalar loads. This makes use of the fact that `Scalar` layouts distinguish pointer-sized integers and pointers -- so I was expecting some wild bugs where layouts set this incorrectly, but so far that does not seem to happen. This does not entirely implement the solution to https://github.com/rust-lang/unsafe-code-guidelines/issues/286; we still do the wrong thing for integers in larger types: we will `copy_op` them and then do validation, and validation will complain about the provenance. To fix that we need mutating validation; validation needs to strip the provenance rather than complaining about it. This is a larger undertaking (but will also help resolve https://github.com/rust-lang/miri/issues/845 since we can reset padding to `Uninit`). The reason this is useful is that we can now implement `addr` as a `transmute` from a pointer to an integer, and actually get the desired behavior of stripping provenance without exposing it!
2022-06-05interpret: better control over whether we read data with provenance, and ↵Ralf Jung-0/+5
implicit provenance stripping where possible
2022-06-03Use serde_json for target spec jsonbjorn3-2/+3
2022-06-03Remove a couple of unused Encodable and Decodable derivesbjorn3-1/+1
2022-05-24Add flag for stricter checks on uninit/zeroed5225225-12/+47
2022-05-06make Size and Align debug-printing a bit more compactRalf Jung-2/+16
2022-04-26Rollup merge of #94703 - kjetilkjeka:nvptx-kernel-args-abi2, r=nagisaGuillaume Gomez-0/+32
Fix codegen bug in "ptx-kernel" abi related to arg passing I found a codegen bug in the nvptx abi related to that args are passed as ptrs ([see comment](https://github.com/rust-lang/rust/issues/38788#issuecomment-1048999928)), this is not as specified in the [ptx-interoperability doc](https://docs.nvidia.com/cuda/ptx-writers-guide-to-interoperability/) or how C/C++ does it. It will also almost always fail in practice since device/host uses different memory spaces for most hardware. This PR fixes the bug and add tests for passing structs to ptx kernels. I observed that all nvptx assembly tests had been marked as [ignore a long time ago](https://github.com/rust-lang/rust/pull/59752#issuecomment-501713428). I'm not sure if the new one should be marked as ignore, it passed on my computer but it might fail if ptx-linker is missing on the server? I guess this is outside scope for this PR and should be looked at in a different issue/PR. I only fixed the nvptx64-nvidia-cuda target and not the potential code paths for the non-existing 32bit target. Even though 32bit nvptx is not a supported target there are still some code under the hood supporting codegen for 32 bit ptx. I was advised to create an MCP to find out if this code should be removed or updated. Perhaps ``@RDambrosio016`` would have interest in taking a quick look at this.
2022-04-19Fix a bug in the ptx-kernel calling convention where structs was passed ↵Kjetil Kjeka-0/+32
indirectly Structs being passed indirectly is suprpising and have a high chance not to work as the device and host usually do not share memory.
2022-04-05trivial cfg(bootstrap) changesPietro Albini-1/+1
2022-04-05Mark scalar layout unions so that backends that do not support partially ↵Oli Scherer-20/+80
initialized scalars can special case them.
2022-03-29allow large Size againRalf Jung-16/+7
2022-03-16resolve the conflict in compiler/rustc_session/src/parse.rscodehorseman-1/+1
Signed-off-by: codehorseman <cricis@yeah.net>
2022-03-07Clarify `Layout` interning.Nicholas Nethercote-11/+65
`Layout` is another type that is sometimes interned, sometimes not, and we always use references to refer to it so we can't take any advantage of the uniqueness properties for hashing or equality checks. This commit renames `Layout` as `LayoutS`, and then introduces a new `Layout` that is a newtype around an `Interned<LayoutS>`. It also interns more layouts than before. Previously layouts within layouts (via the `variants` field) were never interned, but now they are. Hence the lifetime on the new `Layout` type. Unlike other interned types, these ones are in `rustc_target` instead of `rustc_middle`. This reflects the existing structure of the code, which does layout-specific stuff in `rustc_target` while `TyAndLayout` is generic over the `Ty`, allowing the type-specific stuff to occur in `rustc_middle`. The commit also adds a `HashStable` impl for `Interned`, which was needed. It hashes the contents, unlike the `Hash` impl which hashes the pointer.
2022-02-19Adopt let else in more placesest31-6/+3
2021-12-17Eliminate duplicate codes of is_single_fp_elementlzh-0/+18