Rollup merge of #147134 - workingjubilee:remove-explicit-abialign-deref, r=Zalathar
remove explicit deref of AbiAlign for most methods Much of the compiler calls functions on Align projected from AbiAlign. AbiAlign impls Deref to its inner Align, so we can simplify these away. Also, it will minimize disruption when AbiAlign is removed. For now, preserve usages that might resolve to PartialOrd or PartialEq, as those have odd inference.
This commit is contained in:
@@ -1167,7 +1167,7 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
|
||||
// To allow unsizing `&Foo<Type>` -> `&Foo<dyn Trait>`, the layout of the struct must
|
||||
// not depend on the layout of the tail.
|
||||
let max_field_align =
|
||||
fields_excluding_tail.iter().map(|f| f.align.abi.bytes()).max().unwrap_or(1);
|
||||
fields_excluding_tail.iter().map(|f| f.align.bytes()).max().unwrap_or(1);
|
||||
let largest_niche_size = fields_excluding_tail
|
||||
.iter()
|
||||
.filter_map(|f| f.largest_niche)
|
||||
@@ -1187,7 +1187,7 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
|
||||
} else {
|
||||
// Returns `log2(effective-align)`. The calculation assumes that size is an
|
||||
// integer multiple of align, except for ZSTs.
|
||||
let align = layout.align.abi.bytes();
|
||||
let align = layout.align.bytes();
|
||||
let size = layout.size.bytes();
|
||||
let niche_size = layout.largest_niche.map(|n| n.available(dl)).unwrap_or(0);
|
||||
// Group [u8; 4] with align-4 or [u8; 6] with align-2 fields.
|
||||
@@ -1485,7 +1485,7 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
|
||||
for i in layout.fields.index_by_increasing_offset() {
|
||||
let offset = layout.fields.offset(i);
|
||||
let f = &fields[FieldIdx::new(i)];
|
||||
write!(s, "[o{}a{}s{}", offset.bytes(), f.align.abi.bytes(), f.size.bytes()).unwrap();
|
||||
write!(s, "[o{}a{}s{}", offset.bytes(), f.align.bytes(), f.size.bytes()).unwrap();
|
||||
if let Some(n) = f.largest_niche {
|
||||
write!(
|
||||
s,
|
||||
|
||||
@@ -2156,7 +2156,7 @@ impl<FieldIdx: Idx, VariantIdx: Idx> LayoutData<FieldIdx, VariantIdx> {
|
||||
|
||||
/// Returns `true` if the type is sized and a 1-ZST (meaning it has size 0 and alignment 1).
|
||||
pub fn is_1zst(&self) -> bool {
|
||||
self.is_sized() && self.size.bytes() == 0 && self.align.abi.bytes() == 1
|
||||
self.is_sized() && self.size.bytes() == 0 && self.align.bytes() == 1
|
||||
}
|
||||
|
||||
/// Returns `true` if the type is a ZST and not unsized.
|
||||
|
||||
@@ -89,7 +89,7 @@ pub(super) fn add_local_place_comments<'tcx>(
|
||||
format!("{:?}", local),
|
||||
format!("{:?}", ty),
|
||||
size.bytes(),
|
||||
align.abi.bytes(),
|
||||
align.bytes(),
|
||||
if extra.is_empty() { "" } else { " " },
|
||||
extra,
|
||||
));
|
||||
|
||||
@@ -233,7 +233,7 @@ pub(super) fn from_casted_value<'tcx>(
|
||||
// It may also be smaller for example when the type is a wrapper around an integer with a
|
||||
// larger alignment than the integer.
|
||||
std::cmp::max(abi_param_size, layout_size),
|
||||
u32::try_from(layout.align.abi.bytes()).unwrap(),
|
||||
u32::try_from(layout.align.bytes()).unwrap(),
|
||||
);
|
||||
let mut block_params_iter = block_params.iter().copied();
|
||||
for (offset, _) in abi_params {
|
||||
|
||||
@@ -846,7 +846,7 @@ fn codegen_stmt<'tcx>(fx: &mut FunctionCx<'_, '_, 'tcx>, cur_block: Block, stmt:
|
||||
let layout = fx.layout_of(fx.monomorphize(ty));
|
||||
let val = match null_op {
|
||||
NullOp::SizeOf => layout.size.bytes(),
|
||||
NullOp::AlignOf => layout.align.abi.bytes(),
|
||||
NullOp::AlignOf => layout.align.bytes(),
|
||||
NullOp::OffsetOf(fields) => fx
|
||||
.tcx
|
||||
.offset_of_subfield(
|
||||
|
||||
@@ -304,7 +304,7 @@ impl DebugContext {
|
||||
entry.set(gimli::DW_AT_decl_file, AttributeValue::FileIndex(Some(file_id)));
|
||||
entry.set(gimli::DW_AT_decl_line, AttributeValue::Udata(line));
|
||||
|
||||
entry.set(gimli::DW_AT_alignment, AttributeValue::Udata(static_layout.align.abi.bytes()));
|
||||
entry.set(gimli::DW_AT_alignment, AttributeValue::Udata(static_layout.align.bytes()));
|
||||
|
||||
let mut expr = Expression::new();
|
||||
expr.op_addr(address_for_data(data_id));
|
||||
|
||||
@@ -166,7 +166,7 @@ impl DebugContext {
|
||||
let tuple_entry = self.dwarf.unit.get_mut(tuple_type_id);
|
||||
tuple_entry.set(gimli::DW_AT_name, AttributeValue::StringRef(self.dwarf.strings.add(name)));
|
||||
tuple_entry.set(gimli::DW_AT_byte_size, AttributeValue::Udata(layout.size.bytes()));
|
||||
tuple_entry.set(gimli::DW_AT_alignment, AttributeValue::Udata(layout.align.abi.bytes()));
|
||||
tuple_entry.set(gimli::DW_AT_alignment, AttributeValue::Udata(layout.align.bytes()));
|
||||
|
||||
for (i, (ty, dw_ty)) in components.into_iter().enumerate() {
|
||||
let member_id = self.dwarf.unit.add(tuple_type_id, gimli::DW_TAG_member);
|
||||
@@ -178,9 +178,7 @@ impl DebugContext {
|
||||
member_entry.set(gimli::DW_AT_type, AttributeValue::UnitRef(dw_ty));
|
||||
member_entry.set(
|
||||
gimli::DW_AT_alignment,
|
||||
AttributeValue::Udata(
|
||||
FullyMonomorphizedLayoutCx(tcx).layout_of(ty).align.abi.bytes(),
|
||||
),
|
||||
AttributeValue::Udata(FullyMonomorphizedLayoutCx(tcx).layout_of(ty).align.bytes()),
|
||||
);
|
||||
member_entry.set(
|
||||
gimli::DW_AT_data_member_location,
|
||||
|
||||
@@ -167,7 +167,7 @@ pub(crate) fn size_and_align_of<'tcx>(
|
||||
if layout.is_sized() {
|
||||
return (
|
||||
fx.bcx.ins().iconst(fx.pointer_type, layout.size.bytes() as i64),
|
||||
fx.bcx.ins().iconst(fx.pointer_type, layout.align.abi.bytes() as i64),
|
||||
fx.bcx.ins().iconst(fx.pointer_type, layout.align.bytes() as i64),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -186,7 +186,7 @@ pub(crate) fn size_and_align_of<'tcx>(
|
||||
// times the unit size.
|
||||
(
|
||||
fx.bcx.ins().imul_imm(info.unwrap(), unit.size.bytes() as i64),
|
||||
fx.bcx.ins().iconst(fx.pointer_type, unit.align.abi.bytes() as i64),
|
||||
fx.bcx.ins().iconst(fx.pointer_type, unit.align.bytes() as i64),
|
||||
)
|
||||
}
|
||||
ty::Foreign(_) => {
|
||||
@@ -224,7 +224,7 @@ pub(crate) fn size_and_align_of<'tcx>(
|
||||
let unsized_offset_unadjusted = layout.fields.offset(i).bytes();
|
||||
let unsized_offset_unadjusted =
|
||||
fx.bcx.ins().iconst(fx.pointer_type, unsized_offset_unadjusted as i64);
|
||||
let sized_align = layout.align.abi.bytes();
|
||||
let sized_align = layout.align.bytes();
|
||||
let sized_align = fx.bcx.ins().iconst(fx.pointer_type, sized_align as i64);
|
||||
|
||||
// Recurse to get the size of the dynamically sized field (must be
|
||||
|
||||
@@ -383,7 +383,7 @@ impl<'tcx> CPlace<'tcx> {
|
||||
|
||||
let stack_slot = fx.create_stack_slot(
|
||||
u32::try_from(layout.size.bytes()).unwrap(),
|
||||
u32::try_from(layout.align.abi.bytes()).unwrap(),
|
||||
u32::try_from(layout.align.bytes()).unwrap(),
|
||||
);
|
||||
CPlace { inner: CPlaceInner::Addr(stack_slot, None), layout }
|
||||
}
|
||||
@@ -641,8 +641,8 @@ impl<'tcx> CPlace<'tcx> {
|
||||
let size = dst_layout.size.bytes();
|
||||
// `emit_small_memory_copy` uses `u8` for alignments, just use the maximum
|
||||
// alignment that fits in a `u8` if the actual alignment is larger.
|
||||
let src_align = src_layout.align.abi.bytes().try_into().unwrap_or(128);
|
||||
let dst_align = dst_layout.align.abi.bytes().try_into().unwrap_or(128);
|
||||
let src_align = src_layout.align.bytes().try_into().unwrap_or(128);
|
||||
let dst_align = dst_layout.align.bytes().try_into().unwrap_or(128);
|
||||
fx.bcx.emit_small_memory_copy(
|
||||
fx.target_config,
|
||||
to_addr,
|
||||
|
||||
@@ -147,7 +147,7 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
|
||||
let layout = tcx
|
||||
.layout_of(ty::TypingEnv::fully_monomorphized().as_query_input(rust_type))
|
||||
.unwrap();
|
||||
let align = layout.align.abi.bytes();
|
||||
let align = layout.align.bytes();
|
||||
// For types with size 1, the alignment can be 1 and only 1
|
||||
// So, we can skip the call to ``get_aligned`.
|
||||
// In the future, we can add a GCC API to query the type align,
|
||||
@@ -186,9 +186,9 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
|
||||
(i128_type, u128_type)
|
||||
} else {
|
||||
/*let layout = tcx.layout_of(ParamEnv::reveal_all().and(tcx.types.i128)).unwrap();
|
||||
let i128_align = layout.align.abi.bytes();
|
||||
let i128_align = layout.align.bytes();
|
||||
let layout = tcx.layout_of(ParamEnv::reveal_all().and(tcx.types.u128)).unwrap();
|
||||
let u128_align = layout.align.abi.bytes();*/
|
||||
let u128_align = layout.align.bytes();*/
|
||||
|
||||
// TODO(antoyo): re-enable the alignment when libgccjit fixed the issue in
|
||||
// gcc_jit_context_new_array_constructor (it should not use reinterpret_cast).
|
||||
|
||||
@@ -1043,7 +1043,7 @@ fn create_member_type<'ll, 'tcx>(
|
||||
file_metadata,
|
||||
line_number,
|
||||
layout.size.bits(),
|
||||
layout.align.abi.bits() as u32,
|
||||
layout.align.bits() as u32,
|
||||
offset.bits(),
|
||||
flags,
|
||||
type_di_node,
|
||||
|
||||
@@ -289,7 +289,7 @@ fn build_enum_variant_part_di_node<'ll, 'tcx>(
|
||||
file_metadata,
|
||||
line_number,
|
||||
enum_type_and_layout.size.bits(),
|
||||
enum_type_and_layout.align.abi.bits() as u32,
|
||||
enum_type_and_layout.align.bits() as u32,
|
||||
DIFlags::FlagZero,
|
||||
tag_member_di_node,
|
||||
create_DIArray(DIB(cx), &[]),
|
||||
@@ -449,7 +449,7 @@ fn build_enum_variant_member_di_node<'ll, 'tcx>(
|
||||
file_di_node,
|
||||
line_number,
|
||||
enum_type_and_layout.size.bits(),
|
||||
enum_type_and_layout.align.abi.bits() as u32,
|
||||
enum_type_and_layout.align.bits() as u32,
|
||||
Size::ZERO.bits(),
|
||||
discr,
|
||||
DIFlags::FlagZero,
|
||||
|
||||
@@ -297,7 +297,7 @@ impl<'ll, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
|
||||
let align = if name == sym::unaligned_volatile_load {
|
||||
1
|
||||
} else {
|
||||
result.layout.align.abi.bytes() as u32
|
||||
result.layout.align.bytes() as u32
|
||||
};
|
||||
unsafe {
|
||||
llvm::LLVMSetAlignment(load, align);
|
||||
|
||||
@@ -193,7 +193,7 @@ fn emit_aapcs_va_arg<'ll, 'tcx>(
|
||||
// the offset again.
|
||||
|
||||
bx.switch_to_block(maybe_reg);
|
||||
if gr_type && layout.align.abi.bytes() > 8 {
|
||||
if gr_type && layout.align.bytes() > 8 {
|
||||
reg_off_v = bx.add(reg_off_v, bx.const_i32(15));
|
||||
reg_off_v = bx.and(reg_off_v, bx.const_i32(-16));
|
||||
}
|
||||
@@ -761,7 +761,7 @@ fn x86_64_sysv64_va_arg_from_memory<'ll, 'tcx>(
|
||||
// byte boundary if alignment needed by type exceeds 8 byte boundary.
|
||||
// It isn't stated explicitly in the standard, but in practice we use
|
||||
// alignment greater than 16 where necessary.
|
||||
if layout.layout.align.abi.bytes() > 8 {
|
||||
if layout.layout.align.bytes() > 8 {
|
||||
unreachable!("all instances of VaArgSafe have an alignment <= 8");
|
||||
}
|
||||
|
||||
|
||||
@@ -617,7 +617,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
||||
}
|
||||
mir::NullOp::AlignOf => {
|
||||
assert!(bx.cx().type_is_sized(ty));
|
||||
let val = layout.align.abi.bytes();
|
||||
let val = layout.align.bytes();
|
||||
bx.cx().const_usize(val)
|
||||
}
|
||||
mir::NullOp::OffsetOf(fields) => {
|
||||
|
||||
@@ -21,7 +21,7 @@ pub fn size_and_align_of_dst<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
|
||||
trace!("size_and_align_of_dst(ty={}, info={:?}): layout: {:?}", t, info, layout);
|
||||
if layout.is_sized() {
|
||||
let size = bx.const_usize(layout.size.bytes());
|
||||
let align = bx.const_usize(layout.align.abi.bytes());
|
||||
let align = bx.const_usize(layout.align.bytes());
|
||||
return (size, align);
|
||||
}
|
||||
match t.kind() {
|
||||
@@ -49,7 +49,7 @@ pub fn size_and_align_of_dst<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
|
||||
// All slice sizes must fit into `isize`, so this multiplication cannot
|
||||
// wrap -- neither signed nor unsigned.
|
||||
bx.unchecked_sumul(info.unwrap(), bx.const_usize(unit.size.bytes())),
|
||||
bx.const_usize(unit.align.abi.bytes()),
|
||||
bx.const_usize(unit.align.bytes()),
|
||||
)
|
||||
}
|
||||
ty::Foreign(_) => {
|
||||
@@ -82,7 +82,7 @@ pub fn size_and_align_of_dst<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
|
||||
|
||||
// This function does not return so we can now return whatever we want.
|
||||
let size = bx.const_usize(layout.size.bytes());
|
||||
let align = bx.const_usize(layout.align.abi.bytes());
|
||||
let align = bx.const_usize(layout.align.bytes());
|
||||
(size, align)
|
||||
}
|
||||
ty::Adt(..) | ty::Tuple(..) => {
|
||||
@@ -94,7 +94,7 @@ pub fn size_and_align_of_dst<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
|
||||
|
||||
let i = layout.fields.count() - 1;
|
||||
let unsized_offset_unadjusted = layout.fields.offset(i).bytes();
|
||||
let sized_align = layout.align.abi.bytes();
|
||||
let sized_align = layout.align.bytes();
|
||||
debug!(
|
||||
"DST {} offset of dyn field: {}, statically sized align: {}",
|
||||
t, unsized_offset_unadjusted, sized_align
|
||||
|
||||
@@ -528,7 +528,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
|
||||
if !layout.is_sized() {
|
||||
span_bug!(self.cur_span(), "unsized type for `NullaryOp::AlignOf`");
|
||||
}
|
||||
let val = layout.align.abi.bytes();
|
||||
let val = layout.align.bytes();
|
||||
ImmTy::from_uint(val, usize_layout())
|
||||
}
|
||||
OffsetOf(fields) => {
|
||||
|
||||
@@ -37,7 +37,7 @@ where
|
||||
debug!(
|
||||
"is_disaligned({:?}) - align = {}, packed = {}; not disaligned",
|
||||
place,
|
||||
layout.align.abi.bytes(),
|
||||
layout.align.bytes(),
|
||||
pack.bytes()
|
||||
);
|
||||
false
|
||||
|
||||
@@ -129,7 +129,7 @@ fn check_validity_requirement_lax<'tcx>(
|
||||
if let Some(pointee) = this.ty.builtin_deref(false) {
|
||||
let pointee = cx.layout_of(pointee)?;
|
||||
// We need to ensure that the LLVM attributes `aligned` and `dereferenceable(size)` are satisfied.
|
||||
if pointee.align.abi.bytes() > 1 {
|
||||
if pointee.align.bytes() > 1 {
|
||||
// 0x01-filling is not aligned.
|
||||
return Ok(false);
|
||||
}
|
||||
|
||||
@@ -138,7 +138,7 @@ fn is_valid_cmse_inputs<'tcx>(
|
||||
for (index, ty) in fn_sig.inputs().iter().enumerate() {
|
||||
let layout = tcx.layout_of(ty::TypingEnv::fully_monomorphized().as_query_input(*ty))?;
|
||||
|
||||
let align = layout.layout.align().abi.bytes();
|
||||
let align = layout.layout.align().bytes();
|
||||
let size = layout.layout.size().bytes();
|
||||
|
||||
accum += size;
|
||||
|
||||
@@ -104,7 +104,7 @@ pub(super) fn vtable_allocation_provider<'tcx>(
|
||||
.expect("failed to build vtable representation");
|
||||
assert!(layout.is_sized(), "can't create a vtable for an unsized type");
|
||||
let size = layout.size.bytes();
|
||||
let align = layout.align.abi.bytes();
|
||||
let align = layout.align.bytes();
|
||||
|
||||
let ptr_size = tcx.data_layout.pointer_size();
|
||||
let ptr_align = tcx.data_layout.pointer_align().abi;
|
||||
|
||||
@@ -476,7 +476,7 @@ impl<'a, 'tcx> ConstAnalysis<'a, 'tcx> {
|
||||
};
|
||||
let val = match null_op {
|
||||
NullOp::SizeOf if layout.is_sized() => layout.size.bytes(),
|
||||
NullOp::AlignOf if layout.is_sized() => layout.align.abi.bytes(),
|
||||
NullOp::AlignOf if layout.is_sized() => layout.align.bytes(),
|
||||
NullOp::OffsetOf(fields) => self
|
||||
.ecx
|
||||
.tcx
|
||||
|
||||
@@ -618,7 +618,7 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
|
||||
}
|
||||
let val = match null_op {
|
||||
NullOp::SizeOf => arg_layout.size.bytes(),
|
||||
NullOp::AlignOf => arg_layout.align.abi.bytes(),
|
||||
NullOp::AlignOf => arg_layout.align.bytes(),
|
||||
NullOp::OffsetOf(fields) => self
|
||||
.ecx
|
||||
.tcx
|
||||
|
||||
@@ -609,7 +609,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
|
||||
let op_layout = self.ecx.layout_of(ty).ok()?;
|
||||
let val = match null_op {
|
||||
NullOp::SizeOf => op_layout.size.bytes(),
|
||||
NullOp::AlignOf => op_layout.align.abi.bytes(),
|
||||
NullOp::AlignOf => op_layout.align.bytes(),
|
||||
NullOp::OffsetOf(fields) => self
|
||||
.tcx
|
||||
.offset_of_subfield(self.typing_env, op_layout, fields.iter())
|
||||
|
||||
@@ -77,7 +77,7 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
let align = arg.layout.align.abi.bytes();
|
||||
let align = arg.layout.align.bytes();
|
||||
let total = arg.layout.size;
|
||||
arg.cast_to(Uniform::consecutive(if align <= 4 { Reg::i32() } else { Reg::i64() }, total));
|
||||
}
|
||||
|
||||
@@ -322,7 +322,7 @@ fn classify_arg<'a, Ty, C>(
|
||||
}
|
||||
|
||||
let total = arg.layout.size;
|
||||
let align = arg.layout.align.abi.bits();
|
||||
let align = arg.layout.align.bits();
|
||||
|
||||
// "Scalars wider than 2✕XLEN are passed by reference and are replaced in
|
||||
// the argument list with the address."
|
||||
|
||||
@@ -21,7 +21,7 @@ fn classify_arg<Ty>(arg: &mut ArgAbi<'_, Ty>) {
|
||||
|
||||
/// the pass mode used for aggregates in arg and ret position
|
||||
fn classify_aggregate<Ty>(arg: &mut ArgAbi<'_, Ty>) {
|
||||
let align_bytes = arg.layout.align.abi.bytes();
|
||||
let align_bytes = arg.layout.align.bytes();
|
||||
let size = arg.layout.size;
|
||||
|
||||
let reg = match align_bytes {
|
||||
@@ -60,7 +60,7 @@ where
|
||||
// "`extern \"ptx-kernel\"` doesn't allow passing types other than primitives and structs"
|
||||
// );
|
||||
|
||||
let align_bytes = arg.layout.align.abi.bytes();
|
||||
let align_bytes = arg.layout.align.bytes();
|
||||
|
||||
let unit = match align_bytes {
|
||||
1 => Reg::i8(),
|
||||
|
||||
@@ -89,7 +89,7 @@ where
|
||||
// Aggregates larger than i64 should be padded at the tail to fill out a whole number
|
||||
// of i64s or i128s, depending on the aggregate alignment. Always use an array for
|
||||
// this, even if there is only a single element.
|
||||
let reg = if arg.layout.align.abi.bytes() > 8 { Reg::i128() } else { Reg::i64() };
|
||||
let reg = if arg.layout.align.bytes() > 8 { Reg::i128() } else { Reg::i64() };
|
||||
arg.cast_to(Uniform::consecutive(
|
||||
reg,
|
||||
size.align_to(Align::from_bytes(reg.size.bytes()).unwrap()),
|
||||
|
||||
@@ -328,7 +328,7 @@ fn classify_arg<'a, Ty, C>(
|
||||
}
|
||||
|
||||
let total = arg.layout.size;
|
||||
let align = arg.layout.align.abi.bits();
|
||||
let align = arg.layout.align.bits();
|
||||
|
||||
// "Scalars wider than 2✕XLEN are passed by reference and are replaced in
|
||||
// the argument list with the address."
|
||||
|
||||
@@ -48,7 +48,7 @@ where
|
||||
}
|
||||
|
||||
let size = arg.layout.size.bits();
|
||||
let needed_align = arg.layout.align.abi.bits();
|
||||
let needed_align = arg.layout.align.bits();
|
||||
let mut must_use_stack = false;
|
||||
|
||||
// Determine the number of GPRs needed to pass the current argument
|
||||
|
||||
@@ -361,7 +361,7 @@ pub(crate) mod rustc {
|
||||
|
||||
ty::Ref(region, ty, mutability) => {
|
||||
let layout = layout_of(cx, *ty)?;
|
||||
let referent_align = layout.align.abi.bytes_usize();
|
||||
let referent_align = layout.align.bytes_usize();
|
||||
let referent_size = layout.size.bytes_usize();
|
||||
|
||||
Ok(Tree::Ref(Reference {
|
||||
|
||||
@@ -795,7 +795,7 @@ fn variant_info_for_adt<'tcx>(
|
||||
name,
|
||||
offset: offset.bytes(),
|
||||
size: field_layout.size.bytes(),
|
||||
align: field_layout.align.abi.bytes(),
|
||||
align: field_layout.align.bytes(),
|
||||
type_name: None,
|
||||
}
|
||||
})
|
||||
@@ -804,7 +804,7 @@ fn variant_info_for_adt<'tcx>(
|
||||
VariantInfo {
|
||||
name: n,
|
||||
kind: if layout.is_unsized() { SizeKind::Min } else { SizeKind::Exact },
|
||||
align: layout.align.abi.bytes(),
|
||||
align: layout.align.bytes(),
|
||||
size: if min_size.bytes() == 0 { layout.size.bytes() } else { min_size.bytes() },
|
||||
fields: field_info,
|
||||
}
|
||||
@@ -877,7 +877,7 @@ fn variant_info_for_coroutine<'tcx>(
|
||||
name: *name,
|
||||
offset: offset.bytes(),
|
||||
size: field_layout.size.bytes(),
|
||||
align: field_layout.align.abi.bytes(),
|
||||
align: field_layout.align.bytes(),
|
||||
type_name: None,
|
||||
}
|
||||
})
|
||||
@@ -905,7 +905,7 @@ fn variant_info_for_coroutine<'tcx>(
|
||||
}),
|
||||
offset: offset.bytes(),
|
||||
size: field_layout.size.bytes(),
|
||||
align: field_layout.align.abi.bytes(),
|
||||
align: field_layout.align.bytes(),
|
||||
// Include the type name if there is no field name, or if the name is the
|
||||
// __awaitee placeholder symbol which means a child future being `.await`ed.
|
||||
type_name: (field_name.is_none() || field_name == Some(sym::__awaitee))
|
||||
@@ -946,7 +946,7 @@ fn variant_info_for_coroutine<'tcx>(
|
||||
name: Some(Symbol::intern(&ty::CoroutineArgs::variant_name(variant_idx))),
|
||||
kind: SizeKind::Exact,
|
||||
size: variant_size.bytes(),
|
||||
align: variant_layout.align.abi.bytes(),
|
||||
align: variant_layout.align.bytes(),
|
||||
fields,
|
||||
}
|
||||
})
|
||||
|
||||
@@ -8,7 +8,7 @@ use rustc_middle::ty::layout::{HasTyCtxt, LayoutCx, TyAndLayout};
|
||||
pub(super) fn layout_sanity_check<'tcx>(cx: &LayoutCx<'tcx>, layout: &TyAndLayout<'tcx>) {
|
||||
let tcx = cx.tcx();
|
||||
|
||||
if !layout.size.bytes().is_multiple_of(layout.align.abi.bytes()) {
|
||||
if !layout.size.bytes().is_multiple_of(layout.align.bytes()) {
|
||||
bug!("size is not a multiple of align, in the following layout:\n{layout:#?}");
|
||||
}
|
||||
if layout.size.bytes() >= tcx.data_layout.obj_size_bound() {
|
||||
@@ -300,8 +300,8 @@ pub(super) fn layout_sanity_check<'tcx>(cx: &LayoutCx<'tcx>, layout: &TyAndLayou
|
||||
if variant.align.abi > layout.align.abi {
|
||||
bug!(
|
||||
"Type with alignment {} bytes has variant with alignment {} bytes: {layout:#?}",
|
||||
layout.align.abi.bytes(),
|
||||
variant.align.abi.bytes(),
|
||||
layout.align.bytes(),
|
||||
variant.align.bytes(),
|
||||
)
|
||||
}
|
||||
// Skip empty variants.
|
||||
|
||||
@@ -43,8 +43,8 @@ fn lint_cast_ptr_alignment<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'_>, cast_f
|
||||
expr.span,
|
||||
format!(
|
||||
"casting from `{cast_from}` to a more-strictly-aligned pointer (`{cast_to}`) ({} < {} bytes)",
|
||||
from_layout.align.abi.bytes(),
|
||||
to_layout.align.abi.bytes(),
|
||||
from_layout.align.bytes(),
|
||||
to_layout.align.bytes(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ fn is_literal_aligned(cx: &LateContext<'_>, lit: &Spanned<LitKind>, to: &Ty<'_>)
|
||||
cx.tcx
|
||||
.layout_of(cx.typing_env().as_query_input(to_mid_ty))
|
||||
.is_ok_and(|layout| {
|
||||
let align = u128::from(layout.align.abi.bytes());
|
||||
let align = u128::from(layout.align.bytes());
|
||||
u128::from(val) <= align
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1341,7 +1341,7 @@ impl<'tcx> Machine<'tcx> for MiriMachine<'tcx> {
|
||||
name = ecx.tcx.def_path_str(def_id),
|
||||
krate = ecx.tcx.crate_name(def_id.krate),
|
||||
decl_size = extern_decl_layout.size.bytes(),
|
||||
decl_align = extern_decl_layout.align.abi.bytes(),
|
||||
decl_align = extern_decl_layout.align.bytes(),
|
||||
shim_size = info.size.bytes(),
|
||||
shim_align = info.align.bytes(),
|
||||
)
|
||||
|
||||
@@ -150,7 +150,7 @@ fn check_size_and_align(
|
||||
) {
|
||||
let l = eval_goal(ra_fixture, minicore).unwrap();
|
||||
assert_eq!(l.size.bytes(), size, "size mismatch");
|
||||
assert_eq!(l.align.abi.bytes(), align, "align mismatch");
|
||||
assert_eq!(l.align.bytes(), align, "align mismatch");
|
||||
}
|
||||
|
||||
#[track_caller]
|
||||
@@ -162,7 +162,7 @@ fn check_size_and_align_expr(
|
||||
) {
|
||||
let l = eval_expr(ra_fixture, minicore).unwrap();
|
||||
assert_eq!(l.size.bytes(), size, "size mismatch");
|
||||
assert_eq!(l.align.abi.bytes(), align, "align mismatch");
|
||||
assert_eq!(l.align.bytes(), align, "align mismatch");
|
||||
}
|
||||
|
||||
#[track_caller]
|
||||
|
||||
@@ -2085,7 +2085,7 @@ impl<'db> Evaluator<'db> {
|
||||
if let Some(layout) = self.layout_cache.borrow().get(&ty.to_nextsolver(interner)) {
|
||||
return Ok(layout
|
||||
.is_sized()
|
||||
.then(|| (layout.size.bytes_usize(), layout.align.abi.bytes() as usize)));
|
||||
.then(|| (layout.size.bytes_usize(), layout.align.bytes() as usize)));
|
||||
}
|
||||
if let DefWithBodyId::VariantId(f) = locals.body.owner
|
||||
&& let Some((AdtId::EnumId(e), _)) = ty.as_adt()
|
||||
@@ -2104,7 +2104,7 @@ impl<'db> Evaluator<'db> {
|
||||
let layout = layout?;
|
||||
Ok(layout
|
||||
.is_sized()
|
||||
.then(|| (layout.size.bytes_usize(), layout.align.abi.bytes() as usize)))
|
||||
.then(|| (layout.size.bytes_usize(), layout.align.bytes() as usize)))
|
||||
}
|
||||
|
||||
/// A version of `self.size_of` which returns error if the type is unsized. `what` argument should
|
||||
@@ -2797,7 +2797,7 @@ impl<'db> Evaluator<'db> {
|
||||
)?;
|
||||
// FIXME: there is some leak here
|
||||
let size = layout.size.bytes_usize();
|
||||
let addr = self.heap_allocate(size, layout.align.abi.bytes() as usize)?;
|
||||
let addr = self.heap_allocate(size, layout.align.bytes() as usize)?;
|
||||
self.write_memory(addr, &result)?;
|
||||
IntervalAndTy { interval: Interval { addr, size }, ty }
|
||||
};
|
||||
|
||||
@@ -767,7 +767,7 @@ impl Evaluator<'_> {
|
||||
"align_of generic arg is not provided".into(),
|
||||
));
|
||||
};
|
||||
let align = self.layout(ty.to_nextsolver(interner))?.align.abi.bytes();
|
||||
let align = self.layout(ty.to_nextsolver(interner))?.align.bytes();
|
||||
destination.write_from_bytes(self, &align.to_le_bytes()[0..destination.size])
|
||||
}
|
||||
"size_of_val" => {
|
||||
@@ -1431,7 +1431,7 @@ impl Evaluator<'_> {
|
||||
field_types.iter().next_back().unwrap().1.clone().substitute(Interner, subst);
|
||||
let sized_part_size =
|
||||
layout.fields.offset(field_types.iter().count() - 1).bytes_usize();
|
||||
let sized_part_align = layout.align.abi.bytes() as usize;
|
||||
let sized_part_align = layout.align.bytes() as usize;
|
||||
let (unsized_part_size, unsized_part_align) =
|
||||
self.size_align_of_unsized(&last_field_ty, metadata, locals)?;
|
||||
let align = sized_part_align.max(unsized_part_align) as isize;
|
||||
|
||||
@@ -6094,7 +6094,7 @@ impl Layout {
|
||||
}
|
||||
|
||||
pub fn align(&self) -> u64 {
|
||||
self.0.align.abi.bytes()
|
||||
self.0.align.bytes()
|
||||
}
|
||||
|
||||
pub fn niches(&self) -> Option<u128> {
|
||||
|
||||
Reference in New Issue
Block a user