1#![cfg_attr(feature = "nightly", allow(internal_features))]
3#![cfg_attr(feature = "nightly", feature(register_tool))]
4#![cfg_attr(feature = "nightly", feature(rustc_attrs))]
5#![cfg_attr(feature = "nightly", feature(step_trait))]
6#![cfg_attr(feature = "nightly", register_tool(lint))]
7use std::cmp::min;
42use std::fmt;
43#[cfg(feature = "nightly")]
44use std::iter::Step;
45use std::num::{NonZero, ParseIntError};
46use std::ops::{Add, AddAssign, Mul, Sub};
47use std::range::RangeInclusive;
48use std::str::FromStr;
49
50use bitflags::bitflags;
51#[cfg(feature = "nightly")]
52use rustc_data_structures::stable_hash::StableOrd;
53#[cfg(feature = "nightly")]
54use rustc_error_messages::{DiagArgValue, IntoDiagArg};
55#[cfg(feature = "nightly")]
56use rustc_errors::{Diag, DiagCtxtHandle, Diagnostic, Level, msg};
57use rustc_hashes::Hash64;
58use rustc_index::{Idx, IndexSlice, IndexVec};
59#[cfg(feature = "nightly")]
60use rustc_macros::{Decodable_NoContext, Encodable_NoContext, StableHash};
61#[cfg(feature = "nightly")]
62use rustc_span::{Symbol, sym};
63
64mod callconv;
65mod canon_abi;
66mod extern_abi;
67mod layout;
68#[cfg(test)]
69mod tests;
70mod wrapping_range;
71
72pub use callconv::{Heterogeneous, HomogeneousAggregate, Reg, RegKind};
73pub use canon_abi::{ArmCall, CanonAbi, InterruptKind, X86Call};
74#[cfg(feature = "nightly")]
75pub use extern_abi::CVariadicStatus;
76pub use extern_abi::{ExternAbi, all_names};
77pub use layout::{
78 FIRST_VARIANT, FieldIdx, LayoutCalculator, LayoutCalculatorError, PackCoroutineLayout,
79 VariantIdx,
80};
81#[cfg(feature = "nightly")]
82pub use layout::{Layout, TyAbiInterface, TyAndLayout};
83pub use wrapping_range::WrappingRange;
84
85#[derive(#[automatically_derived]#[doc(hidden)]unsafe impl ::core::clone::TrivialClone
for ReprFlags {
}
#[automatically_derived]impl ::core::clone::Clone for ReprFlags {
#[inline]
#[rustc_trivial_field_reads]
fn clone(&self) -> Self {
let _: ::core::clone::AssertParamIsClone<u8>;
*self
}
}Clone, #[automatically_derived]impl ::core::marker::Copy for ReprFlags { }Copy, #[automatically_derived]impl ::core::marker::StructuralPartialEq for ReprFlags
{
}
#[automatically_derived]impl ::core::cmp::PartialEq for ReprFlags {
#[inline]
fn eq(&self, other: &Self) -> bool { self.0 == other.0 }
}PartialEq, #[automatically_derived]impl ::core::cmp::Eq for ReprFlags {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<u8>;
}
}Eq, #[automatically_derived]impl ::core::default::Default for ReprFlags {
#[inline]
fn default() -> Self { ReprFlags(::core::default::Default::default()) }
}Default)]
86#[cfg_attr(feature = "nightly", derive(const _: () =
{
impl<__E: ::rustc_serialize::Encoder>
::rustc_serialize::Encodable<__E> for ReprFlags {
fn encode(&self, __encoder: &mut __E) {
let ReprFlags(ref __binding_0) = *self;
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
}
}
};Encodable_NoContext, const _: () =
{
impl<__D: ::rustc_serialize::Decoder>
::rustc_serialize::Decodable<__D> for ReprFlags {
fn decode(__decoder: &mut __D) -> Self {
ReprFlags(::rustc_serialize::Decodable::decode(__decoder))
}
}
};Decodable_NoContext, const _: () =
{
impl ::rustc_data_structures::stable_hash::StableHash for ReprFlags {
#[inline]
fn stable_hash<__Hcx: ::rustc_data_structures::stable_hash::StableHashCtxt>(&self,
__hcx: &mut __Hcx,
__hasher:
&mut ::rustc_data_structures::stable_hash::StableHasher) {
match *self {
ReprFlags(ref __binding_0) => {
{ __binding_0.stable_hash(__hcx, __hasher); }
}
}
}
}
};StableHash))]
87pub struct ReprFlags(u8);
88
89impl ReprFlags {
#[allow(deprecated, non_upper_case_globals,)]
pub const IS_C: Self = Self::from_bits_retain(1 << 0);
#[allow(deprecated, non_upper_case_globals,)]
pub const IS_SIMD: Self = Self::from_bits_retain(1 << 1);
#[allow(deprecated, non_upper_case_globals,)]
pub const IS_TRANSPARENT: Self = Self::from_bits_retain(1 << 2);
#[doc = r" Internal only for now. If true, don't reorder fields."]
#[doc = r" On its own it does not prevent ABI optimizations."]
#[allow(deprecated, non_upper_case_globals,)]
pub const IS_LINEAR: Self = Self::from_bits_retain(1 << 3);
#[doc =
r" If true, the type's crate has opted into layout randomization."]
#[doc =
r" Other flags can still inhibit reordering and thus randomization."]
#[doc = r" The seed stored in `ReprOptions.field_shuffle_seed`."]
#[doc = r""]
#[doc =
r" `repr(Rust)` structs with only zero-sized fields, single-variant `repr(Rust)` enums with only"]
#[doc =
r" zero-sized fields, and zero-variant `repr(Rust)` enums must remain zero-sized as per"]
#[doc =
r" T-lang decisions in https://github.com/rust-lang/reference/pull/2262 and https://github.com/rust-lang/reference/pull/2293"]
#[allow(deprecated, non_upper_case_globals,)]
pub const RANDOMIZE_LAYOUT: Self = Self::from_bits_retain(1 << 4);
#[doc =
r" If true, the type is always passed indirectly by non-Rustic ABIs."]
#[doc =
r" See [`TyAndLayout::pass_indirectly_in_non_rustic_abis`] for details."]
#[allow(deprecated, non_upper_case_globals,)]
pub const PASS_INDIRECTLY_IN_NON_RUSTIC_ABIS: Self =
Self::from_bits_retain(1 << 5);
#[allow(deprecated, non_upper_case_globals,)]
pub const IS_SCALABLE: Self = Self::from_bits_retain(1 << 6);
#[allow(deprecated, non_upper_case_globals,)]
pub const FIELD_ORDER_UNOPTIMIZABLE: Self =
Self::from_bits_retain(ReprFlags::IS_C.bits() |
ReprFlags::IS_SIMD.bits() | ReprFlags::IS_SCALABLE.bits() |
ReprFlags::IS_LINEAR.bits());
#[allow(deprecated, non_upper_case_globals,)]
pub const ABI_UNOPTIMIZABLE: Self =
Self::from_bits_retain(ReprFlags::IS_C.bits() |
ReprFlags::IS_SIMD.bits());
}
impl ::bitflags::Flags for ReprFlags {
const FLAGS: &'static [::bitflags::Flag<ReprFlags>] =
&[{
#[allow(deprecated, non_upper_case_globals,)]
::bitflags::Flag::new("IS_C", ReprFlags::IS_C)
},
{
#[allow(deprecated, non_upper_case_globals,)]
::bitflags::Flag::new("IS_SIMD", ReprFlags::IS_SIMD)
},
{
#[allow(deprecated, non_upper_case_globals,)]
::bitflags::Flag::new("IS_TRANSPARENT",
ReprFlags::IS_TRANSPARENT)
},
{
#[allow(deprecated, non_upper_case_globals,)]
::bitflags::Flag::new("IS_LINEAR", ReprFlags::IS_LINEAR)
},
{
#[allow(deprecated, non_upper_case_globals,)]
::bitflags::Flag::new("RANDOMIZE_LAYOUT",
ReprFlags::RANDOMIZE_LAYOUT)
},
{
#[allow(deprecated, non_upper_case_globals,)]
::bitflags::Flag::new("PASS_INDIRECTLY_IN_NON_RUSTIC_ABIS",
ReprFlags::PASS_INDIRECTLY_IN_NON_RUSTIC_ABIS)
},
{
#[allow(deprecated, non_upper_case_globals,)]
::bitflags::Flag::new("IS_SCALABLE", ReprFlags::IS_SCALABLE)
},
{
#[allow(deprecated, non_upper_case_globals,)]
::bitflags::Flag::new("FIELD_ORDER_UNOPTIMIZABLE",
ReprFlags::FIELD_ORDER_UNOPTIMIZABLE)
},
{
#[allow(deprecated, non_upper_case_globals,)]
::bitflags::Flag::new("ABI_UNOPTIMIZABLE",
ReprFlags::ABI_UNOPTIMIZABLE)
}];
type Bits = u8;
fn bits(&self) -> u8 { ReprFlags::bits(self) }
fn from_bits_retain(bits: u8) -> ReprFlags {
ReprFlags::from_bits_retain(bits)
}
}
#[allow(dead_code, deprecated, unused_doc_comments, unused_attributes,
unused_mut, unused_imports, non_upper_case_globals, clippy ::
assign_op_pattern, clippy :: iter_without_into_iter,)]
const _: () =
{
#[allow(dead_code, deprecated, unused_attributes)]
impl ReprFlags {
#[inline]
pub const fn empty() -> Self {
Self(<u8 as ::bitflags::Bits>::EMPTY)
}
#[inline]
pub const fn all() -> Self {
let mut truncated = <u8 as ::bitflags::Bits>::EMPTY;
let mut i = 0;
{
{
let flag =
<ReprFlags as ::bitflags::Flags>::FLAGS[i].value().bits();
truncated = truncated | flag;
i += 1;
}
};
{
{
let flag =
<ReprFlags as ::bitflags::Flags>::FLAGS[i].value().bits();
truncated = truncated | flag;
i += 1;
}
};
{
{
let flag =
<ReprFlags as ::bitflags::Flags>::FLAGS[i].value().bits();
truncated = truncated | flag;
i += 1;
}
};
{
{
let flag =
<ReprFlags as ::bitflags::Flags>::FLAGS[i].value().bits();
truncated = truncated | flag;
i += 1;
}
};
{
{
let flag =
<ReprFlags as ::bitflags::Flags>::FLAGS[i].value().bits();
truncated = truncated | flag;
i += 1;
}
};
{
{
let flag =
<ReprFlags as ::bitflags::Flags>::FLAGS[i].value().bits();
truncated = truncated | flag;
i += 1;
}
};
{
{
let flag =
<ReprFlags as ::bitflags::Flags>::FLAGS[i].value().bits();
truncated = truncated | flag;
i += 1;
}
};
{
{
let flag =
<ReprFlags as ::bitflags::Flags>::FLAGS[i].value().bits();
truncated = truncated | flag;
i += 1;
}
};
{
{
let flag =
<ReprFlags as ::bitflags::Flags>::FLAGS[i].value().bits();
truncated = truncated | flag;
i += 1;
}
};
let _ = i;
Self(truncated)
}
#[inline]
pub const fn bits(&self) -> u8 { self.0 }
#[inline]
pub const fn from_bits(bits: u8)
-> ::bitflags::__private::core::option::Option<Self> {
let truncated = Self::from_bits_truncate(bits).0;
if truncated == bits {
::bitflags::__private::core::option::Option::Some(Self(bits))
} else { ::bitflags::__private::core::option::Option::None }
}
#[inline]
pub const fn from_bits_truncate(bits: u8) -> Self {
Self(bits & Self::all().0)
}
#[inline]
pub const fn from_bits_retain(bits: u8) -> Self { Self(bits) }
#[inline]
pub fn from_name(name: &str)
-> ::bitflags::__private::core::option::Option<Self> {
{
if name == "IS_C" {
return ::bitflags::__private::core::option::Option::Some(Self(ReprFlags::IS_C.bits()));
}
};
;
{
if name == "IS_SIMD" {
return ::bitflags::__private::core::option::Option::Some(Self(ReprFlags::IS_SIMD.bits()));
}
};
;
{
if name == "IS_TRANSPARENT" {
return ::bitflags::__private::core::option::Option::Some(Self(ReprFlags::IS_TRANSPARENT.bits()));
}
};
;
{
if name == "IS_LINEAR" {
return ::bitflags::__private::core::option::Option::Some(Self(ReprFlags::IS_LINEAR.bits()));
}
};
;
{
if name == "RANDOMIZE_LAYOUT" {
return ::bitflags::__private::core::option::Option::Some(Self(ReprFlags::RANDOMIZE_LAYOUT.bits()));
}
};
;
{
if name == "PASS_INDIRECTLY_IN_NON_RUSTIC_ABIS" {
return ::bitflags::__private::core::option::Option::Some(Self(ReprFlags::PASS_INDIRECTLY_IN_NON_RUSTIC_ABIS.bits()));
}
};
;
{
if name == "IS_SCALABLE" {
return ::bitflags::__private::core::option::Option::Some(Self(ReprFlags::IS_SCALABLE.bits()));
}
};
;
{
if name == "FIELD_ORDER_UNOPTIMIZABLE" {
return ::bitflags::__private::core::option::Option::Some(Self(ReprFlags::FIELD_ORDER_UNOPTIMIZABLE.bits()));
}
};
;
{
if name == "ABI_UNOPTIMIZABLE" {
return ::bitflags::__private::core::option::Option::Some(Self(ReprFlags::ABI_UNOPTIMIZABLE.bits()));
}
};
;
let _ = name;
::bitflags::__private::core::option::Option::None
}
#[inline]
pub const fn is_empty(&self) -> bool {
self.0 == <u8 as ::bitflags::Bits>::EMPTY
}
#[inline]
pub const fn is_all(&self) -> bool {
Self::all().0 | self.0 == self.0
}
#[inline]
pub const fn intersects(&self, other: Self) -> bool {
self.0 & other.0 != <u8 as ::bitflags::Bits>::EMPTY
}
#[inline]
pub const fn contains(&self, other: Self) -> bool {
self.0 & other.0 == other.0
}
#[inline]
pub fn insert(&mut self, other: Self) {
*self = Self(self.0).union(other);
}
#[inline]
pub fn remove(&mut self, other: Self) {
*self = Self(self.0).difference(other);
}
#[inline]
pub fn toggle(&mut self, other: Self) {
*self = Self(self.0).symmetric_difference(other);
}
#[inline]
pub fn set(&mut self, other: Self, value: bool) {
if value { self.insert(other); } else { self.remove(other); }
}
#[inline]
#[must_use]
pub const fn intersection(self, other: Self) -> Self {
Self(self.0 & other.0)
}
#[inline]
#[must_use]
pub const fn union(self, other: Self) -> Self {
Self(self.0 | other.0)
}
#[inline]
#[must_use]
pub const fn difference(self, other: Self) -> Self {
Self(self.0 & !other.0)
}
#[inline]
#[must_use]
pub const fn symmetric_difference(self, other: Self) -> Self {
Self(self.0 ^ other.0)
}
#[inline]
#[must_use]
pub const fn complement(self) -> Self {
Self::from_bits_truncate(!self.0)
}
}
impl ::bitflags::__private::core::fmt::Binary for ReprFlags {
fn fmt(&self, f: &mut ::bitflags::__private::core::fmt::Formatter)
-> ::bitflags::__private::core::fmt::Result {
let inner = self.0;
::bitflags::__private::core::fmt::Binary::fmt(&inner, f)
}
}
impl ::bitflags::__private::core::fmt::Octal for ReprFlags {
fn fmt(&self, f: &mut ::bitflags::__private::core::fmt::Formatter)
-> ::bitflags::__private::core::fmt::Result {
let inner = self.0;
::bitflags::__private::core::fmt::Octal::fmt(&inner, f)
}
}
impl ::bitflags::__private::core::fmt::LowerHex for ReprFlags {
fn fmt(&self, f: &mut ::bitflags::__private::core::fmt::Formatter)
-> ::bitflags::__private::core::fmt::Result {
let inner = self.0;
::bitflags::__private::core::fmt::LowerHex::fmt(&inner, f)
}
}
impl ::bitflags::__private::core::fmt::UpperHex for ReprFlags {
fn fmt(&self, f: &mut ::bitflags::__private::core::fmt::Formatter)
-> ::bitflags::__private::core::fmt::Result {
let inner = self.0;
::bitflags::__private::core::fmt::UpperHex::fmt(&inner, f)
}
}
impl ::bitflags::__private::core::ops::BitOr for ReprFlags {
type Output = Self;
#[inline]
fn bitor(self, other: ReprFlags) -> Self { self.union(other) }
}
impl ::bitflags::__private::core::ops::BitOrAssign for ReprFlags {
#[inline]
fn bitor_assign(&mut self, other: Self) { self.insert(other); }
}
impl ::bitflags::__private::core::ops::BitXor for ReprFlags {
type Output = Self;
#[inline]
fn bitxor(self, other: Self) -> Self {
self.symmetric_difference(other)
}
}
impl ::bitflags::__private::core::ops::BitXorAssign for ReprFlags {
#[inline]
fn bitxor_assign(&mut self, other: Self) { self.toggle(other); }
}
impl ::bitflags::__private::core::ops::BitAnd for ReprFlags {
type Output = Self;
#[inline]
fn bitand(self, other: Self) -> Self { self.intersection(other) }
}
impl ::bitflags::__private::core::ops::BitAndAssign for ReprFlags {
#[inline]
fn bitand_assign(&mut self, other: Self) {
*self =
Self::from_bits_retain(self.bits()).intersection(other);
}
}
impl ::bitflags::__private::core::ops::Sub for ReprFlags {
type Output = Self;
#[inline]
fn sub(self, other: Self) -> Self { self.difference(other) }
}
impl ::bitflags::__private::core::ops::SubAssign for ReprFlags {
#[inline]
fn sub_assign(&mut self, other: Self) { self.remove(other); }
}
impl ::bitflags::__private::core::ops::Not for ReprFlags {
type Output = Self;
#[inline]
fn not(self) -> Self { self.complement() }
}
impl ::bitflags::__private::core::iter::Extend<ReprFlags> for
ReprFlags {
fn extend<T: ::bitflags::__private::core::iter::IntoIterator<Item
= Self>>(&mut self, iterator: T) {
for item in iterator { self.insert(item) }
}
}
impl ::bitflags::__private::core::iter::FromIterator<ReprFlags> for
ReprFlags {
fn from_iter<T: ::bitflags::__private::core::iter::IntoIterator<Item
= Self>>(iterator: T) -> Self {
use ::bitflags::__private::core::iter::Extend;
let mut result = Self::empty();
result.extend(iterator);
result
}
}
impl ReprFlags {
#[inline]
pub const fn iter(&self) -> ::bitflags::iter::Iter<ReprFlags> {
::bitflags::iter::Iter::__private_const_new(<ReprFlags as
::bitflags::Flags>::FLAGS,
ReprFlags::from_bits_retain(self.bits()),
ReprFlags::from_bits_retain(self.bits()))
}
#[inline]
pub const fn iter_names(&self)
-> ::bitflags::iter::IterNames<ReprFlags> {
::bitflags::iter::IterNames::__private_const_new(<ReprFlags as
::bitflags::Flags>::FLAGS,
ReprFlags::from_bits_retain(self.bits()),
ReprFlags::from_bits_retain(self.bits()))
}
}
impl ::bitflags::__private::core::iter::IntoIterator for ReprFlags {
type Item = ReprFlags;
type IntoIter = ::bitflags::iter::Iter<ReprFlags>;
fn into_iter(self) -> Self::IntoIter { self.iter() }
}
};bitflags! {
90 impl ReprFlags: u8 {
91 const IS_C = 1 << 0;
92 const IS_SIMD = 1 << 1;
93 const IS_TRANSPARENT = 1 << 2;
94 const IS_LINEAR = 1 << 3;
97 const RANDOMIZE_LAYOUT = 1 << 4;
105 const PASS_INDIRECTLY_IN_NON_RUSTIC_ABIS = 1 << 5;
108 const IS_SCALABLE = 1 << 6;
109 const FIELD_ORDER_UNOPTIMIZABLE = ReprFlags::IS_C.bits()
111 | ReprFlags::IS_SIMD.bits()
112 | ReprFlags::IS_SCALABLE.bits()
113 | ReprFlags::IS_LINEAR.bits();
114 const ABI_UNOPTIMIZABLE = ReprFlags::IS_C.bits() | ReprFlags::IS_SIMD.bits();
115 }
116}
117
118impl std::fmt::Debug for ReprFlags {
121 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
122 bitflags::parser::to_writer(self, f)
123 }
124}
125
126#[derive(#[automatically_derived]impl ::core::marker::Copy for IntegerType { }Copy, #[automatically_derived]#[doc(hidden)]unsafe impl ::core::clone::TrivialClone
for IntegerType {
}
#[automatically_derived]impl ::core::clone::Clone for IntegerType {
#[inline]
#[rustc_trivial_field_reads]
fn clone(&self) -> Self {
let _: ::core::clone::AssertParamIsClone<bool>;
let _: ::core::clone::AssertParamIsClone<Integer>;
*self
}
}Clone, #[automatically_derived]impl ::core::fmt::Debug for IntegerType {
#[inline]
#[rustc_trivial_field_reads]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
Self::Pointer(__self_0) =>
::core::fmt::Formatter::debug_struct_field1_finish(f,
"Pointer", &__self_0),
Self::Fixed(__self_0, __self_1) =>
::core::fmt::Formatter::debug_struct_field2_finish(f, "Fixed",
__self_0, &__self_1),
}
}
}Debug, #[automatically_derived]impl ::core::cmp::Eq for IntegerType {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<bool>;
let _: ::core::cmp::AssertParamIsEq<Integer>;
}
}Eq, #[automatically_derived]impl ::core::marker::StructuralPartialEq for
IntegerType {
}
#[automatically_derived]impl ::core::cmp::PartialEq for IntegerType {
#[inline]
fn eq(&self, other: &Self) -> bool {
::core::intrinsics::discriminant_value(self) ==
::core::intrinsics::discriminant_value(other) &&
match (self, other) {
(Self::Pointer(__self_0), Self::Pointer(__arg1_0)) =>
__self_0 == __arg1_0,
(Self::Fixed(__self_0, __self_1),
Self::Fixed(__arg1_0, __arg1_1)) =>
__self_1 == __arg1_1 && __self_0 == __arg1_0,
_ => unsafe { ::core::intrinsics::unreachable() }
}
}
}PartialEq)]
127#[cfg_attr(feature = "nightly", derive(const _: () =
{
impl<__E: ::rustc_serialize::Encoder>
::rustc_serialize::Encodable<__E> for IntegerType {
fn encode(&self, __encoder: &mut __E) {
let disc =
match *self {
IntegerType::Pointer(ref __binding_0) => { 0usize }
IntegerType::Fixed(ref __binding_0, ref __binding_1) => {
1usize
}
};
::rustc_serialize::Encoder::emit_u8(__encoder, disc as u8);
match *self {
IntegerType::Pointer(ref __binding_0) => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
}
IntegerType::Fixed(ref __binding_0, ref __binding_1) => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_1,
__encoder);
}
}
}
}
};Encodable_NoContext, const _: () =
{
impl<__D: ::rustc_serialize::Decoder>
::rustc_serialize::Decodable<__D> for IntegerType {
fn decode(__decoder: &mut __D) -> Self {
match ::rustc_serialize::Decoder::read_u8(__decoder) as usize
{
0usize => {
IntegerType::Pointer(::rustc_serialize::Decodable::decode(__decoder))
}
1usize => {
IntegerType::Fixed(::rustc_serialize::Decodable::decode(__decoder),
::rustc_serialize::Decodable::decode(__decoder))
}
n => {
::core::panicking::panic_fmt(format_args!("invalid enum variant tag while decoding `IntegerType`, expected 0..2, actual {0}",
n));
}
}
}
}
};Decodable_NoContext, const _: () =
{
impl ::rustc_data_structures::stable_hash::StableHash for IntegerType
{
#[inline]
fn stable_hash<__Hcx: ::rustc_data_structures::stable_hash::StableHashCtxt>(&self,
__hcx: &mut __Hcx,
__hasher:
&mut ::rustc_data_structures::stable_hash::StableHasher) {
match *self {
IntegerType::Pointer(ref __binding_0) =>
0u8.stable_hash(__hcx, __hasher),
IntegerType::Fixed(ref __binding_0, ref __binding_1) =>
1u8.stable_hash(__hcx, __hasher),
}
match *self {
IntegerType::Pointer(ref __binding_0) => {
{ __binding_0.stable_hash(__hcx, __hasher); }
}
IntegerType::Fixed(ref __binding_0, ref __binding_1) => {
{ __binding_0.stable_hash(__hcx, __hasher); }
{ __binding_1.stable_hash(__hcx, __hasher); }
}
}
}
}
};StableHash))]
128pub enum IntegerType {
129 Pointer(bool),
132 Fixed(Integer, bool),
135}
136
137impl IntegerType {
138 pub fn is_signed(&self) -> bool {
139 match self {
140 IntegerType::Pointer(b) => *b,
141 IntegerType::Fixed(_, b) => *b,
142 }
143 }
144}
145
146#[derive(#[automatically_derived]impl ::core::marker::Copy for ScalableElt { }Copy, #[automatically_derived]#[doc(hidden)]unsafe impl ::core::clone::TrivialClone
for ScalableElt {
}
#[automatically_derived]impl ::core::clone::Clone for ScalableElt {
#[inline]
#[rustc_trivial_field_reads]
fn clone(&self) -> Self {
let _: ::core::clone::AssertParamIsClone<u16>;
*self
}
}Clone, #[automatically_derived]impl ::core::fmt::Debug for ScalableElt {
#[inline]
#[rustc_trivial_field_reads]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
Self::ElementCount(__self_0) =>
::core::fmt::Formatter::debug_struct_field1_finish(f,
"ElementCount", &__self_0),
Self::Container =>
::core::fmt::Formatter::write_str(f, "Container"),
}
}
}Debug, #[automatically_derived]impl ::core::cmp::Eq for ScalableElt {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<u16>;
}
}Eq, #[automatically_derived]impl ::core::marker::StructuralPartialEq for
ScalableElt {
}
#[automatically_derived]impl ::core::cmp::PartialEq for ScalableElt {
#[inline]
fn eq(&self, other: &Self) -> bool {
::core::intrinsics::discriminant_value(self) ==
::core::intrinsics::discriminant_value(other) &&
match (self, other) {
(Self::ElementCount(__self_0), Self::ElementCount(__arg1_0))
=> __self_0 == __arg1_0,
_ => true,
}
}
}PartialEq)]
147#[cfg_attr(feature = "nightly", derive(const _: () =
{
impl<__E: ::rustc_serialize::Encoder>
::rustc_serialize::Encodable<__E> for ScalableElt {
fn encode(&self, __encoder: &mut __E) {
let disc =
match *self {
ScalableElt::ElementCount(ref __binding_0) => { 0usize }
ScalableElt::Container => { 1usize }
};
::rustc_serialize::Encoder::emit_u8(__encoder, disc as u8);
match *self {
ScalableElt::ElementCount(ref __binding_0) => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
}
ScalableElt::Container => {}
}
}
}
};Encodable_NoContext, const _: () =
{
impl<__D: ::rustc_serialize::Decoder>
::rustc_serialize::Decodable<__D> for ScalableElt {
fn decode(__decoder: &mut __D) -> Self {
match ::rustc_serialize::Decoder::read_u8(__decoder) as usize
{
0usize => {
ScalableElt::ElementCount(::rustc_serialize::Decodable::decode(__decoder))
}
1usize => { ScalableElt::Container }
n => {
::core::panicking::panic_fmt(format_args!("invalid enum variant tag while decoding `ScalableElt`, expected 0..2, actual {0}",
n));
}
}
}
}
};Decodable_NoContext, const _: () =
{
impl ::rustc_data_structures::stable_hash::StableHash for ScalableElt
{
#[inline]
fn stable_hash<__Hcx: ::rustc_data_structures::stable_hash::StableHashCtxt>(&self,
__hcx: &mut __Hcx,
__hasher:
&mut ::rustc_data_structures::stable_hash::StableHasher) {
match *self {
ScalableElt::ElementCount(ref __binding_0) =>
0u8.stable_hash(__hcx, __hasher),
ScalableElt::Container => 1u8.stable_hash(__hcx, __hasher),
}
match *self {
ScalableElt::ElementCount(ref __binding_0) => {
{ __binding_0.stable_hash(__hcx, __hasher); }
}
ScalableElt::Container => {}
}
}
}
};StableHash))]
148pub enum ScalableElt {
149 ElementCount(u16),
151 Container,
154}
155
156#[derive(#[automatically_derived]impl ::core::marker::Copy for ReprOptions { }Copy, #[automatically_derived]#[doc(hidden)]unsafe impl ::core::clone::TrivialClone
for ReprOptions {
}
#[automatically_derived]impl ::core::clone::Clone for ReprOptions {
#[inline]
#[rustc_trivial_field_reads]
fn clone(&self) -> Self {
let _: ::core::clone::AssertParamIsClone<Option<IntegerType>>;
let _: ::core::clone::AssertParamIsClone<Option<Align>>;
let _: ::core::clone::AssertParamIsClone<Option<Align>>;
let _: ::core::clone::AssertParamIsClone<ReprFlags>;
let _: ::core::clone::AssertParamIsClone<Option<ScalableElt>>;
let _: ::core::clone::AssertParamIsClone<Hash64>;
*self
}
}Clone, #[automatically_derived]impl ::core::fmt::Debug for ReprOptions {
#[inline]
#[rustc_trivial_field_reads]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_fields_finish(f,
"ReprOptions int align pack flags scalable field_shuffle_seed",
&[&self.int, &self.align, &self.pack, &self.flags, &self.scalable,
&&self.field_shuffle_seed])
}
}Debug, #[automatically_derived]impl ::core::cmp::Eq for ReprOptions {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<Option<IntegerType>>;
let _: ::core::cmp::AssertParamIsEq<Option<Align>>;
let _: ::core::cmp::AssertParamIsEq<Option<Align>>;
let _: ::core::cmp::AssertParamIsEq<ReprFlags>;
let _: ::core::cmp::AssertParamIsEq<Option<ScalableElt>>;
let _: ::core::cmp::AssertParamIsEq<Hash64>;
}
}Eq, #[automatically_derived]impl ::core::marker::StructuralPartialEq for
ReprOptions {
}
#[automatically_derived]impl ::core::cmp::PartialEq for ReprOptions {
#[inline]
fn eq(&self, other: &Self) -> bool {
self.int == other.int && self.align == other.align &&
self.pack == other.pack && self.flags == other.flags &&
self.scalable == other.scalable &&
self.field_shuffle_seed == other.field_shuffle_seed
}
}PartialEq, #[automatically_derived]impl ::core::default::Default for ReprOptions {
#[inline]
fn default() -> Self {
ReprOptions {
int: ::core::default::Default::default(),
align: ::core::default::Default::default(),
pack: ::core::default::Default::default(),
flags: ::core::default::Default::default(),
scalable: ::core::default::Default::default(),
field_shuffle_seed: ::core::default::Default::default(),
}
}
}Default)]
158#[cfg_attr(feature = "nightly", derive(const _: () =
{
impl<__E: ::rustc_serialize::Encoder>
::rustc_serialize::Encodable<__E> for ReprOptions {
fn encode(&self, __encoder: &mut __E) {
let ReprOptions {
int: ref __binding_0,
align: ref __binding_1,
pack: ref __binding_2,
flags: ref __binding_3,
scalable: ref __binding_4,
field_shuffle_seed: ref __binding_5 } = *self;
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_1,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_2,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_3,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_4,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_5,
__encoder);
}
}
};Encodable_NoContext, const _: () =
{
impl<__D: ::rustc_serialize::Decoder>
::rustc_serialize::Decodable<__D> for ReprOptions {
fn decode(__decoder: &mut __D) -> Self {
ReprOptions {
int: ::rustc_serialize::Decodable::decode(__decoder),
align: ::rustc_serialize::Decodable::decode(__decoder),
pack: ::rustc_serialize::Decodable::decode(__decoder),
flags: ::rustc_serialize::Decodable::decode(__decoder),
scalable: ::rustc_serialize::Decodable::decode(__decoder),
field_shuffle_seed: ::rustc_serialize::Decodable::decode(__decoder),
}
}
}
};Decodable_NoContext, const _: () =
{
impl ::rustc_data_structures::stable_hash::StableHash for ReprOptions
{
#[inline]
fn stable_hash<__Hcx: ::rustc_data_structures::stable_hash::StableHashCtxt>(&self,
__hcx: &mut __Hcx,
__hasher:
&mut ::rustc_data_structures::stable_hash::StableHasher) {
match *self {
ReprOptions {
int: ref __binding_0,
align: ref __binding_1,
pack: ref __binding_2,
flags: ref __binding_3,
scalable: ref __binding_4,
field_shuffle_seed: ref __binding_5 } => {
{ __binding_0.stable_hash(__hcx, __hasher); }
{ __binding_1.stable_hash(__hcx, __hasher); }
{ __binding_2.stable_hash(__hcx, __hasher); }
{ __binding_3.stable_hash(__hcx, __hasher); }
{ __binding_4.stable_hash(__hcx, __hasher); }
{ __binding_5.stable_hash(__hcx, __hasher); }
}
}
}
}
};StableHash))]
159pub struct ReprOptions {
160 pub int: Option<IntegerType>,
161 pub align: Option<Align>,
162 pub pack: Option<Align>,
163 pub flags: ReprFlags,
164 pub scalable: Option<ScalableElt>,
166 pub field_shuffle_seed: Hash64,
174}
175
176impl ReprOptions {
177 #[inline]
178 pub fn simd(&self) -> bool {
179 self.flags.contains(ReprFlags::IS_SIMD)
180 }
181
182 #[inline]
183 pub fn scalable(&self) -> bool {
184 self.flags.contains(ReprFlags::IS_SCALABLE)
185 }
186
187 #[inline]
188 pub fn c(&self) -> bool {
189 self.flags.contains(ReprFlags::IS_C)
190 }
191
192 #[inline]
195 pub fn rust(&self) -> bool {
196 !self.c() & !self.simd() & !self.scalable() & !self.transparent()
198 }
199
200 #[inline]
201 pub fn packed(&self) -> bool {
202 self.pack.is_some()
203 }
204
205 #[inline]
206 pub fn transparent(&self) -> bool {
207 self.flags.contains(ReprFlags::IS_TRANSPARENT)
208 }
209
210 #[inline]
211 pub fn linear(&self) -> bool {
212 self.flags.contains(ReprFlags::IS_LINEAR)
213 }
214
215 pub fn discr_type(&self) -> IntegerType {
223 self.int.unwrap_or(IntegerType::Pointer(true))
224 }
225
226 pub fn inhibit_enum_layout_opt(&self) -> bool {
230 self.c() || self.int.is_some()
231 }
232
233 pub fn inhibit_newtype_abi_optimization(&self) -> bool {
234 self.flags.intersects(ReprFlags::ABI_UNOPTIMIZABLE)
235 }
236
237 pub fn inhibit_struct_field_reordering(&self) -> bool {
240 self.flags.intersects(ReprFlags::FIELD_ORDER_UNOPTIMIZABLE) || self.int.is_some()
241 }
242
243 pub fn can_randomize_type_layout(&self) -> bool {
246 !self.inhibit_struct_field_reordering() && self.flags.contains(ReprFlags::RANDOMIZE_LAYOUT)
247 }
248
249 pub fn inhibits_union_abi_opt(&self) -> bool {
251 self.c()
252 }
253
254 pub fn equal_up_to_seed(&self, other: &Self) -> bool {
256 let ReprOptions { int, align, pack, flags, scalable, field_shuffle_seed: _ } = *self;
257 int == other.int
258 && align == other.align
259 && pack == other.pack
260 && flags == other.flags
261 && scalable == other.scalable
262 }
263}
264
265pub const MAX_SIMD_LANES: u16 = 1 << 0xF;
271
272#[derive(#[automatically_derived]impl ::core::fmt::Debug for BackendLaneCount {
#[inline]
#[rustc_trivial_field_reads]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field1_finish(f,
"BackendLaneCount", &&self.0)
}
}Debug, #[automatically_derived]impl ::core::marker::Copy for BackendLaneCount { }Copy, #[automatically_derived]#[doc(hidden)]unsafe impl ::core::clone::TrivialClone
for BackendLaneCount {
}
#[automatically_derived]impl ::core::clone::Clone for BackendLaneCount {
#[inline]
#[rustc_trivial_field_reads]
fn clone(&self) -> Self {
let _: ::core::clone::AssertParamIsClone<NonZero<u16>>;
*self
}
}Clone, #[automatically_derived]impl ::core::hash::Hash for BackendLaneCount {
#[inline]
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
::core::hash::Hash::hash(&self.0, state)
}
}Hash, #[automatically_derived]impl ::core::cmp::Eq for BackendLaneCount {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<NonZero<u16>>;
}
}Eq, #[automatically_derived]impl ::core::marker::StructuralPartialEq for
BackendLaneCount {
}
#[automatically_derived]impl ::core::cmp::PartialEq for BackendLaneCount {
#[inline]
fn eq(&self, other: &Self) -> bool { self.0 == other.0 }
}PartialEq, #[automatically_derived]impl ::core::cmp::Ord for BackendLaneCount {
#[inline]
fn cmp(&self, other: &Self) -> ::core::cmp::Ordering {
::core::cmp::Ord::cmp(&self.0, &other.0)
}
}Ord, #[automatically_derived]impl ::core::cmp::PartialOrd for BackendLaneCount {
#[inline]
fn partial_cmp(&self, other: &Self)
-> ::core::option::Option<::core::cmp::Ordering> {
::core::option::Option::Some(::core::cmp::Ord::cmp(self, other))
}
}PartialOrd)]
274#[cfg_attr(feature = "nightly", derive(const _: () =
{
impl<__E: ::rustc_serialize::Encoder>
::rustc_serialize::Encodable<__E> for BackendLaneCount {
fn encode(&self, __encoder: &mut __E) {
let BackendLaneCount(ref __binding_0) = *self;
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
}
}
};Encodable_NoContext, const _: () =
{
impl<__D: ::rustc_serialize::Decoder>
::rustc_serialize::Decodable<__D> for BackendLaneCount {
fn decode(__decoder: &mut __D) -> Self {
BackendLaneCount(::rustc_serialize::Decodable::decode(__decoder))
}
}
};Decodable_NoContext, const _: () =
{
impl ::rustc_data_structures::stable_hash::StableHash for
BackendLaneCount {
#[inline]
fn stable_hash<__Hcx: ::rustc_data_structures::stable_hash::StableHashCtxt>(&self,
__hcx: &mut __Hcx,
__hasher:
&mut ::rustc_data_structures::stable_hash::StableHasher) {
match *self {
BackendLaneCount(ref __binding_0) => {
{ __binding_0.stable_hash(__hcx, __hasher); }
}
}
}
}
};StableHash))]
275pub struct BackendLaneCount(NonZero<u16>);
276
277impl BackendLaneCount {
278 pub fn new<N>(count: u64) -> Result<Self, LayoutCalculatorError<N>> {
279 let Ok(count @ ..=MAX_SIMD_LANES) = u16::try_from(count) else {
280 return Err(LayoutCalculatorError::OversizedSimdType {
281 max_lanes: crate::MAX_SIMD_LANES.into(),
282 });
283 };
284 if let Some(count) = NonZero::new(count) {
285 Ok(BackendLaneCount(count))
286 } else {
287 Err(LayoutCalculatorError::ZeroLengthSimdType)
288 }
289 }
290
291 #[inline]
292 pub fn is_power_of_two(self) -> bool {
293 self.0.is_power_of_two()
294 }
295
296 #[inline]
297 pub fn as_u64(self) -> u64 {
298 self.0.get().into()
299 }
300
301 #[inline]
302 pub fn as_u32(self) -> u32 {
303 self.0.get().into()
304 }
305}
306
307#[derive(#[automatically_derived]impl ::core::marker::Copy for PointerSpec { }Copy, #[automatically_derived]#[doc(hidden)]unsafe impl ::core::clone::TrivialClone
for PointerSpec {
}
#[automatically_derived]impl ::core::clone::Clone for PointerSpec {
#[inline]
#[rustc_trivial_field_reads]
fn clone(&self) -> Self {
let _: ::core::clone::AssertParamIsClone<Size>;
let _: ::core::clone::AssertParamIsClone<Align>;
let _: ::core::clone::AssertParamIsClone<bool>;
*self
}
}Clone, #[automatically_derived]impl ::core::fmt::Debug for PointerSpec {
#[inline]
#[rustc_trivial_field_reads]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field4_finish(f,
"PointerSpec pointer_size pointer_align pointer_offset _is_fat",
&self.pointer_size, &self.pointer_align, &self.pointer_offset,
&&self._is_fat)
}
}Debug, #[automatically_derived]impl ::core::marker::StructuralPartialEq for
PointerSpec {
}
#[automatically_derived]impl ::core::cmp::PartialEq for PointerSpec {
#[inline]
fn eq(&self, other: &Self) -> bool {
self._is_fat == other._is_fat &&
self.pointer_size == other.pointer_size &&
self.pointer_align == other.pointer_align &&
self.pointer_offset == other.pointer_offset
}
}PartialEq, #[automatically_derived]impl ::core::cmp::Eq for PointerSpec {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<Size>;
let _: ::core::cmp::AssertParamIsEq<Align>;
let _: ::core::cmp::AssertParamIsEq<bool>;
}
}Eq)]
309pub struct PointerSpec {
310 pointer_size: Size,
312 pointer_align: Align,
314 pointer_offset: Size,
316 _is_fat: bool,
319}
320
321#[derive(#[automatically_derived]impl ::core::fmt::Debug for TargetDataLayout {
#[inline]
#[rustc_trivial_field_reads]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_fields_finish(f,
"TargetDataLayout endian i16_align i32_align i64_align i128_align f16_align f32_align f64_align x87_f80_align f128_align aggregate_align vector_align default_address_space default_address_space_pointer_spec address_space_info instruction_address_space c_enum_min_size",
&[&self.endian, &self.i16_align, &self.i32_align, &self.i64_align,
&self.i128_align, &self.f16_align, &self.f32_align,
&self.f64_align, &self.x87_f80_align, &self.f128_align,
&self.aggregate_align, &self.vector_align,
&self.default_address_space,
&self.default_address_space_pointer_spec,
&self.address_space_info, &self.instruction_address_space,
&&self.c_enum_min_size])
}
}Debug, #[automatically_derived]impl ::core::marker::StructuralPartialEq for
TargetDataLayout {
}
#[automatically_derived]impl ::core::cmp::PartialEq for TargetDataLayout {
#[inline]
fn eq(&self, other: &Self) -> bool {
self.endian == other.endian && self.i16_align == other.i16_align &&
self.i32_align == other.i32_align &&
self.i64_align == other.i64_align &&
self.i128_align == other.i128_align &&
self.f16_align == other.f16_align &&
self.f32_align == other.f32_align &&
self.f64_align == other.f64_align &&
self.x87_f80_align == other.x87_f80_align &&
self.f128_align == other.f128_align &&
self.aggregate_align == other.aggregate_align &&
self.vector_align == other.vector_align &&
self.default_address_space == other.default_address_space &&
self.default_address_space_pointer_spec ==
other.default_address_space_pointer_spec &&
self.address_space_info == other.address_space_info &&
self.instruction_address_space ==
other.instruction_address_space &&
self.c_enum_min_size == other.c_enum_min_size
}
}PartialEq, #[automatically_derived]impl ::core::cmp::Eq for TargetDataLayout {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<Endian>;
let _: ::core::cmp::AssertParamIsEq<Align>;
let _: ::core::cmp::AssertParamIsEq<Vec<(Size, Align)>>;
let _: ::core::cmp::AssertParamIsEq<AddressSpace>;
let _: ::core::cmp::AssertParamIsEq<PointerSpec>;
let _: ::core::cmp::AssertParamIsEq<Vec<(AddressSpace, PointerSpec)>>;
let _: ::core::cmp::AssertParamIsEq<Integer>;
}
}Eq)]
324pub struct TargetDataLayout {
325 pub endian: Endian,
326 pub i16_align: Align,
327 pub i32_align: Align,
328 pub i64_align: Align,
329 pub i128_align: Align,
330 pub f16_align: Align,
331 pub f32_align: Align,
332 pub f64_align: Align,
333 pub x87_f80_align: Align,
334 pub f128_align: Align,
335 pub aggregate_align: Align,
336
337 pub vector_align: Vec<(Size, Align)>,
339
340 pub default_address_space: AddressSpace,
341 pub default_address_space_pointer_spec: PointerSpec,
342
343 address_space_info: Vec<(AddressSpace, PointerSpec)>,
350
351 pub instruction_address_space: AddressSpace,
352
353 pub c_enum_min_size: Integer,
357}
358
359impl Default for TargetDataLayout {
360 fn default() -> TargetDataLayout {
362 let align = |bits| Align::from_bits(bits).unwrap();
363 TargetDataLayout {
364 endian: Endian::Big,
365 i16_align: align(16),
366 i32_align: align(32),
367 i64_align: align(32),
368 i128_align: align(32),
369 f16_align: align(16),
370 f32_align: align(32),
371 f64_align: align(64),
372 x87_f80_align: align(128),
373 f128_align: align(128),
374 aggregate_align: align(8),
375 vector_align: ::alloc::boxed::box_assume_init_into_vec_unsafe(::alloc::intrinsics::write_box_via_move(::alloc::boxed::Box::new_uninit(),
[(Size::from_bits(64), align(64)),
(Size::from_bits(128), align(128))]))vec![
376 (Size::from_bits(64), align(64)),
377 (Size::from_bits(128), align(128)),
378 ],
379 default_address_space: AddressSpace::ZERO,
380 default_address_space_pointer_spec: PointerSpec {
381 pointer_size: Size::from_bits(64),
382 pointer_align: align(64),
383 pointer_offset: Size::from_bits(64),
384 _is_fat: false,
385 },
386 address_space_info: ::alloc::vec::Vec::new()vec![],
387 instruction_address_space: AddressSpace::ZERO,
388 c_enum_min_size: Integer::I32,
389 }
390 }
391}
392
393pub enum TargetDataLayoutError<'a> {
394 InvalidAddressSpace { addr_space: &'a str, cause: &'a str, err: ParseIntError },
395 InvalidBits { kind: &'a str, bit: &'a str, cause: &'a str, err: ParseIntError },
396 MissingAlignment { cause: &'a str },
397 InvalidAlignment { cause: &'a str, err: AlignFromBytesError },
398 AlignmentTooLargeForType { cause: &'a str, align: Align },
399 InconsistentTargetArchitecture { dl: &'a str, target: &'a str },
400 InconsistentTargetPointerWidth { pointer_size: u64, target: u16 },
401 InvalidBitsSize { err: String },
402 UnknownPointerSpecification { err: String },
403}
404
405#[cfg(feature = "nightly")]
406impl Diagnostic<'_> for TargetDataLayoutError<'_> {
407 fn into_diag(self, dcx: DiagCtxtHandle<'_>, level: Level) -> Diag<'_> {
408 match self {
409 TargetDataLayoutError::InvalidAddressSpace { addr_space, err, cause } => {
410 Diag::new(dcx, level, rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("invalid address space `{$addr_space}` for `{$cause}` in \"data-layout\": {$err}"))msg!("invalid address space `{$addr_space}` for `{$cause}` in \"data-layout\": {$err}"))
411 .with_arg("addr_space", addr_space)
412 .with_arg("cause", cause)
413 .with_arg("err", err)
414 }
415 TargetDataLayoutError::InvalidBits { kind, bit, cause, err } => {
416 Diag::new(dcx, level, rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("invalid {$kind} `{$bit}` for `{$cause}` in \"data-layout\": {$err}"))msg!("invalid {$kind} `{$bit}` for `{$cause}` in \"data-layout\": {$err}"))
417 .with_arg("kind", kind)
418 .with_arg("bit", bit)
419 .with_arg("cause", cause)
420 .with_arg("err", err)
421 }
422 TargetDataLayoutError::MissingAlignment { cause } => {
423 Diag::new(dcx, level, rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("missing alignment for `{$cause}` in \"data-layout\""))msg!("missing alignment for `{$cause}` in \"data-layout\""))
424 .with_arg("cause", cause)
425 }
426 TargetDataLayoutError::InvalidAlignment { cause, err } => {
427 Diag::new(dcx, level, rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("invalid alignment for `{$cause}` in \"data-layout\": {$err}"))msg!("invalid alignment for `{$cause}` in \"data-layout\": {$err}"))
428 .with_arg("cause", cause)
429 .with_arg("err", err.to_string())
430 }
431 TargetDataLayoutError::AlignmentTooLargeForType { cause, align } => {
432 Diag::new(dcx, level, rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("alignment of `{$align}` bytes in \"data-layout\" is too large for `{$cause}`"))msg!("alignment of `{$align}` bytes in \"data-layout\" is too large for `{$cause}`")).with_arg("align", align.bytes()).with_arg("cause", cause)
433 }
434 TargetDataLayoutError::InconsistentTargetArchitecture { dl, target } => {
435 Diag::new(dcx, level, rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("inconsistent target specification: \"data-layout\" claims architecture is {$dl}-endian, while \"target-endian\" is `{$target}`"))msg!("inconsistent target specification: \"data-layout\" claims architecture is {$dl}-endian, while \"target-endian\" is `{$target}`"))
436 .with_arg("dl", dl).with_arg("target", target)
437 }
438 TargetDataLayoutError::InconsistentTargetPointerWidth { pointer_size, target } => {
439 Diag::new(dcx, level, rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("inconsistent target specification: \"data-layout\" claims pointers are {$pointer_size}-bit, while \"target-pointer-width\" is `{$target}`"))msg!("inconsistent target specification: \"data-layout\" claims pointers are {$pointer_size}-bit, while \"target-pointer-width\" is `{$target}`"))
440 .with_arg("pointer_size", pointer_size).with_arg("target", target)
441 }
442 TargetDataLayoutError::InvalidBitsSize { err } => {
443 Diag::new(dcx, level, rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("{$err}"))msg!("{$err}")).with_arg("err", err)
444 }
445 TargetDataLayoutError::UnknownPointerSpecification { err } => {
446 Diag::new(dcx, level, rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("unknown pointer specification `{$err}` in datalayout string"))msg!("unknown pointer specification `{$err}` in datalayout string"))
447 .with_arg("err", err)
448 }
449 }
450 }
451}
452
453impl TargetDataLayout {
454 pub fn parse_from_llvm_datalayout_string<'a>(
460 input: &'a str,
461 default_address_space: AddressSpace,
462 ) -> Result<TargetDataLayout, TargetDataLayoutError<'a>> {
463 let parse_address_space = |s: &'a str, cause: &'a str| {
465 s.parse::<u32>().map(AddressSpace).map_err(|err| {
466 TargetDataLayoutError::InvalidAddressSpace { addr_space: s, cause, err }
467 })
468 };
469
470 let parse_bits = |s: &'a str, kind: &'a str, cause: &'a str| {
472 s.parse::<u64>().map_err(|err| TargetDataLayoutError::InvalidBits {
473 kind,
474 bit: s,
475 cause,
476 err,
477 })
478 };
479
480 let parse_size =
482 |s: &'a str, cause: &'a str| parse_bits(s, "size", cause).map(Size::from_bits);
483
484 let parse_align_str = |s: &'a str, cause: &'a str, size_bits: u64| {
486 let align_from_bits = |bits| {
487 Align::from_bits(bits)
488 .map_err(|err| TargetDataLayoutError::InvalidAlignment { cause, err })
489 };
490 let align_bits = parse_bits(s, "alignment", cause)?;
491 let align = align_from_bits(align_bits)?;
492 let max_align_bytes = size_bits.div_ceil(8).next_power_of_two();
493 if align.bytes() > max_align_bytes {
494 Err(TargetDataLayoutError::AlignmentTooLargeForType { cause, align })
495 } else {
496 Ok(align)
497 }
498 };
499
500 let parse_align_seq = |s: &[&'a str], cause: &'a str, size_bits: u64| {
503 if s.is_empty() {
504 return Err(TargetDataLayoutError::MissingAlignment { cause });
505 }
506 parse_align_str(s[0], cause, size_bits)
507 };
508
509 let mut dl = TargetDataLayout::default();
510 dl.default_address_space = default_address_space;
511
512 let mut i128_align_src = 64;
513 for spec in input.split('-') {
514 let spec_parts = spec.split(':').collect::<Vec<_>>();
515
516 match &*spec_parts {
517 ["e"] => dl.endian = Endian::Little,
518 ["E"] => dl.endian = Endian::Big,
519 [p] if p.starts_with('P') => {
520 dl.instruction_address_space = parse_address_space(&p[1..], "P")?
521 }
522 ["a", a @ ..] => dl.aggregate_align = parse_align_seq(a, "a", u64::MAX)?,
523 ["f16", a @ ..] => dl.f16_align = parse_align_seq(a, "f16", 16)?,
524 ["f32", a @ ..] => dl.f32_align = parse_align_seq(a, "f32", 32)?,
525 ["f64", a @ ..] => dl.f64_align = parse_align_seq(a, "f64", 64)?,
526 ["f80", a @ ..] => dl.x87_f80_align = parse_align_seq(a, "f80", 80)?,
527 ["f128", a @ ..] => dl.f128_align = parse_align_seq(a, "f128", 128)?,
528 [p, s, a @ ..] if p.starts_with("p") => {
529 let mut p = p.strip_prefix('p').unwrap();
530 let mut _is_fat = false;
531
532 if p.starts_with('f') {
536 p = p.strip_prefix('f').unwrap();
537 _is_fat = true;
538 }
539
540 if p.starts_with(char::is_alphabetic) {
543 return Err(TargetDataLayoutError::UnknownPointerSpecification {
544 err: p.to_string(),
545 });
546 }
547
548 let addr_space = if !p.is_empty() {
549 parse_address_space(p, "p-")?
550 } else {
551 AddressSpace::ZERO
552 };
553
554 let pointer_size = parse_size(s, "p-")?;
555 let pointer_align = parse_align_seq(a, "p-", pointer_size.bits())?;
556 let info = PointerSpec {
557 pointer_offset: pointer_size,
558 pointer_size,
559 pointer_align,
560 _is_fat,
561 };
562 if addr_space == default_address_space {
563 dl.default_address_space_pointer_spec = info;
564 } else {
565 match dl.address_space_info.iter_mut().find(|(a, _)| *a == addr_space) {
566 Some(e) => e.1 = info,
567 None => {
568 dl.address_space_info.push((addr_space, info));
569 }
570 }
571 }
572 }
573 [p, s, a, _pr, i] if p.starts_with("p") => {
574 let mut p = p.strip_prefix('p').unwrap();
575 let mut _is_fat = false;
576
577 if p.starts_with('f') {
581 p = p.strip_prefix('f').unwrap();
582 _is_fat = true;
583 }
584
585 if p.starts_with(char::is_alphabetic) {
588 return Err(TargetDataLayoutError::UnknownPointerSpecification {
589 err: p.to_string(),
590 });
591 }
592
593 let addr_space = if !p.is_empty() {
594 parse_address_space(p, "p")?
595 } else {
596 AddressSpace::ZERO
597 };
598
599 let pointer_size = parse_size(s, "p-")?;
600 let info = PointerSpec {
601 pointer_size,
602 pointer_align: parse_align_str(a, "p-", pointer_size.bits())?,
603 pointer_offset: parse_size(i, "p-")?,
604 _is_fat,
605 };
606
607 if addr_space == default_address_space {
608 dl.default_address_space_pointer_spec = info;
609 } else {
610 match dl.address_space_info.iter_mut().find(|(a, _)| *a == addr_space) {
611 Some(e) => e.1 = info,
612 None => {
613 dl.address_space_info.push((addr_space, info));
614 }
615 }
616 }
617 }
618
619 [s, a @ ..] if s.starts_with('i') => {
620 let Ok(bits) = s[1..].parse::<u64>() else {
621 parse_size(&s[1..], "i")?; continue;
623 };
624 let a = parse_align_seq(a, s, bits)?;
625 match bits {
626 16 => dl.i16_align = a,
629 32 => dl.i32_align = a,
630 64 => dl.i64_align = a,
631 _ => {}
632 }
633 if bits >= i128_align_src && bits <= 128 {
634 i128_align_src = bits;
637 dl.i128_align = a;
638 }
639 }
640 [s, a @ ..] if s.starts_with('v') => {
641 let v_size = parse_size(&s[1..], "v")?;
642 let a = parse_align_seq(a, s, v_size.bits())?;
643 if let Some(v) = dl.vector_align.iter_mut().find(|v| v.0 == v_size) {
644 v.1 = a;
645 continue;
646 }
647 dl.vector_align.push((v_size, a));
649 }
650 _ => {} }
652 }
653
654 if (dl.instruction_address_space != dl.default_address_space)
657 && dl
658 .address_space_info
659 .iter()
660 .find(|(a, _)| *a == dl.instruction_address_space)
661 .is_none()
662 {
663 dl.address_space_info.push((
664 dl.instruction_address_space,
665 dl.default_address_space_pointer_spec.clone(),
666 ));
667 }
668
669 Ok(dl)
670 }
671
672 #[inline]
683 pub fn obj_size_bound(&self) -> u64 {
684 match self.pointer_size().bits() {
685 16 => 1 << 15,
686 32 => 1 << 31,
687 64 => 1 << 61,
688 bits => {
::core::panicking::panic_fmt(format_args!("obj_size_bound: unknown pointer bit size {0}",
bits));
}panic!("obj_size_bound: unknown pointer bit size {bits}"),
689 }
690 }
691
692 #[inline]
702 pub fn obj_size_bound_in(&self, address_space: AddressSpace) -> u64 {
703 match self.pointer_size_in(address_space).bits() {
704 16 => 1 << 15,
705 32 => 1 << 31,
706 64 => 1 << 61,
707 bits => {
::core::panicking::panic_fmt(format_args!("obj_size_bound: unknown pointer bit size {0}",
bits));
}panic!("obj_size_bound: unknown pointer bit size {bits}"),
708 }
709 }
710
711 #[inline]
712 pub fn ptr_sized_integer(&self) -> Integer {
713 use Integer::*;
714 match self.pointer_offset().bits() {
715 16 => I16,
716 32 => I32,
717 64 => I64,
718 bits => {
::core::panicking::panic_fmt(format_args!("ptr_sized_integer: unknown pointer bit size {0}",
bits));
}panic!("ptr_sized_integer: unknown pointer bit size {bits}"),
719 }
720 }
721
722 #[inline]
723 pub fn ptr_sized_integer_in(&self, address_space: AddressSpace) -> Integer {
724 use Integer::*;
725 match self.pointer_offset_in(address_space).bits() {
726 16 => I16,
727 32 => I32,
728 64 => I64,
729 bits => {
::core::panicking::panic_fmt(format_args!("ptr_sized_integer: unknown pointer bit size {0}",
bits));
}panic!("ptr_sized_integer: unknown pointer bit size {bits}"),
730 }
731 }
732
733 #[inline]
735 fn c_vector_align(&self, vec_size: Size) -> Option<Align> {
736 self.vector_align
737 .iter()
738 .find(|(size, _align)| *size == vec_size)
739 .map(|(_size, align)| *align)
740 }
741
742 #[inline]
752 pub fn rust_vector_align(&self, vec_size: Size) -> Align {
753 self.c_vector_align(vec_size)
754 .unwrap_or(Align::from_bytes(vec_size.bytes().next_power_of_two()).unwrap())
755 }
756
757 #[inline]
759 pub fn pointer_size(&self) -> Size {
760 self.default_address_space_pointer_spec.pointer_size
761 }
762
763 #[inline]
765 pub fn pointer_size_in(&self, c: AddressSpace) -> Size {
766 if c == self.default_address_space {
767 return self.default_address_space_pointer_spec.pointer_size;
768 }
769
770 if let Some(e) = self.address_space_info.iter().find(|(a, _)| a == &c) {
771 e.1.pointer_size
772 } else {
773 {
::core::panicking::panic_fmt(format_args!("Use of unknown address space {0:?}",
c));
};panic!("Use of unknown address space {c:?}");
774 }
775 }
776
777 #[inline]
779 pub fn pointer_offset(&self) -> Size {
780 self.default_address_space_pointer_spec.pointer_offset
781 }
782
783 #[inline]
785 pub fn pointer_offset_in(&self, c: AddressSpace) -> Size {
786 if c == self.default_address_space {
787 return self.default_address_space_pointer_spec.pointer_offset;
788 }
789
790 if let Some(e) = self.address_space_info.iter().find(|(a, _)| a == &c) {
791 e.1.pointer_offset
792 } else {
793 {
::core::panicking::panic_fmt(format_args!("Use of unknown address space {0:?}",
c));
};panic!("Use of unknown address space {c:?}");
794 }
795 }
796
797 #[inline]
799 pub fn pointer_align(&self) -> Align {
800 self.default_address_space_pointer_spec.pointer_align
801 }
802
803 #[inline]
805 pub fn pointer_align_in(&self, c: AddressSpace) -> Align {
806 if c == self.default_address_space {
807 self.default_address_space_pointer_spec.pointer_align
808 } else if let Some(e) = self.address_space_info.iter().find(|(a, _)| a == &c) {
809 e.1.pointer_align
810 } else {
811 {
::core::panicking::panic_fmt(format_args!("Use of unknown address space {0:?}",
c));
};panic!("Use of unknown address space {c:?}");
812 }
813 }
814}
815
816pub trait HasDataLayout {
817 fn data_layout(&self) -> &TargetDataLayout;
818}
819
820impl HasDataLayout for TargetDataLayout {
821 #[inline]
822 fn data_layout(&self) -> &TargetDataLayout {
823 self
824 }
825}
826
827impl HasDataLayout for &TargetDataLayout {
829 #[inline]
830 fn data_layout(&self) -> &TargetDataLayout {
831 (**self).data_layout()
832 }
833}
834
835#[derive(#[automatically_derived]impl ::core::marker::Copy for Endian { }Copy, #[automatically_derived]#[doc(hidden)]unsafe impl ::core::clone::TrivialClone
for Endian {
}
#[automatically_derived]impl ::core::clone::Clone for Endian {
#[inline]
#[rustc_trivial_field_reads]
fn clone(&self) -> Self { *self }
}Clone, #[automatically_derived]impl ::core::marker::StructuralPartialEq for Endian {
}
#[automatically_derived]impl ::core::cmp::PartialEq for Endian {
#[inline]
fn eq(&self, other: &Self) -> bool {
::core::intrinsics::discriminant_value(self) ==
::core::intrinsics::discriminant_value(other)
}
}PartialEq, #[automatically_derived]impl ::core::cmp::Eq for Endian { }Eq)]
837pub enum Endian {
838 Little,
839 Big,
840}
841
842impl Endian {
843 pub fn as_str(&self) -> &'static str {
844 match self {
845 Self::Little => "little",
846 Self::Big => "big",
847 }
848 }
849
850 #[cfg(feature = "nightly")]
851 pub fn desc_symbol(&self) -> Symbol {
852 match self {
853 Self::Little => sym::little,
854 Self::Big => sym::big,
855 }
856 }
857}
858
859impl fmt::Debug for Endian {
860 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
861 f.write_str(self.as_str())
862 }
863}
864
865impl FromStr for Endian {
866 type Err = String;
867
868 fn from_str(s: &str) -> Result<Self, Self::Err> {
869 match s {
870 "little" => Ok(Self::Little),
871 "big" => Ok(Self::Big),
872 _ => Err(::alloc::__export::must_use({
::alloc::fmt::format(format_args!("unknown endian: \"{0}\"", s))
})format!(r#"unknown endian: "{s}""#)),
873 }
874 }
875}
876
877#[derive(#[automatically_derived]impl ::core::marker::Copy for Size { }Copy, #[automatically_derived]#[doc(hidden)]unsafe impl ::core::clone::TrivialClone
for Size {
}
#[automatically_derived]impl ::core::clone::Clone for Size {
#[inline]
#[rustc_trivial_field_reads]
fn clone(&self) -> Self {
let _: ::core::clone::AssertParamIsClone<u64>;
*self
}
}Clone, #[automatically_derived]impl ::core::marker::StructuralPartialEq for Size { }
#[automatically_derived]impl ::core::cmp::PartialEq for Size {
#[inline]
fn eq(&self, other: &Self) -> bool { self.raw == other.raw }
}PartialEq, #[automatically_derived]impl ::core::cmp::Eq for Size {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<u64>;
}
}Eq, #[automatically_derived]impl ::core::cmp::PartialOrd for Size {
#[inline]
fn partial_cmp(&self, other: &Self)
-> ::core::option::Option<::core::cmp::Ordering> {
::core::option::Option::Some(::core::cmp::Ord::cmp(self, other))
}
}PartialOrd, #[automatically_derived]impl ::core::cmp::Ord for Size {
#[inline]
fn cmp(&self, other: &Self) -> ::core::cmp::Ordering {
::core::cmp::Ord::cmp(&self.raw, &other.raw)
}
}Ord, #[automatically_derived]impl ::core::hash::Hash for Size {
#[inline]
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
::core::hash::Hash::hash(&self.raw, state)
}
}Hash, #[automatically_derived]impl ::core::default::Default for Size {
#[inline]
fn default() -> Self { Size { raw: ::core::default::Default::default() } }
}Default)]
879#[cfg_attr(feature = "nightly", derive(const _: () =
{
impl<__E: ::rustc_serialize::Encoder>
::rustc_serialize::Encodable<__E> for Size {
fn encode(&self, __encoder: &mut __E) {
let Size { raw: ref __binding_0 } = *self;
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
}
}
};Encodable_NoContext, const _: () =
{
impl<__D: ::rustc_serialize::Decoder>
::rustc_serialize::Decodable<__D> for Size {
fn decode(__decoder: &mut __D) -> Self {
Size { raw: ::rustc_serialize::Decodable::decode(__decoder) }
}
}
};Decodable_NoContext, const _: () =
{
impl ::rustc_data_structures::stable_hash::StableHash for Size {
#[inline]
fn stable_hash<__Hcx: ::rustc_data_structures::stable_hash::StableHashCtxt>(&self,
__hcx: &mut __Hcx,
__hasher:
&mut ::rustc_data_structures::stable_hash::StableHasher) {
match *self {
Size { raw: ref __binding_0 } => {
{ __binding_0.stable_hash(__hcx, __hasher); }
}
}
}
}
};StableHash))]
880pub struct Size {
881 raw: u64,
882}
883
884#[cfg(feature = "nightly")]
885impl StableOrd for Size {
886 const CAN_USE_UNSTABLE_SORT: bool = true;
887
888 const THIS_IMPLEMENTATION_HAS_BEEN_TRIPLE_CHECKED: () = ();
891}
892
893impl fmt::Debug for Size {
895 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
896 f.write_fmt(format_args!("Size({0} bytes)", self.bytes()))write!(f, "Size({} bytes)", self.bytes())
897 }
898}
899
900impl Size {
901 pub const ZERO: Size = Size { raw: 0 };
902
903 pub fn from_bits(bits: impl TryInto<u64>) -> Size {
906 let bits = bits.try_into().ok().unwrap();
907 Size { raw: bits.div_ceil(8) }
908 }
909
910 #[inline]
911 pub fn from_bytes(bytes: impl TryInto<u64>) -> Size {
912 let bytes: u64 = bytes.try_into().ok().unwrap();
913 Size { raw: bytes }
914 }
915
916 #[inline]
917 pub fn bytes(self) -> u64 {
918 self.raw
919 }
920
921 #[inline]
922 pub fn bytes_usize(self) -> usize {
923 self.bytes().try_into().unwrap()
924 }
925
926 #[inline]
927 pub fn bits(self) -> u64 {
928 #[cold]
929 fn overflow(bytes: u64) -> ! {
930 {
::core::panicking::panic_fmt(format_args!("Size::bits: {0} bytes in bits doesn\'t fit in u64",
bytes));
}panic!("Size::bits: {bytes} bytes in bits doesn't fit in u64")
931 }
932
933 self.bytes().checked_mul(8).unwrap_or_else(|| overflow(self.bytes()))
934 }
935
936 #[inline]
937 pub fn bits_usize(self) -> usize {
938 self.bits().try_into().unwrap()
939 }
940
941 #[inline]
942 pub fn align_to(self, align: Align) -> Size {
943 let mask = align.bytes() - 1;
944 Size::from_bytes((self.bytes() + mask) & !mask)
945 }
946
947 #[inline]
948 pub fn is_aligned(self, align: Align) -> bool {
949 let mask = align.bytes() - 1;
950 self.bytes() & mask == 0
951 }
952
953 #[inline]
954 pub fn checked_add<C: HasDataLayout>(self, offset: Size, cx: &C) -> Option<Size> {
955 let dl = cx.data_layout();
956
957 let bytes = self.bytes().checked_add(offset.bytes())?;
958
959 if bytes < dl.obj_size_bound() { Some(Size::from_bytes(bytes)) } else { None }
960 }
961
962 #[inline]
963 pub fn checked_mul<C: HasDataLayout>(self, count: u64, cx: &C) -> Option<Size> {
964 let dl = cx.data_layout();
965
966 let bytes = self.bytes().checked_mul(count)?;
967 if bytes < dl.obj_size_bound() { Some(Size::from_bytes(bytes)) } else { None }
968 }
969
970 #[inline]
973 pub fn sign_extend(self, value: u128) -> i128 {
974 let size = self.bits();
975 if size == 0 {
976 return 0;
978 }
979 let shift = 128 - size;
981 ((value << shift) as i128) >> shift
984 }
985
986 #[inline]
988 pub fn truncate(self, value: u128) -> u128 {
989 let size = self.bits();
990 if size == 0 {
991 return 0;
993 }
994 let shift = 128 - size;
995 (value << shift) >> shift
997 }
998
999 #[inline]
1000 pub fn signed_int_min(&self) -> i128 {
1001 self.sign_extend(1_u128 << (self.bits() - 1))
1002 }
1003
1004 #[inline]
1005 pub fn signed_int_max(&self) -> i128 {
1006 i128::MAX >> (128 - self.bits())
1007 }
1008
1009 #[inline]
1010 pub fn unsigned_int_max(&self) -> u128 {
1011 u128::MAX >> (128 - self.bits())
1012 }
1013}
1014
1015impl Add for Size {
1019 type Output = Size;
1020 #[inline]
1021 fn add(self, other: Size) -> Size {
1022 Size::from_bytes(self.bytes().checked_add(other.bytes()).unwrap_or_else(|| {
1023 {
::core::panicking::panic_fmt(format_args!("Size::add: {0} + {1} doesn\'t fit in u64",
self.bytes(), other.bytes()));
}panic!("Size::add: {} + {} doesn't fit in u64", self.bytes(), other.bytes())
1024 }))
1025 }
1026}
1027
1028impl Sub for Size {
1029 type Output = Size;
1030 #[inline]
1031 fn sub(self, other: Size) -> Size {
1032 Size::from_bytes(self.bytes().checked_sub(other.bytes()).unwrap_or_else(|| {
1033 {
::core::panicking::panic_fmt(format_args!("Size::sub: {0} - {1} would result in negative size",
self.bytes(), other.bytes()));
}panic!("Size::sub: {} - {} would result in negative size", self.bytes(), other.bytes())
1034 }))
1035 }
1036}
1037
1038impl Mul<Size> for u64 {
1039 type Output = Size;
1040 #[inline]
1041 fn mul(self, size: Size) -> Size {
1042 size * self
1043 }
1044}
1045
1046impl Mul<u64> for Size {
1047 type Output = Size;
1048 #[inline]
1049 fn mul(self, count: u64) -> Size {
1050 match self.bytes().checked_mul(count) {
1051 Some(bytes) => Size::from_bytes(bytes),
1052 None => {
::core::panicking::panic_fmt(format_args!("Size::mul: {0} * {1} doesn\'t fit in u64",
self.bytes(), count));
}panic!("Size::mul: {} * {} doesn't fit in u64", self.bytes(), count),
1053 }
1054 }
1055}
1056
1057impl AddAssign for Size {
1058 #[inline]
1059 fn add_assign(&mut self, other: Size) {
1060 *self = *self + other;
1061 }
1062}
1063
1064#[cfg(feature = "nightly")]
1065impl Step for Size {
1066 #[inline]
1067 fn steps_between(start: &Self, end: &Self) -> (usize, Option<usize>) {
1068 u64::steps_between(&start.bytes(), &end.bytes())
1069 }
1070
1071 #[inline]
1072 fn forward_checked(start: Self, count: usize) -> Option<Self> {
1073 u64::forward_checked(start.bytes(), count).map(Self::from_bytes)
1074 }
1075
1076 #[inline]
1077 fn forward_overflowing(start: Self, count: usize) -> (Self, bool) {
1078 let (s, o) = u64::forward_overflowing(start.bytes(), count);
1079 (Self::from_bytes(s), o)
1080 }
1081
1082 #[inline]
1083 fn forward(start: Self, count: usize) -> Self {
1084 Self::from_bytes(u64::forward(start.bytes(), count))
1085 }
1086
1087 #[inline]
1088 unsafe fn forward_unchecked(start: Self, count: usize) -> Self {
1089 Self::from_bytes(unsafe { u64::forward_unchecked(start.bytes(), count) })
1090 }
1091
1092 #[inline]
1093 fn backward_checked(start: Self, count: usize) -> Option<Self> {
1094 u64::backward_checked(start.bytes(), count).map(Self::from_bytes)
1095 }
1096
1097 #[inline]
1098 fn backward_overflowing(start: Self, count: usize) -> (Self, bool) {
1099 let (s, o) = u64::backward_overflowing(start.bytes(), count);
1100 (Self::from_bytes(s), o)
1101 }
1102
1103 #[inline]
1104 fn backward(start: Self, count: usize) -> Self {
1105 Self::from_bytes(u64::backward(start.bytes(), count))
1106 }
1107
1108 #[inline]
1109 unsafe fn backward_unchecked(start: Self, count: usize) -> Self {
1110 Self::from_bytes(unsafe { u64::backward_unchecked(start.bytes(), count) })
1111 }
1112}
1113
1114#[derive(#[automatically_derived]impl ::core::marker::Copy for Align { }Copy, #[automatically_derived]#[doc(hidden)]unsafe impl ::core::clone::TrivialClone
for Align {
}
#[automatically_derived]impl ::core::clone::Clone for Align {
#[inline]
#[rustc_trivial_field_reads]
fn clone(&self) -> Self {
let _: ::core::clone::AssertParamIsClone<u8>;
*self
}
}Clone, #[automatically_derived]impl ::core::marker::StructuralPartialEq for Align { }
#[automatically_derived]impl ::core::cmp::PartialEq for Align {
#[inline]
fn eq(&self, other: &Self) -> bool { self.pow2 == other.pow2 }
}PartialEq, #[automatically_derived]impl ::core::cmp::Eq for Align {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<u8>;
}
}Eq, #[automatically_derived]impl ::core::cmp::PartialOrd for Align {
#[inline]
fn partial_cmp(&self, other: &Self)
-> ::core::option::Option<::core::cmp::Ordering> {
::core::option::Option::Some(::core::cmp::Ord::cmp(self, other))
}
}PartialOrd, #[automatically_derived]impl ::core::cmp::Ord for Align {
#[inline]
fn cmp(&self, other: &Self) -> ::core::cmp::Ordering {
::core::cmp::Ord::cmp(&self.pow2, &other.pow2)
}
}Ord, #[automatically_derived]impl ::core::hash::Hash for Align {
#[inline]
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
::core::hash::Hash::hash(&self.pow2, state)
}
}Hash)]
1116#[cfg_attr(feature = "nightly", derive(const _: () =
{
impl<__E: ::rustc_serialize::Encoder>
::rustc_serialize::Encodable<__E> for Align {
fn encode(&self, __encoder: &mut __E) {
let Align { pow2: ref __binding_0 } = *self;
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
}
}
};Encodable_NoContext, const _: () =
{
impl<__D: ::rustc_serialize::Decoder>
::rustc_serialize::Decodable<__D> for Align {
fn decode(__decoder: &mut __D) -> Self {
Align {
pow2: ::rustc_serialize::Decodable::decode(__decoder),
}
}
}
};Decodable_NoContext, const _: () =
{
impl ::rustc_data_structures::stable_hash::StableHash for Align {
#[inline]
fn stable_hash<__Hcx: ::rustc_data_structures::stable_hash::StableHashCtxt>(&self,
__hcx: &mut __Hcx,
__hasher:
&mut ::rustc_data_structures::stable_hash::StableHasher) {
match *self {
Align { pow2: ref __binding_0 } => {
{ __binding_0.stable_hash(__hcx, __hasher); }
}
}
}
}
};StableHash))]
1117pub struct Align {
1118 pow2: u8,
1119}
1120
1121impl fmt::Debug for Align {
1123 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1124 f.write_fmt(format_args!("Align({0} bytes)", self.bytes()))write!(f, "Align({} bytes)", self.bytes())
1125 }
1126}
1127
1128#[derive(#[automatically_derived]#[doc(hidden)]unsafe impl ::core::clone::TrivialClone
for AlignFromBytesError {
}
#[automatically_derived]impl ::core::clone::Clone for AlignFromBytesError {
#[inline]
#[rustc_trivial_field_reads]
fn clone(&self) -> Self {
let _: ::core::clone::AssertParamIsClone<u64>;
*self
}
}Clone, #[automatically_derived]impl ::core::marker::Copy for AlignFromBytesError { }Copy)]
1129pub enum AlignFromBytesError {
1130 NotPowerOfTwo(u64),
1131 TooLarge(u64),
1132}
1133
1134impl fmt::Debug for AlignFromBytesError {
1135 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1136 fmt::Display::fmt(self, f)
1137 }
1138}
1139
1140impl fmt::Display for AlignFromBytesError {
1141 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1142 match self {
1143 AlignFromBytesError::NotPowerOfTwo(align) => f.write_fmt(format_args!("{0} is not a power of 2", align))write!(f, "{align} is not a power of 2"),
1144 AlignFromBytesError::TooLarge(align) => f.write_fmt(format_args!("{0} is too large", align))write!(f, "{align} is too large"),
1145 }
1146 }
1147}
1148
1149impl Align {
1150 pub const ONE: Align = Align { pow2: 0 };
1151 pub const FOUR: Align = Align { pow2: 2 };
1152 pub const EIGHT: Align = Align { pow2: 3 };
1153 pub const MAX: Align = Align { pow2: 29 };
1155
1156 #[inline]
1158 pub fn max_for_target(tdl: &TargetDataLayout) -> Align {
1159 let pointer_bits = u8::try_from(tdl.pointer_size().bits()).unwrap();
1160 min(Align { pow2: pointer_bits - 1 }, Align::MAX)
1161 }
1162
1163 #[inline]
1164 pub fn from_bits(bits: u64) -> Result<Align, AlignFromBytesError> {
1165 Align::from_bytes(Size::from_bits(bits).bytes())
1166 }
1167
1168 #[inline]
1169 pub const fn from_bytes(align: u64) -> Result<Align, AlignFromBytesError> {
1170 if align == 0 {
1172 return Ok(Align::ONE);
1173 }
1174
1175 #[cold]
1176 const fn not_power_of_2(align: u64) -> AlignFromBytesError {
1177 AlignFromBytesError::NotPowerOfTwo(align)
1178 }
1179
1180 #[cold]
1181 const fn too_large(align: u64) -> AlignFromBytesError {
1182 AlignFromBytesError::TooLarge(align)
1183 }
1184
1185 let tz = align.trailing_zeros();
1186 if align != (1 << tz) {
1187 return Err(not_power_of_2(align));
1188 }
1189
1190 let pow2 = tz as u8;
1191 if pow2 > Self::MAX.pow2 {
1192 return Err(too_large(align));
1193 }
1194
1195 Ok(Align { pow2 })
1196 }
1197
1198 #[inline]
1199 pub const fn bytes(self) -> u64 {
1200 1 << self.pow2
1201 }
1202
1203 #[inline]
1204 pub fn bytes_usize(self) -> usize {
1205 self.bytes().try_into().unwrap()
1206 }
1207
1208 #[inline]
1209 pub const fn bits(self) -> u64 {
1210 self.bytes() * 8
1211 }
1212
1213 #[inline]
1214 pub fn bits_usize(self) -> usize {
1215 self.bits().try_into().unwrap()
1216 }
1217
1218 #[inline]
1223 pub fn max_aligned_factor(size: Size) -> Align {
1224 Align { pow2: size.bytes().trailing_zeros() as u8 }
1225 }
1226
1227 #[inline]
1229 pub fn restrict_for_offset(self, size: Size) -> Align {
1230 self.min(Align::max_aligned_factor(size))
1231 }
1232}
1233
1234#[derive(#[automatically_derived]impl ::core::marker::Copy for Integer { }Copy, #[automatically_derived]#[doc(hidden)]unsafe impl ::core::clone::TrivialClone
for Integer {
}
#[automatically_derived]impl ::core::clone::Clone for Integer {
#[inline]
#[rustc_trivial_field_reads]
fn clone(&self) -> Self { *self }
}Clone, #[automatically_derived]impl ::core::marker::StructuralPartialEq for Integer {
}
#[automatically_derived]impl ::core::cmp::PartialEq for Integer {
#[inline]
fn eq(&self, other: &Self) -> bool {
::core::intrinsics::discriminant_value(self) ==
::core::intrinsics::discriminant_value(other)
}
}PartialEq, #[automatically_derived]impl ::core::cmp::Eq for Integer { }Eq, #[automatically_derived]impl ::core::cmp::PartialOrd for Integer {
#[inline]
fn partial_cmp(&self, other: &Self)
-> ::core::option::Option<::core::cmp::Ordering> {
::core::option::Option::Some(::core::cmp::Ord::cmp(self, other))
}
}PartialOrd, #[automatically_derived]impl ::core::cmp::Ord for Integer {
#[inline]
fn cmp(&self, other: &Self) -> ::core::cmp::Ordering {
::core::cmp::Ord::cmp(&::core::intrinsics::discriminant_value(self),
&::core::intrinsics::discriminant_value(other))
}
}Ord, #[automatically_derived]impl ::core::hash::Hash for Integer {
#[inline]
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
::core::hash::Hash::hash(&::core::intrinsics::discriminant_value(self),
state)
}
}Hash, #[automatically_derived]impl ::core::fmt::Debug for Integer {
#[inline]
#[rustc_trivial_field_reads]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_c_like_enum_write_str(f,
"I8 I16 I32 I64 I128",
match self {
Integer::I8 => 0usize,
Integer::I16 => 3usize,
Integer::I32 => 7usize,
Integer::I64 => 11usize,
Integer::I128 => 15usize,
})
}
}Debug)]
1236#[cfg_attr(feature = "nightly", derive(const _: () =
{
impl<__E: ::rustc_serialize::Encoder>
::rustc_serialize::Encodable<__E> for Integer {
fn encode(&self, __encoder: &mut __E) {
let disc =
match *self {
Integer::I8 => { 0usize }
Integer::I16 => { 1usize }
Integer::I32 => { 2usize }
Integer::I64 => { 3usize }
Integer::I128 => { 4usize }
};
::rustc_serialize::Encoder::emit_u8(__encoder, disc as u8);
}
}
};Encodable_NoContext, const _: () =
{
impl<__D: ::rustc_serialize::Decoder>
::rustc_serialize::Decodable<__D> for Integer {
fn decode(__decoder: &mut __D) -> Self {
match ::rustc_serialize::Decoder::read_u8(__decoder) as usize
{
0usize => { Integer::I8 }
1usize => { Integer::I16 }
2usize => { Integer::I32 }
3usize => { Integer::I64 }
4usize => { Integer::I128 }
n => {
::core::panicking::panic_fmt(format_args!("invalid enum variant tag while decoding `Integer`, expected 0..5, actual {0}",
n));
}
}
}
}
};Decodable_NoContext, const _: () =
{
impl ::rustc_data_structures::stable_hash::StableHash for Integer {
#[inline]
fn stable_hash<__Hcx: ::rustc_data_structures::stable_hash::StableHashCtxt>(&self,
__hcx: &mut __Hcx,
__hasher:
&mut ::rustc_data_structures::stable_hash::StableHasher) {
match *self {
Integer::I8 => 0u8.stable_hash(__hcx, __hasher),
Integer::I16 => 1u8.stable_hash(__hcx, __hasher),
Integer::I32 => 2u8.stable_hash(__hcx, __hasher),
Integer::I64 => 3u8.stable_hash(__hcx, __hasher),
Integer::I128 => 4u8.stable_hash(__hcx, __hasher),
}
match *self {
Integer::I8 => {}
Integer::I16 => {}
Integer::I32 => {}
Integer::I64 => {}
Integer::I128 => {}
}
}
}
};StableHash))]
1237pub enum Integer {
1238 I8,
1239 I16,
1240 I32,
1241 I64,
1242 I128,
1243}
1244
1245impl Integer {
1246 pub fn int_ty_str(self) -> &'static str {
1247 use Integer::*;
1248 match self {
1249 I8 => "i8",
1250 I16 => "i16",
1251 I32 => "i32",
1252 I64 => "i64",
1253 I128 => "i128",
1254 }
1255 }
1256
1257 pub fn uint_ty_str(self) -> &'static str {
1258 use Integer::*;
1259 match self {
1260 I8 => "u8",
1261 I16 => "u16",
1262 I32 => "u32",
1263 I64 => "u64",
1264 I128 => "u128",
1265 }
1266 }
1267
1268 #[inline]
1269 pub fn size(self) -> Size {
1270 use Integer::*;
1271 match self {
1272 I8 => Size::from_bytes(1),
1273 I16 => Size::from_bytes(2),
1274 I32 => Size::from_bytes(4),
1275 I64 => Size::from_bytes(8),
1276 I128 => Size::from_bytes(16),
1277 }
1278 }
1279
1280 pub fn from_attr<C: HasDataLayout>(cx: &C, ity: IntegerType) -> Integer {
1282 let dl = cx.data_layout();
1283
1284 match ity {
1285 IntegerType::Pointer(_) => dl.ptr_sized_integer(),
1286 IntegerType::Fixed(x, _) => x,
1287 }
1288 }
1289
1290 pub fn align<C: HasDataLayout>(self, cx: &C) -> Align {
1291 use Integer::*;
1292 let dl = cx.data_layout();
1293
1294 match self {
1295 I8 => Align::ONE,
1296 I16 => dl.i16_align,
1297 I32 => dl.i32_align,
1298 I64 => dl.i64_align,
1299 I128 => dl.i128_align,
1300 }
1301 }
1302
1303 #[inline]
1305 pub fn signed_max(self) -> i128 {
1306 use Integer::*;
1307 match self {
1308 I8 => i8::MAX as i128,
1309 I16 => i16::MAX as i128,
1310 I32 => i32::MAX as i128,
1311 I64 => i64::MAX as i128,
1312 I128 => i128::MAX,
1313 }
1314 }
1315
1316 #[inline]
1318 pub fn signed_min(self) -> i128 {
1319 use Integer::*;
1320 match self {
1321 I8 => i8::MIN as i128,
1322 I16 => i16::MIN as i128,
1323 I32 => i32::MIN as i128,
1324 I64 => i64::MIN as i128,
1325 I128 => i128::MIN,
1326 }
1327 }
1328
1329 #[inline]
1331 pub fn fit_signed(x: i128) -> Integer {
1332 use Integer::*;
1333 match x {
1334 -0x0000_0000_0000_0080..=0x0000_0000_0000_007f => I8,
1335 -0x0000_0000_0000_8000..=0x0000_0000_0000_7fff => I16,
1336 -0x0000_0000_8000_0000..=0x0000_0000_7fff_ffff => I32,
1337 -0x8000_0000_0000_0000..=0x7fff_ffff_ffff_ffff => I64,
1338 _ => I128,
1339 }
1340 }
1341
1342 #[inline]
1344 pub fn fit_unsigned(x: u128) -> Integer {
1345 use Integer::*;
1346 match x {
1347 0..=0x0000_0000_0000_00ff => I8,
1348 0..=0x0000_0000_0000_ffff => I16,
1349 0..=0x0000_0000_ffff_ffff => I32,
1350 0..=0xffff_ffff_ffff_ffff => I64,
1351 _ => I128,
1352 }
1353 }
1354
1355 pub fn for_align<C: HasDataLayout>(cx: &C, wanted: Align) -> Option<Integer> {
1357 use Integer::*;
1358 let dl = cx.data_layout();
1359
1360 [I8, I16, I32, I64, I128].into_iter().find(|&candidate| {
1361 wanted == candidate.align(dl) && wanted.bytes() == candidate.size().bytes()
1362 })
1363 }
1364
1365 pub fn approximate_align<C: HasDataLayout>(cx: &C, wanted: Align) -> Integer {
1367 use Integer::*;
1368 let dl = cx.data_layout();
1369
1370 for candidate in [I64, I32, I16] {
1372 if wanted >= candidate.align(dl) && wanted.bytes() >= candidate.size().bytes() {
1373 return candidate;
1374 }
1375 }
1376 I8
1377 }
1378
1379 #[inline]
1382 pub fn from_size(size: Size) -> Result<Self, String> {
1383 match size.bits() {
1384 8 => Ok(Integer::I8),
1385 16 => Ok(Integer::I16),
1386 32 => Ok(Integer::I32),
1387 64 => Ok(Integer::I64),
1388 128 => Ok(Integer::I128),
1389 _ => Err(::alloc::__export::must_use({
::alloc::fmt::format(format_args!("rust does not support integers with {0} bits",
size.bits()))
})format!("rust does not support integers with {} bits", size.bits())),
1390 }
1391 }
1392}
1393
1394#[derive(#[automatically_derived]impl ::core::marker::Copy for Float { }Copy, #[automatically_derived]#[doc(hidden)]unsafe impl ::core::clone::TrivialClone
for Float {
}
#[automatically_derived]impl ::core::clone::Clone for Float {
#[inline]
#[rustc_trivial_field_reads]
fn clone(&self) -> Self { *self }
}Clone, #[automatically_derived]impl ::core::marker::StructuralPartialEq for Float { }
#[automatically_derived]impl ::core::cmp::PartialEq for Float {
#[inline]
fn eq(&self, other: &Self) -> bool {
::core::intrinsics::discriminant_value(self) ==
::core::intrinsics::discriminant_value(other)
}
}PartialEq, #[automatically_derived]impl ::core::cmp::Eq for Float { }Eq, #[automatically_derived]impl ::core::cmp::PartialOrd for Float {
#[inline]
fn partial_cmp(&self, other: &Self)
-> ::core::option::Option<::core::cmp::Ordering> {
::core::option::Option::Some(::core::cmp::Ord::cmp(self, other))
}
}PartialOrd, #[automatically_derived]impl ::core::cmp::Ord for Float {
#[inline]
fn cmp(&self, other: &Self) -> ::core::cmp::Ordering {
::core::cmp::Ord::cmp(&::core::intrinsics::discriminant_value(self),
&::core::intrinsics::discriminant_value(other))
}
}Ord, #[automatically_derived]impl ::core::hash::Hash for Float {
#[inline]
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
::core::hash::Hash::hash(&::core::intrinsics::discriminant_value(self),
state)
}
}Hash, #[automatically_derived]impl ::core::fmt::Debug for Float {
#[inline]
#[rustc_trivial_field_reads]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_c_like_enum_write_str(f,
"F16 F16B F32 F64 X87F80 F128 PpcF128",
match self {
Float::F16 => 0usize,
Float::F16B => 4usize,
Float::F32 => 9usize,
Float::F64 => 13usize,
Float::X87F80 => 17usize,
Float::F128 => 24usize,
Float::PpcF128 => 29usize,
})
}
}Debug)]
1396#[cfg_attr(feature = "nightly", derive(const _: () =
{
impl ::rustc_data_structures::stable_hash::StableHash for Float {
#[inline]
fn stable_hash<__Hcx: ::rustc_data_structures::stable_hash::StableHashCtxt>(&self,
__hcx: &mut __Hcx,
__hasher:
&mut ::rustc_data_structures::stable_hash::StableHasher) {
match *self {
Float::F16 => 0u8.stable_hash(__hcx, __hasher),
Float::F16B => 1u8.stable_hash(__hcx, __hasher),
Float::F32 => 2u8.stable_hash(__hcx, __hasher),
Float::F64 => 3u8.stable_hash(__hcx, __hasher),
Float::X87F80 => 4u8.stable_hash(__hcx, __hasher),
Float::F128 => 5u8.stable_hash(__hcx, __hasher),
Float::PpcF128 => 6u8.stable_hash(__hcx, __hasher),
}
match *self {
Float::F16 => {}
Float::F16B => {}
Float::F32 => {}
Float::F64 => {}
Float::X87F80 => {}
Float::F128 => {}
Float::PpcF128 => {}
}
}
}
};StableHash))]
1397pub enum Float {
1398 F16,
1399 F16B,
1403 F32,
1404 F64,
1405 X87F80,
1415 F128,
1416 PpcF128,
1422}
1423
1424impl Float {
1425 pub fn size(self) -> Size {
1426 use Float::*;
1427
1428 match self {
1429 F16 => Size::from_bits(16),
1430 F16B => Size::from_bits(16),
1431 F32 => Size::from_bits(32),
1432 F64 => Size::from_bits(64),
1433 X87F80 => Size::from_bits(80),
1434 F128 => Size::from_bits(128),
1435 PpcF128 => Size::from_bits(128),
1436 }
1437 }
1438
1439 pub fn align<C: HasDataLayout>(self, cx: &C) -> Align {
1440 use Float::*;
1441 let dl = cx.data_layout();
1442
1443 match self {
1444 F16 | F16B => dl.f16_align,
1445 F32 => dl.f32_align,
1446 F64 => dl.f64_align,
1447 X87F80 => Align::ONE,
1450 F128 => dl.f128_align,
1451 PpcF128 => dl.f128_align,
1452 }
1453 }
1454
1455 pub fn ty_str(self) -> &'static str {
1456 use Float::*;
1457
1458 match self {
1459 F16 => "f16",
1460 F16B => "f16b",
1461 F32 => "f32",
1462 F64 => "f64",
1463 X87F80 => "x87_f80",
1464 F128 => "f128",
1465 PpcF128 => "ppcf128",
1466 }
1467 }
1468
1469 pub fn is_ieee(self) -> bool {
1470 use Float::*;
1471
1472 match self {
1473 F16 | F32 | F64 | F128 => true,
1474 F16B | X87F80 | PpcF128 => false,
1475 }
1476 }
1477}
1478
1479#[derive(#[automatically_derived]impl ::core::marker::Copy for Numeric { }Copy, #[automatically_derived]#[doc(hidden)]unsafe impl ::core::clone::TrivialClone
for Numeric {
}
#[automatically_derived]impl ::core::clone::Clone for Numeric {
#[inline]
#[rustc_trivial_field_reads]
fn clone(&self) -> Self {
let _: ::core::clone::AssertParamIsClone<Integer>;
let _: ::core::clone::AssertParamIsClone<bool>;
let _: ::core::clone::AssertParamIsClone<Float>;
*self
}
}Clone, #[automatically_derived]impl ::core::marker::StructuralPartialEq for Numeric {
}
#[automatically_derived]impl ::core::cmp::PartialEq for Numeric {
#[inline]
fn eq(&self, other: &Self) -> bool {
::core::intrinsics::discriminant_value(self) ==
::core::intrinsics::discriminant_value(other) &&
match (self, other) {
(Self::Int(__self_0, __self_1), Self::Int(__arg1_0, __arg1_1))
=> __self_1 == __arg1_1 && __self_0 == __arg1_0,
(Self::Float(__self_0), Self::Float(__arg1_0)) =>
__self_0 == __arg1_0,
_ => unsafe { ::core::intrinsics::unreachable() }
}
}
}PartialEq, #[automatically_derived]impl ::core::cmp::Eq for Numeric {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<Integer>;
let _: ::core::cmp::AssertParamIsEq<bool>;
let _: ::core::cmp::AssertParamIsEq<Float>;
}
}Eq, #[automatically_derived]impl ::core::hash::Hash for Numeric {
#[inline]
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
::core::hash::Hash::hash(&::core::intrinsics::discriminant_value(self),
state);
match self {
Self::Int(__self_0, __self_1) => {
::core::hash::Hash::hash(__self_0, state);
::core::hash::Hash::hash(__self_1, state)
}
Self::Float(__self_0) =>
::core::hash::Hash::hash(__self_0, state),
}
}
}Hash)]
1481#[cfg_attr(feature = "nightly", derive(const _: () =
{
impl ::rustc_data_structures::stable_hash::StableHash for Numeric {
#[inline]
fn stable_hash<__Hcx: ::rustc_data_structures::stable_hash::StableHashCtxt>(&self,
__hcx: &mut __Hcx,
__hasher:
&mut ::rustc_data_structures::stable_hash::StableHasher) {
match *self {
Numeric::Int(ref __binding_0, ref __binding_1) =>
0u8.stable_hash(__hcx, __hasher),
Numeric::Float(ref __binding_0) =>
1u8.stable_hash(__hcx, __hasher),
}
match *self {
Numeric::Int(ref __binding_0, ref __binding_1) => {
{ __binding_0.stable_hash(__hcx, __hasher); }
{ __binding_1.stable_hash(__hcx, __hasher); }
}
Numeric::Float(ref __binding_0) => {
{ __binding_0.stable_hash(__hcx, __hasher); }
}
}
}
}
};StableHash))]
1482pub enum Numeric {
1483 Int(Integer, bool),
1485 Float(Float),
1486}
1487
1488impl Numeric {
1489 pub fn size(self) -> Size {
1490 match self {
1491 Numeric::Int(integer, _) => integer.size(),
1492 Numeric::Float(float) => float.size(),
1493 }
1494 }
1495
1496 pub fn reg_kind(self) -> RegKind {
1497 match self {
1498 Numeric::Int(_, _) => RegKind::Integer,
1499 Numeric::Float(Float::PpcF128) => RegKind::PpcF128,
1500 Numeric::Float(
1501 Float::F16 | Float::F16B | Float::F32 | Float::F64 | Float::X87F80 | Float::F128,
1502 ) => RegKind::Float,
1503 }
1504 }
1505}
1506
1507#[derive(#[automatically_derived]impl ::core::marker::Copy for Primitive { }Copy, #[automatically_derived]#[doc(hidden)]unsafe impl ::core::clone::TrivialClone
for Primitive {
}
#[automatically_derived]impl ::core::clone::Clone for Primitive {
#[inline]
#[rustc_trivial_field_reads]
fn clone(&self) -> Self {
let _: ::core::clone::AssertParamIsClone<Integer>;
let _: ::core::clone::AssertParamIsClone<bool>;
let _: ::core::clone::AssertParamIsClone<Float>;
let _: ::core::clone::AssertParamIsClone<AddressSpace>;
*self
}
}Clone, #[automatically_derived]impl ::core::marker::StructuralPartialEq for Primitive
{
}
#[automatically_derived]impl ::core::cmp::PartialEq for Primitive {
#[inline]
fn eq(&self, other: &Self) -> bool {
::core::intrinsics::discriminant_value(self) ==
::core::intrinsics::discriminant_value(other) &&
match (self, other) {
(Self::Int(__self_0, __self_1), Self::Int(__arg1_0, __arg1_1))
=> __self_1 == __arg1_1 && __self_0 == __arg1_0,
(Self::Float(__self_0), Self::Float(__arg1_0)) =>
__self_0 == __arg1_0,
(Self::Pointer(__self_0), Self::Pointer(__arg1_0)) =>
__self_0 == __arg1_0,
_ => true,
}
}
}PartialEq, #[automatically_derived]impl ::core::cmp::Eq for Primitive {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<Integer>;
let _: ::core::cmp::AssertParamIsEq<bool>;
let _: ::core::cmp::AssertParamIsEq<Float>;
let _: ::core::cmp::AssertParamIsEq<AddressSpace>;
}
}Eq, #[automatically_derived]impl ::core::hash::Hash for Primitive {
#[inline]
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
::core::hash::Hash::hash(&::core::intrinsics::discriminant_value(self),
state);
match self {
Self::Int(__self_0, __self_1) => {
::core::hash::Hash::hash(__self_0, state);
::core::hash::Hash::hash(__self_1, state)
}
Self::Float(__self_0) =>
::core::hash::Hash::hash(__self_0, state),
Self::Pointer(__self_0) =>
::core::hash::Hash::hash(__self_0, state),
_ => {}
}
}
}Hash)]
1509#[cfg_attr(feature = "nightly", derive(const _: () =
{
impl ::rustc_data_structures::stable_hash::StableHash for Primitive {
#[inline]
fn stable_hash<__Hcx: ::rustc_data_structures::stable_hash::StableHashCtxt>(&self,
__hcx: &mut __Hcx,
__hasher:
&mut ::rustc_data_structures::stable_hash::StableHasher) {
match *self {
Primitive::Bool => 0u8.stable_hash(__hcx, __hasher),
Primitive::Int(ref __binding_0, ref __binding_1) =>
1u8.stable_hash(__hcx, __hasher),
Primitive::Float(ref __binding_0) =>
2u8.stable_hash(__hcx, __hasher),
Primitive::Pointer(ref __binding_0) =>
3u8.stable_hash(__hcx, __hasher),
}
match *self {
Primitive::Bool => {}
Primitive::Int(ref __binding_0, ref __binding_1) => {
{ __binding_0.stable_hash(__hcx, __hasher); }
{ __binding_1.stable_hash(__hcx, __hasher); }
}
Primitive::Float(ref __binding_0) => {
{ __binding_0.stable_hash(__hcx, __hasher); }
}
Primitive::Pointer(ref __binding_0) => {
{ __binding_0.stable_hash(__hcx, __hasher); }
}
}
}
}
};StableHash))]
1510pub enum Primitive {
1511 Bool,
1512 Int(Integer, bool),
1520 Float(Float),
1521 Pointer(AddressSpace),
1522}
1523
1524impl fmt::Debug for Primitive {
1525 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1526 let name = match *self {
1527 Primitive::Bool => "bool",
1528 Primitive::Int(integer, is_signed) => {
1529 if is_signed {
1530 integer.int_ty_str()
1531 } else {
1532 integer.uint_ty_str()
1533 }
1534 }
1535 Primitive::Float(float) => float.ty_str(),
1536 Primitive::Pointer(addr_space) => {
1537 if addr_space == AddressSpace::ZERO {
1538 "pointer"
1539 } else {
1540 return f.write_fmt(format_args!("pointer({0:?})", addr_space))write!(f, "pointer({addr_space:?})");
1541 }
1542 }
1543 };
1544 f.write_str(name)
1545 }
1546}
1547
1548impl Primitive {
1549 pub fn size<C: HasDataLayout>(self, cx: &C) -> Size {
1550 use Primitive::*;
1551 let dl = cx.data_layout();
1552
1553 match self {
1554 Bool => Size::from_bits(1),
1555 Int(i, _) => i.size(),
1556 Float(f) => f.size(),
1557 Pointer(a) => dl.pointer_size_in(a),
1558 }
1559 }
1560
1561 pub fn default_align<C: HasDataLayout>(self, cx: &C) -> Align {
1566 use Primitive::*;
1567 let dl = cx.data_layout();
1568
1569 match self {
1570 Bool => Align::ONE,
1571 Int(i, _) => i.align(dl),
1572 Float(f) => f.align(dl),
1573 Pointer(a) => dl.pointer_align_in(a),
1574 }
1575 }
1576}
1577
1578#[derive(#[automatically_derived]#[doc(hidden)]unsafe impl ::core::clone::TrivialClone
for Scalar {
}
#[automatically_derived]impl ::core::clone::Clone for Scalar {
#[inline]
#[rustc_trivial_field_reads]
fn clone(&self) -> Self {
let _: ::core::clone::AssertParamIsClone<Primitive>;
let _: ::core::clone::AssertParamIsClone<WrappingRange>;
*self
}
}Clone, #[automatically_derived]impl ::core::marker::Copy for Scalar { }Copy, #[automatically_derived]impl ::core::marker::StructuralPartialEq for Scalar {
}
#[automatically_derived]impl ::core::cmp::PartialEq for Scalar {
#[inline]
fn eq(&self, other: &Self) -> bool {
::core::intrinsics::discriminant_value(self) ==
::core::intrinsics::discriminant_value(other) &&
match (self, other) {
(Self::Initialized { value: __self_0, valid_range: __self_1 },
Self::Initialized { value: __arg1_0, valid_range: __arg1_1
}) => __self_0 == __arg1_0 && __self_1 == __arg1_1,
(Self::Union { value: __self_0 }, Self::Union {
value: __arg1_0 }) => __self_0 == __arg1_0,
_ => unsafe { ::core::intrinsics::unreachable() }
}
}
}PartialEq, #[automatically_derived]impl ::core::cmp::Eq for Scalar {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<Primitive>;
let _: ::core::cmp::AssertParamIsEq<WrappingRange>;
}
}Eq, #[automatically_derived]impl ::core::hash::Hash for Scalar {
#[inline]
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
::core::hash::Hash::hash(&::core::intrinsics::discriminant_value(self),
state);
match self {
Self::Initialized { value: __self_0, valid_range: __self_1 } => {
::core::hash::Hash::hash(__self_0, state);
::core::hash::Hash::hash(__self_1, state)
}
Self::Union { value: __self_0 } =>
::core::hash::Hash::hash(__self_0, state),
}
}
}Hash)]
1580#[cfg_attr(feature = "nightly", derive(const _: () =
{
impl ::rustc_data_structures::stable_hash::StableHash for Scalar {
#[inline]
fn stable_hash<__Hcx: ::rustc_data_structures::stable_hash::StableHashCtxt>(&self,
__hcx: &mut __Hcx,
__hasher:
&mut ::rustc_data_structures::stable_hash::StableHasher) {
match *self {
Scalar::Initialized {
value: ref __binding_0, valid_range: ref __binding_1 } =>
0u8.stable_hash(__hcx, __hasher),
Scalar::Union { value: ref __binding_0 } =>
1u8.stable_hash(__hcx, __hasher),
}
match *self {
Scalar::Initialized {
value: ref __binding_0, valid_range: ref __binding_1 } => {
{ __binding_0.stable_hash(__hcx, __hasher); }
{ __binding_1.stable_hash(__hcx, __hasher); }
}
Scalar::Union { value: ref __binding_0 } => {
{ __binding_0.stable_hash(__hcx, __hasher); }
}
}
}
}
};StableHash))]
1581pub enum Scalar {
1582 Initialized {
1583 value: Primitive,
1584
1585 valid_range: WrappingRange,
1589 },
1590 Union {
1591 value: Primitive,
1597 },
1598}
1599
1600impl fmt::Debug for Scalar {
1601 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1602 match self {
1603 Scalar::Initialized { value, valid_range } => {
1604 let (size, is_signed) = match *value {
1605 Primitive::Bool => (Size::from_bits(1), false),
1606 Primitive::Int(integer, is_signed) => (integer.size(), is_signed),
1607 Primitive::Float(float) => (float.size(), false),
1608 Primitive::Pointer(_) => (Size::from_bits(128), false),
1609 };
1610 f.write_fmt(format_args!("{1:?} is {0:?}",
valid_range.debug_as(size, is_signed), value))write!(f, "{value:?} is {:?}", valid_range.debug_as(size, is_signed))
1611 }
1612 Scalar::Union { value } => {
1613 f.write_fmt(format_args!("union {0:?}", value))write!(f, "union {value:?}")
1614 }
1615 }
1616 }
1617}
1618
1619impl Scalar {
1620 #[inline]
1621 pub fn is_bool(&self) -> bool {
1622 #[allow(non_exhaustive_omitted_patterns)] match self {
Scalar::Initialized { value: Primitive::Bool, valid_range: _ } => true,
_ => false,
}matches!(self, Scalar::Initialized { value: Primitive::Bool, valid_range: _ })
1623 }
1624
1625 pub fn primitive(&self) -> Primitive {
1628 match *self {
1629 Scalar::Initialized { value, .. } | Scalar::Union { value } => value,
1630 }
1631 }
1632
1633 pub fn default_align(self, cx: &impl HasDataLayout) -> Align {
1638 self.primitive().default_align(cx)
1639 }
1640
1641 pub fn size(self, cx: &impl HasDataLayout) -> Size {
1642 self.primitive().size(cx)
1643 }
1644
1645 #[inline]
1646 pub fn to_union(&self) -> Self {
1647 Self::Union { value: self.primitive() }
1648 }
1649
1650 #[inline]
1651 pub fn valid_range(&self, cx: &impl HasDataLayout) -> WrappingRange {
1652 match *self {
1653 Scalar::Initialized { valid_range, .. } => valid_range,
1654 Scalar::Union { value } => WrappingRange::full(value.size(cx)),
1655 }
1656 }
1657
1658 #[inline]
1659 pub fn valid_range_mut(&mut self) -> &mut WrappingRange {
1662 match self {
1663 Scalar::Initialized { valid_range, .. } => valid_range,
1664 Scalar::Union { .. } => {
::core::panicking::panic_fmt(format_args!("cannot change the valid range of a union"));
}panic!("cannot change the valid range of a union"),
1665 }
1666 }
1667
1668 #[inline]
1671 pub fn is_always_valid<C: HasDataLayout>(&self, cx: &C) -> bool {
1672 match *self {
1673 Scalar::Initialized { valid_range, .. } => valid_range.is_full_for(self.size(cx)),
1674 Scalar::Union { .. } => true,
1675 }
1676 }
1677
1678 #[inline]
1680 pub fn is_uninit_valid(&self) -> bool {
1681 match *self {
1682 Scalar::Initialized { .. } => false,
1683 Scalar::Union { .. } => true,
1684 }
1685 }
1686
1687 #[inline]
1689 pub fn is_signed(&self) -> bool {
1690 match self.primitive() {
1691 Primitive::Int(_, signed) => signed,
1692 _ => false,
1693 }
1694 }
1695}
1696
1697#[derive(#[automatically_derived]impl<FieldIdx: ::core::cmp::PartialEq + Idx>
::core::marker::StructuralPartialEq for FieldsShape<FieldIdx> {
}
#[automatically_derived]impl<FieldIdx: ::core::cmp::PartialEq + Idx>
::core::cmp::PartialEq for FieldsShape<FieldIdx> {
#[inline]
fn eq(&self, other: &Self) -> bool {
::core::intrinsics::discriminant_value(self) ==
::core::intrinsics::discriminant_value(other) &&
match (self, other) {
(Self::Union(__self_0), Self::Union(__arg1_0)) =>
__self_0 == __arg1_0,
(Self::Array { stride: __self_0, count: __self_1 },
Self::Array { stride: __arg1_0, count: __arg1_1 }) =>
__self_1 == __arg1_1 && __self_0 == __arg1_0,
(Self::Arbitrary {
offsets: __self_0, in_memory_order: __self_1 },
Self::Arbitrary {
offsets: __arg1_0, in_memory_order: __arg1_1 }) =>
__self_0 == __arg1_0 && __self_1 == __arg1_1,
_ => true,
}
}
}PartialEq, #[automatically_derived]impl<FieldIdx: ::core::cmp::Eq + Idx> ::core::cmp::Eq
for FieldsShape<FieldIdx> {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<NonZero<usize>>;
let _: ::core::cmp::AssertParamIsEq<Size>;
let _: ::core::cmp::AssertParamIsEq<u64>;
let _: ::core::cmp::AssertParamIsEq<IndexVec<FieldIdx, Size>>;
let _: ::core::cmp::AssertParamIsEq<IndexVec<u32, FieldIdx>>;
}
}Eq, #[automatically_derived]impl<FieldIdx: ::core::hash::Hash + Idx>
::core::hash::Hash for FieldsShape<FieldIdx> {
#[inline]
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
::core::hash::Hash::hash(&::core::intrinsics::discriminant_value(self),
state);
match self {
Self::Union(__self_0) =>
::core::hash::Hash::hash(__self_0, state),
Self::Array { stride: __self_0, count: __self_1 } => {
::core::hash::Hash::hash(__self_0, state);
::core::hash::Hash::hash(__self_1, state)
}
Self::Arbitrary { offsets: __self_0, in_memory_order: __self_1 }
=> {
::core::hash::Hash::hash(__self_0, state);
::core::hash::Hash::hash(__self_1, state)
}
_ => {}
}
}
}Hash, #[automatically_derived]impl<FieldIdx: ::core::clone::Clone + Idx>
::core::clone::Clone for FieldsShape<FieldIdx> {
#[inline]
#[rustc_trivial_field_reads]
fn clone(&self) -> Self {
match self {
Self::Primitive => FieldsShape::Primitive,
Self::Union(__self_0) =>
FieldsShape::Union(::core::clone::Clone::clone(__self_0)),
Self::Array { stride: __self_0, count: __self_1 } =>
FieldsShape::Array {
stride: ::core::clone::Clone::clone(__self_0),
count: ::core::clone::Clone::clone(__self_1),
},
Self::Arbitrary { offsets: __self_0, in_memory_order: __self_1 }
=>
FieldsShape::Arbitrary {
offsets: ::core::clone::Clone::clone(__self_0),
in_memory_order: ::core::clone::Clone::clone(__self_1),
},
}
}
}Clone, #[automatically_derived]impl<FieldIdx: ::core::fmt::Debug + Idx>
::core::fmt::Debug for FieldsShape<FieldIdx> {
#[inline]
#[rustc_trivial_field_reads]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
Self::Primitive =>
::core::fmt::Formatter::write_str(f, "Primitive"),
Self::Union(__self_0) =>
::core::fmt::Formatter::debug_struct_field1_finish(f, "Union",
&__self_0),
Self::Array { stride: __self_0, count: __self_1 } =>
::core::fmt::Formatter::debug_struct_field2_finish(f,
"Array stride count", __self_0, &__self_1),
Self::Arbitrary { offsets: __self_0, in_memory_order: __self_1 }
=>
::core::fmt::Formatter::debug_struct_field2_finish(f,
"Arbitrary offsets in_memory_order", __self_0, &__self_1),
}
}
}Debug)]
1700#[cfg_attr(feature = "nightly", derive(const _: () =
{
impl<FieldIdx: Idx> ::rustc_data_structures::stable_hash::StableHash
for FieldsShape<FieldIdx> where
FieldIdx: ::rustc_data_structures::stable_hash::StableHash {
#[inline]
fn stable_hash<__Hcx: ::rustc_data_structures::stable_hash::StableHashCtxt>(&self,
__hcx: &mut __Hcx,
__hasher:
&mut ::rustc_data_structures::stable_hash::StableHasher) {
match *self {
FieldsShape::Primitive => 0u8.stable_hash(__hcx, __hasher),
FieldsShape::Union(ref __binding_0) =>
1u8.stable_hash(__hcx, __hasher),
FieldsShape::Array {
stride: ref __binding_0, count: ref __binding_1 } =>
2u8.stable_hash(__hcx, __hasher),
FieldsShape::Arbitrary {
offsets: ref __binding_0, in_memory_order: ref __binding_1 }
=> 3u8.stable_hash(__hcx, __hasher),
}
match *self {
FieldsShape::Primitive => {}
FieldsShape::Union(ref __binding_0) => {
{ __binding_0.stable_hash(__hcx, __hasher); }
}
FieldsShape::Array {
stride: ref __binding_0, count: ref __binding_1 } => {
{ __binding_0.stable_hash(__hcx, __hasher); }
{ __binding_1.stable_hash(__hcx, __hasher); }
}
FieldsShape::Arbitrary {
offsets: ref __binding_0, in_memory_order: ref __binding_1 }
=> {
{ __binding_0.stable_hash(__hcx, __hasher); }
{ __binding_1.stable_hash(__hcx, __hasher); }
}
}
}
}
};StableHash))]
1701pub enum FieldsShape<FieldIdx: Idx> {
1702 Primitive,
1704
1705 Union(NonZero<usize>),
1707
1708 Array { stride: Size, count: u64 },
1710
1711 Arbitrary {
1719 offsets: IndexVec<FieldIdx, Size>,
1724
1725 in_memory_order: IndexVec<u32, FieldIdx>,
1733 },
1734}
1735
1736impl<FieldIdx: Idx> FieldsShape<FieldIdx> {
1737 #[inline]
1738 pub fn count(&self) -> usize {
1739 match *self {
1740 FieldsShape::Primitive => 0,
1741 FieldsShape::Union(count) => count.get(),
1742 FieldsShape::Array { count, .. } => count.try_into().unwrap(),
1743 FieldsShape::Arbitrary { ref offsets, .. } => offsets.len(),
1744 }
1745 }
1746
1747 #[inline]
1748 pub fn offset(&self, i: usize) -> Size {
1749 match *self {
1750 FieldsShape::Primitive => {
1751 {
::core::panicking::panic_fmt(format_args!("internal error: entered unreachable code: {0}",
format_args!("FieldsShape::offset: `Primitive`s have no fields")));
}unreachable!("FieldsShape::offset: `Primitive`s have no fields")
1752 }
1753 FieldsShape::Union(count) => {
1754 if !(i < count.get()) {
{
::core::panicking::panic_fmt(format_args!("tried to access field {0} of union with {1} fields",
i, count));
}
};assert!(i < count.get(), "tried to access field {i} of union with {count} fields");
1755 Size::ZERO
1756 }
1757 FieldsShape::Array { stride, count } => {
1758 let i = u64::try_from(i).unwrap();
1759 if !(i < count) {
{
::core::panicking::panic_fmt(format_args!("tried to access field {0} of array with {1} fields",
i, count));
}
};assert!(i < count, "tried to access field {i} of array with {count} fields");
1760 stride * i
1761 }
1762 FieldsShape::Arbitrary { ref offsets, .. } => offsets[FieldIdx::new(i)],
1763 }
1764 }
1765
1766 #[inline]
1768 pub fn index_by_increasing_offset(&self) -> impl ExactSizeIterator<Item = usize> {
1769 let pseudofield_count = if let FieldsShape::Primitive = self { 1 } else { self.count() };
1773
1774 (0..pseudofield_count).map(move |i| match self {
1775 FieldsShape::Primitive | FieldsShape::Union(_) | FieldsShape::Array { .. } => i,
1776 FieldsShape::Arbitrary { in_memory_order, .. } => in_memory_order[i as u32].index(),
1777 })
1778 }
1779}
1780
1781#[derive(#[automatically_derived]impl ::core::marker::Copy for AddressSpace { }Copy, #[automatically_derived]#[doc(hidden)]unsafe impl ::core::clone::TrivialClone
for AddressSpace {
}
#[automatically_derived]impl ::core::clone::Clone for AddressSpace {
#[inline]
#[rustc_trivial_field_reads]
fn clone(&self) -> Self {
let _: ::core::clone::AssertParamIsClone<u32>;
*self
}
}Clone, #[automatically_derived]impl ::core::fmt::Debug for AddressSpace {
#[inline]
#[rustc_trivial_field_reads]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field1_finish(f, "AddressSpace",
&&self.0)
}
}Debug, #[automatically_derived]impl ::core::marker::StructuralPartialEq for
AddressSpace {
}
#[automatically_derived]impl ::core::cmp::PartialEq for AddressSpace {
#[inline]
fn eq(&self, other: &Self) -> bool { self.0 == other.0 }
}PartialEq, #[automatically_derived]impl ::core::cmp::Eq for AddressSpace {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<u32>;
}
}Eq, #[automatically_derived]impl ::core::cmp::PartialOrd for AddressSpace {
#[inline]
fn partial_cmp(&self, other: &Self)
-> ::core::option::Option<::core::cmp::Ordering> {
::core::option::Option::Some(::core::cmp::Ord::cmp(self, other))
}
}PartialOrd, #[automatically_derived]impl ::core::cmp::Ord for AddressSpace {
#[inline]
fn cmp(&self, other: &Self) -> ::core::cmp::Ordering {
::core::cmp::Ord::cmp(&self.0, &other.0)
}
}Ord, #[automatically_derived]impl ::core::hash::Hash for AddressSpace {
#[inline]
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
::core::hash::Hash::hash(&self.0, state)
}
}Hash)]
1785#[cfg_attr(feature = "nightly", derive(const _: () =
{
impl ::rustc_data_structures::stable_hash::StableHash for AddressSpace
{
#[inline]
fn stable_hash<__Hcx: ::rustc_data_structures::stable_hash::StableHashCtxt>(&self,
__hcx: &mut __Hcx,
__hasher:
&mut ::rustc_data_structures::stable_hash::StableHasher) {
match *self {
AddressSpace(ref __binding_0) => {
{ __binding_0.stable_hash(__hcx, __hasher); }
}
}
}
}
};StableHash))]
1786pub struct AddressSpace(pub u32);
1787
1788impl AddressSpace {
1789 pub const ZERO: Self = AddressSpace(0);
1791 pub const GPU_CONSTANT: Self = AddressSpace(4);
1795 pub const GPU_WORKGROUP: Self = AddressSpace(3);
1798}
1799
1800#[derive(#[automatically_derived]#[doc(hidden)]unsafe impl ::core::clone::TrivialClone
for NumScalableVectors {
}
#[automatically_derived]impl ::core::clone::Clone for NumScalableVectors {
#[inline]
#[rustc_trivial_field_reads]
fn clone(&self) -> Self {
let _: ::core::clone::AssertParamIsClone<u8>;
*self
}
}Clone, #[automatically_derived]impl ::core::marker::Copy for NumScalableVectors { }Copy, #[automatically_derived]impl ::core::marker::StructuralPartialEq for
NumScalableVectors {
}
#[automatically_derived]impl ::core::cmp::PartialEq for NumScalableVectors {
#[inline]
fn eq(&self, other: &Self) -> bool { self.0 == other.0 }
}PartialEq, #[automatically_derived]impl ::core::cmp::Eq for NumScalableVectors {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<u8>;
}
}Eq, #[automatically_derived]impl ::core::hash::Hash for NumScalableVectors {
#[inline]
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
::core::hash::Hash::hash(&self.0, state)
}
}Hash, #[automatically_derived]impl ::core::fmt::Debug for NumScalableVectors {
#[inline]
#[rustc_trivial_field_reads]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field1_finish(f,
"NumScalableVectors", &&self.0)
}
}Debug)]
1802#[cfg_attr(feature = "nightly", derive(const _: () =
{
impl ::rustc_data_structures::stable_hash::StableHash for
NumScalableVectors {
#[inline]
fn stable_hash<__Hcx: ::rustc_data_structures::stable_hash::StableHashCtxt>(&self,
__hcx: &mut __Hcx,
__hasher:
&mut ::rustc_data_structures::stable_hash::StableHasher) {
match *self {
NumScalableVectors(ref __binding_0) => {
{ __binding_0.stable_hash(__hcx, __hasher); }
}
}
}
}
};StableHash))]
1803pub struct NumScalableVectors(pub u8);
1804
1805impl NumScalableVectors {
1806 pub fn for_non_tuple() -> Self {
1808 NumScalableVectors(1)
1809 }
1810
1811 pub fn from_field_count(count: usize) -> Option<Self> {
1815 match count {
1816 2..=8 => Some(NumScalableVectors(count as u8)),
1817 _ => None,
1818 }
1819 }
1820}
1821
1822#[cfg(feature = "nightly")]
1823impl IntoDiagArg for NumScalableVectors {
1824 fn into_diag_arg(self, _: &mut Option<std::path::PathBuf>) -> DiagArgValue {
1825 DiagArgValue::Str(std::borrow::Cow::Borrowed(match self.0 {
1826 0 => {
::core::panicking::panic_fmt(format_args!("`NumScalableVectors(0)` is illformed"));
}panic!("`NumScalableVectors(0)` is illformed"),
1827 1 => "one",
1828 2 => "two",
1829 3 => "three",
1830 4 => "four",
1831 5 => "five",
1832 6 => "six",
1833 7 => "seven",
1834 8 => "eight",
1835 _ => {
::core::panicking::panic_fmt(format_args!("`NumScalableVectors(N)` for N>8 is illformed"));
}panic!("`NumScalableVectors(N)` for N>8 is illformed"),
1836 }))
1837 }
1838}
1839
1840#[derive(#[automatically_derived]#[doc(hidden)]unsafe impl ::core::clone::TrivialClone
for BackendRepr {
}
#[automatically_derived]impl ::core::clone::Clone for BackendRepr {
#[inline]
#[rustc_trivial_field_reads]
fn clone(&self) -> Self {
let _: ::core::clone::AssertParamIsClone<Scalar>;
let _: ::core::clone::AssertParamIsClone<Size>;
let _: ::core::clone::AssertParamIsClone<BackendLaneCount>;
let _: ::core::clone::AssertParamIsClone<NumScalableVectors>;
let _: ::core::clone::AssertParamIsClone<bool>;
*self
}
}Clone, #[automatically_derived]impl ::core::marker::Copy for BackendRepr { }Copy, #[automatically_derived]impl ::core::marker::StructuralPartialEq for
BackendRepr {
}
#[automatically_derived]impl ::core::cmp::PartialEq for BackendRepr {
#[inline]
fn eq(&self, other: &Self) -> bool {
::core::intrinsics::discriminant_value(self) ==
::core::intrinsics::discriminant_value(other) &&
match (self, other) {
(Self::Scalar(__self_0), Self::Scalar(__arg1_0)) =>
__self_0 == __arg1_0,
(Self::ScalarPair {
a: __self_0, b: __self_1, b_offset: __self_2 },
Self::ScalarPair {
a: __arg1_0, b: __arg1_1, b_offset: __arg1_2 }) =>
__self_0 == __arg1_0 && __self_1 == __arg1_1 &&
__self_2 == __arg1_2,
(Self::SimdScalableVector {
element: __self_0,
count: __self_1,
number_of_vectors: __self_2 }, Self::SimdScalableVector {
element: __arg1_0,
count: __arg1_1,
number_of_vectors: __arg1_2 }) =>
__self_0 == __arg1_0 && __self_1 == __arg1_1 &&
__self_2 == __arg1_2,
(Self::SimdVector { element: __self_0, count: __self_1 },
Self::SimdVector { element: __arg1_0, count: __arg1_1 }) =>
__self_0 == __arg1_0 && __self_1 == __arg1_1,
(Self::Memory { sized: __self_0 }, Self::Memory {
sized: __arg1_0 }) => __self_0 == __arg1_0,
_ => unsafe { ::core::intrinsics::unreachable() }
}
}
}PartialEq, #[automatically_derived]impl ::core::cmp::Eq for BackendRepr {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<Scalar>;
let _: ::core::cmp::AssertParamIsEq<Size>;
let _: ::core::cmp::AssertParamIsEq<BackendLaneCount>;
let _: ::core::cmp::AssertParamIsEq<NumScalableVectors>;
let _: ::core::cmp::AssertParamIsEq<bool>;
}
}Eq, #[automatically_derived]impl ::core::hash::Hash for BackendRepr {
#[inline]
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
::core::hash::Hash::hash(&::core::intrinsics::discriminant_value(self),
state);
match self {
Self::Scalar(__self_0) =>
::core::hash::Hash::hash(__self_0, state),
Self::ScalarPair { a: __self_0, b: __self_1, b_offset: __self_2 }
=> {
::core::hash::Hash::hash(__self_0, state);
::core::hash::Hash::hash(__self_1, state);
::core::hash::Hash::hash(__self_2, state)
}
Self::SimdScalableVector {
element: __self_0,
count: __self_1,
number_of_vectors: __self_2 } => {
::core::hash::Hash::hash(__self_0, state);
::core::hash::Hash::hash(__self_1, state);
::core::hash::Hash::hash(__self_2, state)
}
Self::SimdVector { element: __self_0, count: __self_1 } => {
::core::hash::Hash::hash(__self_0, state);
::core::hash::Hash::hash(__self_1, state)
}
Self::Memory { sized: __self_0 } =>
::core::hash::Hash::hash(__self_0, state),
}
}
}Hash, #[automatically_derived]impl ::core::fmt::Debug for BackendRepr {
#[inline]
#[rustc_trivial_field_reads]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
Self::Scalar(__self_0) =>
::core::fmt::Formatter::debug_struct_field1_finish(f,
"Scalar", &__self_0),
Self::ScalarPair { a: __self_0, b: __self_1, b_offset: __self_2 }
=>
::core::fmt::Formatter::debug_struct_field3_finish(f,
"ScalarPair a b b_offset", __self_0, __self_1, &__self_2),
Self::SimdScalableVector {
element: __self_0,
count: __self_1,
number_of_vectors: __self_2 } =>
::core::fmt::Formatter::debug_struct_field3_finish(f,
"SimdScalableVector element count number_of_vectors",
__self_0, __self_1, &__self_2),
Self::SimdVector { element: __self_0, count: __self_1 } =>
::core::fmt::Formatter::debug_struct_field2_finish(f,
"SimdVector element count", __self_0, &__self_1),
Self::Memory { sized: __self_0 } =>
::core::fmt::Formatter::debug_struct_field1_finish(f,
"Memory sized", &__self_0),
}
}
}Debug)]
1851#[cfg_attr(feature = "nightly", derive(const _: () =
{
impl ::rustc_data_structures::stable_hash::StableHash for BackendRepr
{
#[inline]
fn stable_hash<__Hcx: ::rustc_data_structures::stable_hash::StableHashCtxt>(&self,
__hcx: &mut __Hcx,
__hasher:
&mut ::rustc_data_structures::stable_hash::StableHasher) {
match *self {
BackendRepr::Scalar(ref __binding_0) =>
0u8.stable_hash(__hcx, __hasher),
BackendRepr::ScalarPair {
a: ref __binding_0,
b: ref __binding_1,
b_offset: ref __binding_2 } =>
1u8.stable_hash(__hcx, __hasher),
BackendRepr::SimdScalableVector {
element: ref __binding_0,
count: ref __binding_1,
number_of_vectors: ref __binding_2 } =>
2u8.stable_hash(__hcx, __hasher),
BackendRepr::SimdVector {
element: ref __binding_0, count: ref __binding_1 } =>
3u8.stable_hash(__hcx, __hasher),
BackendRepr::Memory { sized: ref __binding_0 } =>
4u8.stable_hash(__hcx, __hasher),
}
match *self {
BackendRepr::Scalar(ref __binding_0) => {
{ __binding_0.stable_hash(__hcx, __hasher); }
}
BackendRepr::ScalarPair {
a: ref __binding_0,
b: ref __binding_1,
b_offset: ref __binding_2 } => {
{ __binding_0.stable_hash(__hcx, __hasher); }
{ __binding_1.stable_hash(__hcx, __hasher); }
{ __binding_2.stable_hash(__hcx, __hasher); }
}
BackendRepr::SimdScalableVector {
element: ref __binding_0,
count: ref __binding_1,
number_of_vectors: ref __binding_2 } => {
{ __binding_0.stable_hash(__hcx, __hasher); }
{ __binding_1.stable_hash(__hcx, __hasher); }
{ __binding_2.stable_hash(__hcx, __hasher); }
}
BackendRepr::SimdVector {
element: ref __binding_0, count: ref __binding_1 } => {
{ __binding_0.stable_hash(__hcx, __hasher); }
{ __binding_1.stable_hash(__hcx, __hasher); }
}
BackendRepr::Memory { sized: ref __binding_0 } => {
{ __binding_0.stable_hash(__hcx, __hasher); }
}
}
}
}
};StableHash))]
1852pub enum BackendRepr {
1853 Scalar(Scalar),
1854 ScalarPair {
1863 a: Scalar,
1864 b: Scalar,
1865 b_offset: Size,
1866 },
1867 SimdScalableVector {
1868 element: Scalar,
1869 count: BackendLaneCount,
1870 number_of_vectors: NumScalableVectors,
1871 },
1872 SimdVector {
1873 element: Scalar,
1874 count: BackendLaneCount,
1875 },
1876 Memory {
1878 sized: bool,
1880 },
1881}
1882
1883impl BackendRepr {
1884 #[inline]
1886 pub fn is_unsized(&self) -> bool {
1887 match *self {
1888 BackendRepr::Scalar(_)
1889 | BackendRepr::ScalarPair { .. }
1890 | BackendRepr::SimdScalableVector { .. }
1896 | BackendRepr::SimdVector { .. } => false,
1897 BackendRepr::Memory { sized } => !sized,
1898 }
1899 }
1900
1901 #[inline]
1902 pub fn is_sized(&self) -> bool {
1903 !self.is_unsized()
1904 }
1905
1906 #[inline]
1909 pub fn is_signed(&self) -> bool {
1910 match self {
1911 BackendRepr::Scalar(scal) => scal.is_signed(),
1912 _ => {
::core::panicking::panic_fmt(format_args!("`is_signed` on non-scalar ABI {0:?}",
self));
}panic!("`is_signed` on non-scalar ABI {self:?}"),
1913 }
1914 }
1915
1916 #[inline]
1920 pub fn is_scalar(&self) -> bool {
1921 #[allow(non_exhaustive_omitted_patterns)] match *self {
BackendRepr::Scalar(_) => true,
_ => false,
}matches!(*self, BackendRepr::Scalar(_))
1922 }
1923
1924 #[inline]
1926 pub fn is_scalar_or_simd(&self) -> bool {
1927 #[allow(non_exhaustive_omitted_patterns)] match *self {
BackendRepr::Scalar(_) | BackendRepr::SimdVector { .. } |
BackendRepr::SimdScalableVector { .. } => true,
_ => false,
}matches!(
1928 *self,
1929 BackendRepr::Scalar(_)
1930 | BackendRepr::SimdVector { .. }
1931 | BackendRepr::SimdScalableVector { .. }
1932 )
1933 }
1934
1935 #[inline]
1937 pub fn is_bool(&self) -> bool {
1938 #[allow(non_exhaustive_omitted_patterns)] match *self {
BackendRepr::Scalar(s) if s.is_bool() => true,
_ => false,
}matches!(*self, BackendRepr::Scalar(s) if s.is_bool())
1939 }
1940
1941 pub fn scalar_platform_align<C: HasDataLayout>(&self, cx: &C) -> Option<Align> {
1949 match *self {
1950 BackendRepr::Scalar(s) => Some(s.default_align(cx)),
1951 BackendRepr::ScalarPair { a: s1, b: s2, b_offset: _ } => {
1952 Some(s1.default_align(cx).max(s2.default_align(cx)))
1953 }
1954 BackendRepr::SimdVector { .. }
1956 | BackendRepr::Memory { .. }
1957 | BackendRepr::SimdScalableVector { .. } => None,
1958 }
1959 }
1960
1961 pub fn scalar_size<C: HasDataLayout>(&self, cx: &C) -> Option<Size> {
1965 match *self {
1966 BackendRepr::Scalar(s) => Some(s.size(cx)),
1968 BackendRepr::ScalarPair { a: _, b: s2, b_offset: field2_offset } => {
1970 let size = (field2_offset + s2.size(cx)).align_to(
1971 self.scalar_platform_align(cx)
1972 .unwrap(),
1974 );
1975 Some(size)
1976 }
1977 BackendRepr::SimdVector { .. }
1979 | BackendRepr::Memory { .. }
1980 | BackendRepr::SimdScalableVector { .. } => None,
1981 }
1982 }
1983
1984 pub fn to_union(&self) -> Self {
1986 match *self {
1987 BackendRepr::Scalar(s) => BackendRepr::Scalar(s.to_union()),
1988 BackendRepr::ScalarPair { a: s1, b: s2, b_offset } => {
1989 BackendRepr::ScalarPair { a: s1.to_union(), b: s2.to_union(), b_offset }
1990 }
1991 BackendRepr::SimdVector { element, count } => {
1992 BackendRepr::SimdVector { element: element.to_union(), count }
1993 }
1994 BackendRepr::Memory { .. } => BackendRepr::Memory { sized: true },
1995 BackendRepr::SimdScalableVector { element, count, number_of_vectors } => {
1996 BackendRepr::SimdScalableVector {
1997 element: element.to_union(),
1998 count,
1999 number_of_vectors,
2000 }
2001 }
2002 }
2003 }
2004
2005 pub fn eq_up_to_validity(&self, other: &Self) -> bool {
2006 match (self, other) {
2007 (BackendRepr::Scalar(l), BackendRepr::Scalar(r)) => l.primitive() == r.primitive(),
2010 (
2011 BackendRepr::SimdVector { element: element_l, count: count_l },
2012 BackendRepr::SimdVector { element: element_r, count: count_r },
2013 ) => element_l.primitive() == element_r.primitive() && count_l == count_r,
2014 (
2015 BackendRepr::ScalarPair { a: l1, b: l2, b_offset: l_offset },
2016 BackendRepr::ScalarPair { a: r1, b: r2, b_offset: r_offset },
2017 ) => {
2018 l1.primitive() == r1.primitive()
2019 && l2.primitive() == r2.primitive()
2020 && l_offset == r_offset
2021 }
2022 _ => self == other,
2024 }
2025 }
2026}
2027
2028#[derive(#[automatically_derived]impl<FieldIdx: ::core::cmp::PartialEq + Idx,
VariantIdx: ::core::cmp::PartialEq + Idx>
::core::marker::StructuralPartialEq for Variants<FieldIdx, VariantIdx> {
}
#[automatically_derived]impl<FieldIdx: ::core::cmp::PartialEq + Idx,
VariantIdx: ::core::cmp::PartialEq + Idx> ::core::cmp::PartialEq for
Variants<FieldIdx, VariantIdx> {
#[inline]
fn eq(&self, other: &Self) -> bool {
::core::intrinsics::discriminant_value(self) ==
::core::intrinsics::discriminant_value(other) &&
match (self, other) {
(Self::Single { index: __self_0 }, Self::Single {
index: __arg1_0 }) => __self_0 == __arg1_0,
(Self::Multiple {
tag: __self_0,
tag_encoding: __self_1,
tag_field: __self_2,
variants: __self_3 }, Self::Multiple {
tag: __arg1_0,
tag_encoding: __arg1_1,
tag_field: __arg1_2,
variants: __arg1_3 }) =>
__self_0 == __arg1_0 && __self_1 == __arg1_1 &&
__self_2 == __arg1_2 && __self_3 == __arg1_3,
_ => true,
}
}
}PartialEq, #[automatically_derived]impl<FieldIdx: ::core::cmp::Eq + Idx,
VariantIdx: ::core::cmp::Eq + Idx> ::core::cmp::Eq for
Variants<FieldIdx, VariantIdx> {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<VariantIdx>;
let _: ::core::cmp::AssertParamIsEq<Scalar>;
let _: ::core::cmp::AssertParamIsEq<TagEncoding<VariantIdx>>;
let _: ::core::cmp::AssertParamIsEq<FieldIdx>;
let _:
::core::cmp::AssertParamIsEq<IndexVec<VariantIdx,
VariantLayout<FieldIdx>>>;
}
}Eq, #[automatically_derived]impl<FieldIdx: ::core::hash::Hash + Idx,
VariantIdx: ::core::hash::Hash + Idx> ::core::hash::Hash for
Variants<FieldIdx, VariantIdx> {
#[inline]
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
::core::hash::Hash::hash(&::core::intrinsics::discriminant_value(self),
state);
match self {
Self::Single { index: __self_0 } =>
::core::hash::Hash::hash(__self_0, state),
Self::Multiple {
tag: __self_0,
tag_encoding: __self_1,
tag_field: __self_2,
variants: __self_3 } => {
::core::hash::Hash::hash(__self_0, state);
::core::hash::Hash::hash(__self_1, state);
::core::hash::Hash::hash(__self_2, state);
::core::hash::Hash::hash(__self_3, state)
}
_ => {}
}
}
}Hash, #[automatically_derived]impl<FieldIdx: ::core::clone::Clone + Idx,
VariantIdx: ::core::clone::Clone + Idx> ::core::clone::Clone for
Variants<FieldIdx, VariantIdx> {
#[inline]
#[rustc_trivial_field_reads]
fn clone(&self) -> Self {
match self {
Self::Empty => Variants::Empty,
Self::Single { index: __self_0 } =>
Variants::Single {
index: ::core::clone::Clone::clone(__self_0),
},
Self::Multiple {
tag: __self_0,
tag_encoding: __self_1,
tag_field: __self_2,
variants: __self_3 } =>
Variants::Multiple {
tag: ::core::clone::Clone::clone(__self_0),
tag_encoding: ::core::clone::Clone::clone(__self_1),
tag_field: ::core::clone::Clone::clone(__self_2),
variants: ::core::clone::Clone::clone(__self_3),
},
}
}
}Clone, #[automatically_derived]impl<FieldIdx: ::core::fmt::Debug + Idx,
VariantIdx: ::core::fmt::Debug + Idx> ::core::fmt::Debug for
Variants<FieldIdx, VariantIdx> {
#[inline]
#[rustc_trivial_field_reads]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
Self::Empty => ::core::fmt::Formatter::write_str(f, "Empty"),
Self::Single { index: __self_0 } =>
::core::fmt::Formatter::debug_struct_field1_finish(f,
"Single index", &__self_0),
Self::Multiple {
tag: __self_0,
tag_encoding: __self_1,
tag_field: __self_2,
variants: __self_3 } =>
::core::fmt::Formatter::debug_struct_field4_finish(f,
"Multiple tag tag_encoding tag_field variants", __self_0,
__self_1, __self_2, &__self_3),
}
}
}Debug)]
2031#[cfg_attr(feature = "nightly", derive(const _: () =
{
impl<FieldIdx: Idx, VariantIdx: Idx>
::rustc_data_structures::stable_hash::StableHash for
Variants<FieldIdx, VariantIdx> where
VariantIdx: ::rustc_data_structures::stable_hash::StableHash,
FieldIdx: ::rustc_data_structures::stable_hash::StableHash {
#[inline]
fn stable_hash<__Hcx: ::rustc_data_structures::stable_hash::StableHashCtxt>(&self,
__hcx: &mut __Hcx,
__hasher:
&mut ::rustc_data_structures::stable_hash::StableHasher) {
match *self {
Variants::Empty => 0u8.stable_hash(__hcx, __hasher),
Variants::Single { index: ref __binding_0 } =>
1u8.stable_hash(__hcx, __hasher),
Variants::Multiple {
tag: ref __binding_0,
tag_encoding: ref __binding_1,
tag_field: ref __binding_2,
variants: ref __binding_3 } =>
2u8.stable_hash(__hcx, __hasher),
}
match *self {
Variants::Empty => {}
Variants::Single { index: ref __binding_0 } => {
{ __binding_0.stable_hash(__hcx, __hasher); }
}
Variants::Multiple {
tag: ref __binding_0,
tag_encoding: ref __binding_1,
tag_field: ref __binding_2,
variants: ref __binding_3 } => {
{ __binding_0.stable_hash(__hcx, __hasher); }
{ __binding_1.stable_hash(__hcx, __hasher); }
{ __binding_2.stable_hash(__hcx, __hasher); }
{ __binding_3.stable_hash(__hcx, __hasher); }
}
}
}
}
};StableHash))]
2032pub enum Variants<FieldIdx: Idx, VariantIdx: Idx> {
2033 Empty,
2039
2040 Single {
2047 index: VariantIdx,
2050 },
2051
2052 Multiple {
2064 tag: Scalar,
2065 tag_encoding: TagEncoding<VariantIdx>,
2066 tag_field: FieldIdx,
2067 variants: IndexVec<VariantIdx, VariantLayout<FieldIdx>>,
2068 },
2069}
2070
2071#[derive(#[automatically_derived]impl<VariantIdx: ::core::cmp::PartialEq + Idx>
::core::marker::StructuralPartialEq for TagEncoding<VariantIdx> {
}
#[automatically_derived]impl<VariantIdx: ::core::cmp::PartialEq + Idx>
::core::cmp::PartialEq for TagEncoding<VariantIdx> {
#[inline]
fn eq(&self, other: &Self) -> bool {
::core::intrinsics::discriminant_value(self) ==
::core::intrinsics::discriminant_value(other) &&
match (self, other) {
(Self::Niche {
untagged_variant: __self_0,
niche_variants: __self_1,
niche_start: __self_2 }, Self::Niche {
untagged_variant: __arg1_0,
niche_variants: __arg1_1,
niche_start: __arg1_2 }) =>
__self_2 == __arg1_2 && __self_0 == __arg1_0 &&
__self_1 == __arg1_1,
_ => true,
}
}
}PartialEq, #[automatically_derived]impl<VariantIdx: ::core::cmp::Eq + Idx>
::core::cmp::Eq for TagEncoding<VariantIdx> {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<VariantIdx>;
let _: ::core::cmp::AssertParamIsEq<RangeInclusive<VariantIdx>>;
let _: ::core::cmp::AssertParamIsEq<u128>;
}
}Eq, #[automatically_derived]impl<VariantIdx: ::core::hash::Hash + Idx>
::core::hash::Hash for TagEncoding<VariantIdx> {
#[inline]
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
::core::hash::Hash::hash(&::core::intrinsics::discriminant_value(self),
state);
match self {
Self::Niche {
untagged_variant: __self_0,
niche_variants: __self_1,
niche_start: __self_2 } => {
::core::hash::Hash::hash(__self_0, state);
::core::hash::Hash::hash(__self_1, state);
::core::hash::Hash::hash(__self_2, state)
}
_ => {}
}
}
}Hash, #[automatically_derived]impl<VariantIdx: ::core::marker::Copy + Idx>
::core::marker::Copy for TagEncoding<VariantIdx> {
}Copy, #[automatically_derived]impl<VariantIdx: ::core::clone::Clone + Idx>
::core::clone::Clone for TagEncoding<VariantIdx> {
#[inline]
#[rustc_trivial_field_reads]
fn clone(&self) -> Self {
match self {
Self::Direct => TagEncoding::Direct,
Self::Niche {
untagged_variant: __self_0,
niche_variants: __self_1,
niche_start: __self_2 } =>
TagEncoding::Niche {
untagged_variant: ::core::clone::Clone::clone(__self_0),
niche_variants: ::core::clone::Clone::clone(__self_1),
niche_start: ::core::clone::Clone::clone(__self_2),
},
}
}
}Clone, #[automatically_derived]impl<VariantIdx: ::core::fmt::Debug + Idx>
::core::fmt::Debug for TagEncoding<VariantIdx> {
#[inline]
#[rustc_trivial_field_reads]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
Self::Direct => ::core::fmt::Formatter::write_str(f, "Direct"),
Self::Niche {
untagged_variant: __self_0,
niche_variants: __self_1,
niche_start: __self_2 } =>
::core::fmt::Formatter::debug_struct_field3_finish(f,
"Niche untagged_variant niche_variants niche_start",
__self_0, __self_1, &__self_2),
}
}
}Debug)]
2073#[cfg_attr(feature = "nightly", derive(const _: () =
{
impl<VariantIdx: Idx> ::rustc_data_structures::stable_hash::StableHash
for TagEncoding<VariantIdx> where
VariantIdx: ::rustc_data_structures::stable_hash::StableHash {
#[inline]
fn stable_hash<__Hcx: ::rustc_data_structures::stable_hash::StableHashCtxt>(&self,
__hcx: &mut __Hcx,
__hasher:
&mut ::rustc_data_structures::stable_hash::StableHasher) {
match *self {
TagEncoding::Direct => 0u8.stable_hash(__hcx, __hasher),
TagEncoding::Niche {
untagged_variant: ref __binding_0,
niche_variants: ref __binding_1,
niche_start: ref __binding_2 } =>
1u8.stable_hash(__hcx, __hasher),
}
match *self {
TagEncoding::Direct => {}
TagEncoding::Niche {
untagged_variant: ref __binding_0,
niche_variants: ref __binding_1,
niche_start: ref __binding_2 } => {
{ __binding_0.stable_hash(__hcx, __hasher); }
{ __binding_1.stable_hash(__hcx, __hasher); }
{ __binding_2.stable_hash(__hcx, __hasher); }
}
}
}
}
};StableHash))]
2074pub enum TagEncoding<VariantIdx: Idx> {
2075 Direct,
2078
2079 Niche {
2103 untagged_variant: VariantIdx,
2104 niche_variants: RangeInclusive<VariantIdx>,
2107 niche_start: u128,
2110 },
2111}
2112
2113#[derive(#[automatically_derived]#[doc(hidden)]unsafe impl ::core::clone::TrivialClone
for Niche {
}
#[automatically_derived]impl ::core::clone::Clone for Niche {
#[inline]
#[rustc_trivial_field_reads]
fn clone(&self) -> Self {
let _: ::core::clone::AssertParamIsClone<Size>;
let _: ::core::clone::AssertParamIsClone<Primitive>;
let _: ::core::clone::AssertParamIsClone<WrappingRange>;
*self
}
}Clone, #[automatically_derived]impl ::core::marker::Copy for Niche { }Copy, #[automatically_derived]impl ::core::marker::StructuralPartialEq for Niche { }
#[automatically_derived]impl ::core::cmp::PartialEq for Niche {
#[inline]
fn eq(&self, other: &Self) -> bool {
self.offset == other.offset && self.value == other.value &&
self.valid_range == other.valid_range
}
}PartialEq, #[automatically_derived]impl ::core::cmp::Eq for Niche {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<Size>;
let _: ::core::cmp::AssertParamIsEq<Primitive>;
let _: ::core::cmp::AssertParamIsEq<WrappingRange>;
}
}Eq, #[automatically_derived]impl ::core::hash::Hash for Niche {
#[inline]
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
::core::hash::Hash::hash(&self.offset, state);
::core::hash::Hash::hash(&self.value, state);
::core::hash::Hash::hash(&self.valid_range, state)
}
}Hash, #[automatically_derived]impl ::core::fmt::Debug for Niche {
#[inline]
#[rustc_trivial_field_reads]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field3_finish(f,
"Niche offset value valid_range", &self.offset, &self.value,
&&self.valid_range)
}
}Debug)]
2114#[cfg_attr(feature = "nightly", derive(const _: () =
{
impl ::rustc_data_structures::stable_hash::StableHash for Niche {
#[inline]
fn stable_hash<__Hcx: ::rustc_data_structures::stable_hash::StableHashCtxt>(&self,
__hcx: &mut __Hcx,
__hasher:
&mut ::rustc_data_structures::stable_hash::StableHasher) {
match *self {
Niche {
offset: ref __binding_0,
value: ref __binding_1,
valid_range: ref __binding_2 } => {
{ __binding_0.stable_hash(__hcx, __hasher); }
{ __binding_1.stable_hash(__hcx, __hasher); }
{ __binding_2.stable_hash(__hcx, __hasher); }
}
}
}
}
};StableHash))]
2115pub struct Niche {
2116 pub offset: Size,
2117 pub value: Primitive,
2118 pub valid_range: WrappingRange,
2119}
2120
2121impl Niche {
2122 pub fn from_scalar<C: HasDataLayout>(cx: &C, offset: Size, scalar: Scalar) -> Option<Self> {
2123 let Scalar::Initialized { value, valid_range } = scalar else { return None };
2124 let niche = Niche { offset, value, valid_range };
2125 if niche.available(cx) > 0 { Some(niche) } else { None }
2126 }
2127
2128 pub fn available<C: HasDataLayout>(&self, cx: &C) -> u128 {
2129 let Self { value, valid_range: v, .. } = *self;
2130 let size = value.size(cx);
2131 if !(size.bits() <= 128) {
::core::panicking::panic("assertion failed: size.bits() <= 128")
};assert!(size.bits() <= 128);
2132 let max_value = size.unsigned_int_max();
2133
2134 let niche = v.end.wrapping_add(1)..v.start;
2136 niche.end.wrapping_sub(niche.start) & max_value
2137 }
2138
2139 pub fn reserve<C: HasDataLayout>(&self, cx: &C, count: u128) -> Option<(u128, Scalar)> {
2140 if !(count > 0) { ::core::panicking::panic("assertion failed: count > 0") };assert!(count > 0);
2141
2142 let Self { value, valid_range: v, .. } = *self;
2143 let size = value.size(cx);
2144 if !(size.bits() <= 128) {
::core::panicking::panic("assertion failed: size.bits() <= 128")
};assert!(size.bits() <= 128);
2145 let max_value = size.unsigned_int_max();
2146
2147 let available = v.start.wrapping_sub(v.end).wrapping_sub(1) & max_value;
2148 if count > available {
2149 return None;
2150 }
2151
2152 let move_start = |v: WrappingRange| {
2171 let start = v.start.wrapping_sub(count) & max_value;
2172 let valid_range = v.with_start(start);
2173 let mut value = value;
2174 if let Primitive::Bool = value
2175 && valid_range.end.wrapping_sub(valid_range.start) >= 2
2176 {
2177 value = Primitive::Int(Integer::I8, false);
2178 }
2179 Some((start, Scalar::Initialized { value, valid_range }))
2180 };
2181 let move_end = |v: WrappingRange| {
2182 let start = v.end.wrapping_add(1) & max_value;
2183 let end = v.end.wrapping_add(count) & max_value;
2184 let valid_range = v.with_end(end);
2185 let mut value = value;
2186 if let Primitive::Bool = value
2187 && valid_range.end.wrapping_sub(valid_range.start) >= 2
2188 {
2189 value = Primitive::Int(Integer::I8, false);
2190 }
2191 Some((start, Scalar::Initialized { value, valid_range }))
2192 };
2193 let distance_end_zero = max_value - v.end;
2194 if count == 1 && v != (WrappingRange { start: 0, end: 1 }) {
2197 let next_up = size.sign_extend(v.end.wrapping_add(1)).unsigned_abs();
2202 let next_down = size.sign_extend(v.start.wrapping_sub(1)).unsigned_abs();
2203 if next_down <= next_up { move_start(v) } else { move_end(v) }
2204 } else if v.start > v.end {
2205 move_end(v)
2207 } else if v.start <= distance_end_zero {
2208 if count <= v.start {
2209 move_start(v)
2210 } else {
2211 move_end(v)
2213 }
2214 } else {
2215 let end = v.end.wrapping_add(count) & max_value;
2216 let overshot_zero = (1..=v.end).contains(&end);
2217 if overshot_zero {
2218 move_start(v)
2220 } else {
2221 move_end(v)
2222 }
2223 }
2224 }
2225}
2226
2227#[derive(#[automatically_derived]impl ::core::marker::StructuralPartialEq for
NicheOptimizations {
}
#[automatically_derived]impl ::core::cmp::PartialEq for NicheOptimizations {
#[inline]
fn eq(&self, other: &Self) -> bool {
::core::intrinsics::discriminant_value(self) ==
::core::intrinsics::discriminant_value(other)
}
}PartialEq, #[automatically_derived]impl ::core::cmp::Eq for NicheOptimizations { }Eq, #[automatically_derived]#[doc(hidden)]unsafe impl ::core::clone::TrivialClone
for NicheOptimizations {
}
#[automatically_derived]impl ::core::clone::Clone for NicheOptimizations {
#[inline]
#[rustc_trivial_field_reads]
fn clone(&self) -> Self { *self }
}Clone, #[automatically_derived]impl ::core::marker::Copy for NicheOptimizations { }Copy)]
2234pub enum NicheOptimizations {
2235 Enabled,
2236 Disabled,
2237}
2238
2239#[derive(#[automatically_derived]impl<FieldIdx: ::core::cmp::PartialEq + Idx,
VariantIdx: ::core::cmp::PartialEq + Idx>
::core::marker::StructuralPartialEq for LayoutData<FieldIdx, VariantIdx> {
}
#[automatically_derived]impl<FieldIdx: ::core::cmp::PartialEq + Idx,
VariantIdx: ::core::cmp::PartialEq + Idx> ::core::cmp::PartialEq for
LayoutData<FieldIdx, VariantIdx> {
#[inline]
fn eq(&self, other: &Self) -> bool {
self.uninhabited == other.uninhabited && self.repr_c == other.repr_c
&& self.fields == other.fields &&
self.variants == other.variants &&
self.backend_repr == other.backend_repr &&
self.largest_niche == other.largest_niche &&
self.align == other.align && self.size == other.size &&
self.max_repr_align == other.max_repr_align &&
self.unadjusted_abi_align == other.unadjusted_abi_align &&
self.randomization_seed == other.randomization_seed
}
}PartialEq, #[automatically_derived]impl<FieldIdx: ::core::cmp::Eq + Idx,
VariantIdx: ::core::cmp::Eq + Idx> ::core::cmp::Eq for
LayoutData<FieldIdx, VariantIdx> {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<FieldsShape<FieldIdx>>;
let _: ::core::cmp::AssertParamIsEq<Variants<FieldIdx, VariantIdx>>;
let _: ::core::cmp::AssertParamIsEq<BackendRepr>;
let _: ::core::cmp::AssertParamIsEq<Option<Niche>>;
let _: ::core::cmp::AssertParamIsEq<bool>;
let _: ::core::cmp::AssertParamIsEq<Align>;
let _: ::core::cmp::AssertParamIsEq<Size>;
let _: ::core::cmp::AssertParamIsEq<Option<Align>>;
let _: ::core::cmp::AssertParamIsEq<Hash64>;
}
}Eq, #[automatically_derived]impl<FieldIdx: ::core::hash::Hash + Idx,
VariantIdx: ::core::hash::Hash + Idx> ::core::hash::Hash for
LayoutData<FieldIdx, VariantIdx> {
#[inline]
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
::core::hash::Hash::hash(&self.fields, state);
::core::hash::Hash::hash(&self.variants, state);
::core::hash::Hash::hash(&self.backend_repr, state);
::core::hash::Hash::hash(&self.largest_niche, state);
::core::hash::Hash::hash(&self.uninhabited, state);
::core::hash::Hash::hash(&self.align, state);
::core::hash::Hash::hash(&self.size, state);
::core::hash::Hash::hash(&self.max_repr_align, state);
::core::hash::Hash::hash(&self.unadjusted_abi_align, state);
::core::hash::Hash::hash(&self.repr_c, state);
::core::hash::Hash::hash(&self.randomization_seed, state)
}
}Hash, #[automatically_derived]impl<FieldIdx: ::core::clone::Clone + Idx,
VariantIdx: ::core::clone::Clone + Idx> ::core::clone::Clone for
LayoutData<FieldIdx, VariantIdx> {
#[inline]
#[rustc_trivial_field_reads]
fn clone(&self) -> Self {
LayoutData {
fields: ::core::clone::Clone::clone(&self.fields),
variants: ::core::clone::Clone::clone(&self.variants),
backend_repr: ::core::clone::Clone::clone(&self.backend_repr),
largest_niche: ::core::clone::Clone::clone(&self.largest_niche),
uninhabited: ::core::clone::Clone::clone(&self.uninhabited),
align: ::core::clone::Clone::clone(&self.align),
size: ::core::clone::Clone::clone(&self.size),
max_repr_align: ::core::clone::Clone::clone(&self.max_repr_align),
unadjusted_abi_align: ::core::clone::Clone::clone(&self.unadjusted_abi_align),
repr_c: ::core::clone::Clone::clone(&self.repr_c),
randomization_seed: ::core::clone::Clone::clone(&self.randomization_seed),
}
}
}Clone)]
2241#[cfg_attr(feature = "nightly", derive(const _: () =
{
impl<FieldIdx: Idx, VariantIdx: Idx>
::rustc_data_structures::stable_hash::StableHash for
LayoutData<FieldIdx, VariantIdx> where
FieldIdx: ::rustc_data_structures::stable_hash::StableHash,
VariantIdx: ::rustc_data_structures::stable_hash::StableHash {
#[inline]
fn stable_hash<__Hcx: ::rustc_data_structures::stable_hash::StableHashCtxt>(&self,
__hcx: &mut __Hcx,
__hasher:
&mut ::rustc_data_structures::stable_hash::StableHasher) {
match *self {
LayoutData {
fields: ref __binding_0,
variants: ref __binding_1,
backend_repr: ref __binding_2,
largest_niche: ref __binding_3,
uninhabited: ref __binding_4,
align: ref __binding_5,
size: ref __binding_6,
max_repr_align: ref __binding_7,
unadjusted_abi_align: ref __binding_8,
repr_c: ref __binding_9,
randomization_seed: ref __binding_10 } => {
{ __binding_0.stable_hash(__hcx, __hasher); }
{ __binding_1.stable_hash(__hcx, __hasher); }
{ __binding_2.stable_hash(__hcx, __hasher); }
{ __binding_3.stable_hash(__hcx, __hasher); }
{ __binding_4.stable_hash(__hcx, __hasher); }
{ __binding_5.stable_hash(__hcx, __hasher); }
{ __binding_6.stable_hash(__hcx, __hasher); }
{ __binding_7.stable_hash(__hcx, __hasher); }
{ __binding_8.stable_hash(__hcx, __hasher); }
{ __binding_9.stable_hash(__hcx, __hasher); }
{ __binding_10.stable_hash(__hcx, __hasher); }
}
}
}
}
};StableHash))]
2242pub struct LayoutData<FieldIdx: Idx, VariantIdx: Idx> {
2243 pub fields: FieldsShape<FieldIdx>,
2245
2246 pub variants: Variants<FieldIdx, VariantIdx>,
2254
2255 pub backend_repr: BackendRepr,
2263
2264 pub largest_niche: Option<Niche>,
2267 pub uninhabited: bool,
2272
2273 pub align: Align,
2274 pub size: Size,
2275
2276 pub max_repr_align: Option<Align>,
2280
2281 pub unadjusted_abi_align: Align,
2285
2286 pub repr_c: bool,
2292
2293 pub randomization_seed: Hash64,
2304}
2305
2306impl<FieldIdx: Idx, VariantIdx: Idx> LayoutData<FieldIdx, VariantIdx> {
2307 pub fn is_aggregate(&self) -> bool {
2309 match self.backend_repr {
2310 BackendRepr::Scalar(_)
2311 | BackendRepr::SimdVector { .. }
2312 | BackendRepr::SimdScalableVector { .. } => false,
2313 BackendRepr::ScalarPair { .. } | BackendRepr::Memory { .. } => true,
2314 }
2315 }
2316
2317 pub fn is_uninhabited(&self) -> bool {
2319 self.uninhabited
2320 }
2321
2322 pub fn is_variant_uninhabited(&self, variant: VariantIdx) -> bool {
2324 match self.variants {
2325 Variants::Empty => true,
2326 Variants::Single { index } => variant != index || self.uninhabited,
2327 Variants::Multiple { ref variants, .. } => {
2328 variants.get(variant).map(|v| v.uninhabited).unwrap_or(true)
2329 }
2330 }
2331 }
2332
2333 pub fn is_repr_c(&self) -> bool {
2336 self.repr_c
2337 }
2338}
2339
2340impl<FieldIdx: Idx, VariantIdx: Idx> fmt::Debug for LayoutData<FieldIdx, VariantIdx>
2341where
2342 FieldsShape<FieldIdx>: fmt::Debug,
2343 Variants<FieldIdx, VariantIdx>: fmt::Debug,
2344{
2345 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2346 let LayoutData {
2350 size,
2351 align,
2352 backend_repr,
2353 fields,
2354 largest_niche,
2355 uninhabited,
2356 variants,
2357 max_repr_align,
2358 unadjusted_abi_align,
2359 repr_c,
2360 randomization_seed,
2361 } = self;
2362 f.debug_struct("Layout")
2363 .field("size", size)
2364 .field("align", align)
2365 .field("backend_repr", backend_repr)
2366 .field("fields", fields)
2367 .field("largest_niche", largest_niche)
2368 .field("uninhabited", uninhabited)
2369 .field("variants", variants)
2370 .field("max_repr_align", max_repr_align)
2371 .field("unadjusted_abi_align", unadjusted_abi_align)
2372 .field("repr_c", repr_c)
2373 .field("randomization_seed", randomization_seed)
2374 .finish()
2375 }
2376}
2377
2378#[derive(#[automatically_derived]impl ::core::marker::Copy for PointerKind { }Copy, #[automatically_derived]#[doc(hidden)]unsafe impl ::core::clone::TrivialClone
for PointerKind {
}
#[automatically_derived]impl ::core::clone::Clone for PointerKind {
#[inline]
#[rustc_trivial_field_reads]
fn clone(&self) -> Self {
let _: ::core::clone::AssertParamIsClone<bool>;
*self
}
}Clone, #[automatically_derived]impl ::core::marker::StructuralPartialEq for
PointerKind {
}
#[automatically_derived]impl ::core::cmp::PartialEq for PointerKind {
#[inline]
fn eq(&self, other: &Self) -> bool {
::core::intrinsics::discriminant_value(self) ==
::core::intrinsics::discriminant_value(other) &&
match (self, other) {
(Self::SharedRef { frozen: __self_0 }, Self::SharedRef {
frozen: __arg1_0 }) => __self_0 == __arg1_0,
(Self::MutableRef { unpin: __self_0 }, Self::MutableRef {
unpin: __arg1_0 }) => __self_0 == __arg1_0,
(Self::Box { unpin: __self_0, global: __self_1 }, Self::Box {
unpin: __arg1_0, global: __arg1_1 }) =>
__self_0 == __arg1_0 && __self_1 == __arg1_1,
_ => unsafe { ::core::intrinsics::unreachable() }
}
}
}PartialEq, #[automatically_derived]impl ::core::cmp::Eq for PointerKind {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<bool>;
}
}Eq, #[automatically_derived]impl ::core::fmt::Debug for PointerKind {
#[inline]
#[rustc_trivial_field_reads]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
Self::SharedRef { frozen: __self_0 } =>
::core::fmt::Formatter::debug_struct_field1_finish(f,
"SharedRef frozen", &__self_0),
Self::MutableRef { unpin: __self_0 } =>
::core::fmt::Formatter::debug_struct_field1_finish(f,
"MutableRef unpin", &__self_0),
Self::Box { unpin: __self_0, global: __self_1 } =>
::core::fmt::Formatter::debug_struct_field2_finish(f,
"Box unpin global", __self_0, &__self_1),
}
}
}Debug)]
2379pub enum PointerKind {
2380 SharedRef { frozen: bool },
2382 MutableRef { unpin: bool },
2384 Box { unpin: bool, global: bool },
2387}
2388
2389#[derive(#[automatically_derived]impl ::core::marker::Copy for PointeeInfo { }Copy, #[automatically_derived]#[doc(hidden)]unsafe impl ::core::clone::TrivialClone
for PointeeInfo {
}
#[automatically_derived]impl ::core::clone::Clone for PointeeInfo {
#[inline]
#[rustc_trivial_field_reads]
fn clone(&self) -> Self {
let _: ::core::clone::AssertParamIsClone<Option<PointerKind>>;
let _: ::core::clone::AssertParamIsClone<Size>;
let _: ::core::clone::AssertParamIsClone<Align>;
*self
}
}Clone, #[automatically_derived]impl ::core::fmt::Debug for PointeeInfo {
#[inline]
#[rustc_trivial_field_reads]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field3_finish(f,
"PointeeInfo safe size align", &self.safe, &self.size,
&&self.align)
}
}Debug)]
2395pub struct PointeeInfo {
2396 pub safe: Option<PointerKind>,
2398 pub size: Size,
2408 pub align: Align,
2410}
2411
2412impl<FieldIdx: Idx, VariantIdx: Idx> LayoutData<FieldIdx, VariantIdx> {
2413 #[inline]
2415 pub fn is_unsized(&self) -> bool {
2416 self.backend_repr.is_unsized()
2417 }
2418
2419 #[inline]
2420 pub fn is_sized(&self) -> bool {
2421 self.backend_repr.is_sized()
2422 }
2423
2424 pub fn is_1zst(&self) -> bool {
2426 self.is_sized() && self.size.bytes() == 0 && self.align.bytes() == 1
2427 }
2428
2429 pub fn is_scalable_vector(&self) -> bool {
2431 #[allow(non_exhaustive_omitted_patterns)] match self.backend_repr {
BackendRepr::SimdScalableVector { .. } => true,
_ => false,
}matches!(self.backend_repr, BackendRepr::SimdScalableVector { .. })
2432 }
2433
2434 pub fn scalable_vector_element_count(&self) -> Option<BackendLaneCount> {
2436 match self.backend_repr {
2437 BackendRepr::SimdScalableVector { count, .. } => Some(count),
2438 _ => None,
2439 }
2440 }
2441
2442 pub fn is_zst(&self) -> bool {
2447 match self.backend_repr {
2448 BackendRepr::Scalar(_)
2449 | BackendRepr::ScalarPair { .. }
2450 | BackendRepr::SimdScalableVector { .. }
2451 | BackendRepr::SimdVector { .. } => false,
2452 BackendRepr::Memory { sized } => sized && self.size.bytes() == 0,
2453 }
2454 }
2455
2456 #[inline]
2465 pub fn is_ssa_standalone(&self) -> bool {
2466 match self.backend_repr {
2467 BackendRepr::Memory { .. } => self.is_zst(),
2468 BackendRepr::Scalar(..)
2469 | BackendRepr::ScalarPair { .. }
2470 | BackendRepr::SimdVector { .. }
2471 | BackendRepr::SimdScalableVector { .. } => true,
2472 }
2473 }
2474
2475 pub fn eq_abi(&self, other: &Self) -> bool {
2481 let LayoutData {
2482 size,
2483 align,
2484 backend_repr,
2485 fields: _,
2488 variants: _,
2489 largest_niche: _,
2491 uninhabited: _,
2492 max_repr_align: _,
2496 unadjusted_abi_align: _,
2497 repr_c: _,
2498 randomization_seed: _,
2500 } = self;
2501 *size == other.size
2505 && *align == other.align
2506 && backend_repr.eq_up_to_validity(&other.backend_repr)
2507 }
2508}
2509
2510#[derive(#[automatically_derived]impl ::core::marker::Copy for StructKind { }Copy, #[automatically_derived]#[doc(hidden)]unsafe impl ::core::clone::TrivialClone
for StructKind {
}
#[automatically_derived]impl ::core::clone::Clone for StructKind {
#[inline]
#[rustc_trivial_field_reads]
fn clone(&self) -> Self {
let _: ::core::clone::AssertParamIsClone<Size>;
let _: ::core::clone::AssertParamIsClone<Align>;
*self
}
}Clone, #[automatically_derived]impl ::core::fmt::Debug for StructKind {
#[inline]
#[rustc_trivial_field_reads]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
Self::AlwaysSized =>
::core::fmt::Formatter::write_str(f, "AlwaysSized"),
Self::MaybeUnsized =>
::core::fmt::Formatter::write_str(f, "MaybeUnsized"),
Self::Prefixed(__self_0, __self_1) =>
::core::fmt::Formatter::debug_struct_field2_finish(f,
"Prefixed", __self_0, &__self_1),
}
}
}Debug)]
2511pub enum StructKind {
2512 AlwaysSized,
2514 MaybeUnsized,
2516 Prefixed(Size, Align),
2518}
2519
2520#[derive(#[automatically_derived]impl ::core::clone::Clone for AbiFromStrErr {
#[inline]
#[rustc_trivial_field_reads]
fn clone(&self) -> Self {
match self {
Self::Unknown => AbiFromStrErr::Unknown,
Self::NoExplicitUnwind => AbiFromStrErr::NoExplicitUnwind,
}
}
}Clone, #[automatically_derived]impl ::core::fmt::Debug for AbiFromStrErr {
#[inline]
#[rustc_trivial_field_reads]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::write_str(f,
match self {
AbiFromStrErr::Unknown => "Unknown",
AbiFromStrErr::NoExplicitUnwind => "NoExplicitUnwind",
})
}
}Debug)]
2521pub enum AbiFromStrErr {
2522 Unknown,
2524 NoExplicitUnwind,
2526}
2527
2528#[derive(#[automatically_derived]impl<FieldIdx: ::core::cmp::PartialEq + Idx>
::core::marker::StructuralPartialEq for VariantLayout<FieldIdx> {
}
#[automatically_derived]impl<FieldIdx: ::core::cmp::PartialEq + Idx>
::core::cmp::PartialEq for VariantLayout<FieldIdx> {
#[inline]
fn eq(&self, other: &Self) -> bool {
self.uninhabited == other.uninhabited && self.size == other.size &&
self.backend_repr == other.backend_repr &&
self.field_offsets == other.field_offsets &&
self.fields_in_memory_order == other.fields_in_memory_order &&
self.largest_niche == other.largest_niche
}
}PartialEq, #[automatically_derived]impl<FieldIdx: ::core::cmp::Eq + Idx> ::core::cmp::Eq
for VariantLayout<FieldIdx> {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<Size>;
let _: ::core::cmp::AssertParamIsEq<BackendRepr>;
let _: ::core::cmp::AssertParamIsEq<IndexVec<FieldIdx, Size>>;
let _: ::core::cmp::AssertParamIsEq<IndexVec<u32, FieldIdx>>;
let _: ::core::cmp::AssertParamIsEq<Option<Niche>>;
let _: ::core::cmp::AssertParamIsEq<bool>;
}
}Eq, #[automatically_derived]impl<FieldIdx: ::core::hash::Hash + Idx>
::core::hash::Hash for VariantLayout<FieldIdx> {
#[inline]
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
::core::hash::Hash::hash(&self.size, state);
::core::hash::Hash::hash(&self.backend_repr, state);
::core::hash::Hash::hash(&self.field_offsets, state);
::core::hash::Hash::hash(&self.fields_in_memory_order, state);
::core::hash::Hash::hash(&self.largest_niche, state);
::core::hash::Hash::hash(&self.uninhabited, state)
}
}Hash, #[automatically_derived]impl<FieldIdx: ::core::clone::Clone + Idx>
::core::clone::Clone for VariantLayout<FieldIdx> {
#[inline]
#[rustc_trivial_field_reads]
fn clone(&self) -> Self {
VariantLayout {
size: ::core::clone::Clone::clone(&self.size),
backend_repr: ::core::clone::Clone::clone(&self.backend_repr),
field_offsets: ::core::clone::Clone::clone(&self.field_offsets),
fields_in_memory_order: ::core::clone::Clone::clone(&self.fields_in_memory_order),
largest_niche: ::core::clone::Clone::clone(&self.largest_niche),
uninhabited: ::core::clone::Clone::clone(&self.uninhabited),
}
}
}Clone, #[automatically_derived]impl<FieldIdx: ::core::fmt::Debug + Idx>
::core::fmt::Debug for VariantLayout<FieldIdx> {
#[inline]
#[rustc_trivial_field_reads]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_fields_finish(f,
"VariantLayout size backend_repr field_offsets fields_in_memory_order largest_niche uninhabited",
&[&self.size, &self.backend_repr, &self.field_offsets,
&self.fields_in_memory_order, &self.largest_niche,
&&self.uninhabited])
}
}Debug)]
2537#[cfg_attr(feature = "nightly", derive(const _: () =
{
impl<FieldIdx: Idx> ::rustc_data_structures::stable_hash::StableHash
for VariantLayout<FieldIdx> where
FieldIdx: ::rustc_data_structures::stable_hash::StableHash {
#[inline]
fn stable_hash<__Hcx: ::rustc_data_structures::stable_hash::StableHashCtxt>(&self,
__hcx: &mut __Hcx,
__hasher:
&mut ::rustc_data_structures::stable_hash::StableHasher) {
match *self {
VariantLayout {
size: ref __binding_0,
backend_repr: ref __binding_1,
field_offsets: ref __binding_2,
fields_in_memory_order: ref __binding_3,
largest_niche: ref __binding_4,
uninhabited: ref __binding_5 } => {
{ __binding_0.stable_hash(__hcx, __hasher); }
{ __binding_1.stable_hash(__hcx, __hasher); }
{ __binding_2.stable_hash(__hcx, __hasher); }
{ __binding_3.stable_hash(__hcx, __hasher); }
{ __binding_4.stable_hash(__hcx, __hasher); }
{ __binding_5.stable_hash(__hcx, __hasher); }
}
}
}
}
};StableHash))]
2538pub struct VariantLayout<FieldIdx: Idx> {
2539 pub size: Size,
2542 pub backend_repr: BackendRepr,
2543
2544 pub field_offsets: IndexVec<FieldIdx, Size>,
2545 fields_in_memory_order: IndexVec<u32, FieldIdx>,
2546 largest_niche: Option<Niche>,
2547 uninhabited: bool,
2548}
2549
2550impl<FieldIdx: Idx> VariantLayout<FieldIdx> {
2551 pub fn from_layout(layout: LayoutData<FieldIdx, impl Idx>) -> Self {
2552 let FieldsShape::Arbitrary { offsets, in_memory_order } = layout.fields else {
2553 {
::core::panicking::panic_fmt(format_args!("Layout of fields should be Arbitrary for variants"));
};panic!("Layout of fields should be Arbitrary for variants");
2554 };
2555
2556 Self {
2557 size: layout.size,
2558 backend_repr: layout.backend_repr,
2559 field_offsets: offsets,
2560 fields_in_memory_order: in_memory_order,
2561 largest_niche: layout.largest_niche,
2562 uninhabited: layout.uninhabited,
2563 }
2564 }
2565
2566 pub fn is_uninhabited(&self) -> bool {
2567 self.uninhabited
2568 }
2569
2570 pub fn has_fields(&self) -> bool {
2571 self.field_offsets.len() > 0
2572 }
2573}