Skip to content

Commit cd6f32a

Browse files
authored
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.
2 parents 6c40c16 + 0c9d0df commit cd6f32a

File tree

40 files changed

+66
-68
lines changed

40 files changed

+66
-68
lines changed

compiler/rustc_abi/src/layout.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1167,7 +1167,7 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
11671167
// To allow unsizing `&Foo<Type>` -> `&Foo<dyn Trait>`, the layout of the struct must
11681168
// not depend on the layout of the tail.
11691169
let max_field_align =
1170-
fields_excluding_tail.iter().map(|f| f.align.abi.bytes()).max().unwrap_or(1);
1170+
fields_excluding_tail.iter().map(|f| f.align.bytes()).max().unwrap_or(1);
11711171
let largest_niche_size = fields_excluding_tail
11721172
.iter()
11731173
.filter_map(|f| f.largest_niche)
@@ -1187,7 +1187,7 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
11871187
} else {
11881188
// Returns `log2(effective-align)`. The calculation assumes that size is an
11891189
// integer multiple of align, except for ZSTs.
1190-
let align = layout.align.abi.bytes();
1190+
let align = layout.align.bytes();
11911191
let size = layout.size.bytes();
11921192
let niche_size = layout.largest_niche.map(|n| n.available(dl)).unwrap_or(0);
11931193
// Group [u8; 4] with align-4 or [u8; 6] with align-2 fields.
@@ -1485,7 +1485,7 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
14851485
for i in layout.fields.index_by_increasing_offset() {
14861486
let offset = layout.fields.offset(i);
14871487
let f = &fields[FieldIdx::new(i)];
1488-
write!(s, "[o{}a{}s{}", offset.bytes(), f.align.abi.bytes(), f.size.bytes()).unwrap();
1488+
write!(s, "[o{}a{}s{}", offset.bytes(), f.align.bytes(), f.size.bytes()).unwrap();
14891489
if let Some(n) = f.largest_niche {
14901490
write!(
14911491
s,

compiler/rustc_abi/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2156,7 +2156,7 @@ impl<FieldIdx: Idx, VariantIdx: Idx> LayoutData<FieldIdx, VariantIdx> {
21562156

21572157
/// Returns `true` if the type is sized and a 1-ZST (meaning it has size 0 and alignment 1).
21582158
pub fn is_1zst(&self) -> bool {
2159-
self.is_sized() && self.size.bytes() == 0 && self.align.abi.bytes() == 1
2159+
self.is_sized() && self.size.bytes() == 0 && self.align.bytes() == 1
21602160
}
21612161

21622162
/// Returns `true` if the type is a ZST and not unsized.

compiler/rustc_codegen_cranelift/src/abi/comments.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ pub(super) fn add_local_place_comments<'tcx>(
8989
format!("{:?}", local),
9090
format!("{:?}", ty),
9191
size.bytes(),
92-
align.abi.bytes(),
92+
align.bytes(),
9393
if extra.is_empty() { "" } else { " " },
9494
extra,
9595
));

compiler/rustc_codegen_cranelift/src/abi/pass_mode.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ pub(super) fn from_casted_value<'tcx>(
233233
// It may also be smaller for example when the type is a wrapper around an integer with a
234234
// larger alignment than the integer.
235235
std::cmp::max(abi_param_size, layout_size),
236-
u32::try_from(layout.align.abi.bytes()).unwrap(),
236+
u32::try_from(layout.align.bytes()).unwrap(),
237237
);
238238
let mut block_params_iter = block_params.iter().copied();
239239
for (offset, _) in abi_params {

compiler/rustc_codegen_cranelift/src/base.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -846,7 +846,7 @@ fn codegen_stmt<'tcx>(fx: &mut FunctionCx<'_, '_, 'tcx>, cur_block: Block, stmt:
846846
let layout = fx.layout_of(fx.monomorphize(ty));
847847
let val = match null_op {
848848
NullOp::SizeOf => layout.size.bytes(),
849-
NullOp::AlignOf => layout.align.abi.bytes(),
849+
NullOp::AlignOf => layout.align.bytes(),
850850
NullOp::OffsetOf(fields) => fx
851851
.tcx
852852
.offset_of_subfield(

compiler/rustc_codegen_cranelift/src/debuginfo/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ impl DebugContext {
304304
entry.set(gimli::DW_AT_decl_file, AttributeValue::FileIndex(Some(file_id)));
305305
entry.set(gimli::DW_AT_decl_line, AttributeValue::Udata(line));
306306

307-
entry.set(gimli::DW_AT_alignment, AttributeValue::Udata(static_layout.align.abi.bytes()));
307+
entry.set(gimli::DW_AT_alignment, AttributeValue::Udata(static_layout.align.bytes()));
308308

309309
let mut expr = Expression::new();
310310
expr.op_addr(address_for_data(data_id));

compiler/rustc_codegen_cranelift/src/debuginfo/types.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ impl DebugContext {
166166
let tuple_entry = self.dwarf.unit.get_mut(tuple_type_id);
167167
tuple_entry.set(gimli::DW_AT_name, AttributeValue::StringRef(self.dwarf.strings.add(name)));
168168
tuple_entry.set(gimli::DW_AT_byte_size, AttributeValue::Udata(layout.size.bytes()));
169-
tuple_entry.set(gimli::DW_AT_alignment, AttributeValue::Udata(layout.align.abi.bytes()));
169+
tuple_entry.set(gimli::DW_AT_alignment, AttributeValue::Udata(layout.align.bytes()));
170170

171171
for (i, (ty, dw_ty)) in components.into_iter().enumerate() {
172172
let member_id = self.dwarf.unit.add(tuple_type_id, gimli::DW_TAG_member);
@@ -178,9 +178,7 @@ impl DebugContext {
178178
member_entry.set(gimli::DW_AT_type, AttributeValue::UnitRef(dw_ty));
179179
member_entry.set(
180180
gimli::DW_AT_alignment,
181-
AttributeValue::Udata(
182-
FullyMonomorphizedLayoutCx(tcx).layout_of(ty).align.abi.bytes(),
183-
),
181+
AttributeValue::Udata(FullyMonomorphizedLayoutCx(tcx).layout_of(ty).align.bytes()),
184182
);
185183
member_entry.set(
186184
gimli::DW_AT_data_member_location,

compiler/rustc_codegen_cranelift/src/unsize.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ pub(crate) fn size_and_align_of<'tcx>(
167167
if layout.is_sized() {
168168
return (
169169
fx.bcx.ins().iconst(fx.pointer_type, layout.size.bytes() as i64),
170-
fx.bcx.ins().iconst(fx.pointer_type, layout.align.abi.bytes() as i64),
170+
fx.bcx.ins().iconst(fx.pointer_type, layout.align.bytes() as i64),
171171
);
172172
}
173173

@@ -186,7 +186,7 @@ pub(crate) fn size_and_align_of<'tcx>(
186186
// times the unit size.
187187
(
188188
fx.bcx.ins().imul_imm(info.unwrap(), unit.size.bytes() as i64),
189-
fx.bcx.ins().iconst(fx.pointer_type, unit.align.abi.bytes() as i64),
189+
fx.bcx.ins().iconst(fx.pointer_type, unit.align.bytes() as i64),
190190
)
191191
}
192192
ty::Foreign(_) => {
@@ -224,7 +224,7 @@ pub(crate) fn size_and_align_of<'tcx>(
224224
let unsized_offset_unadjusted = layout.fields.offset(i).bytes();
225225
let unsized_offset_unadjusted =
226226
fx.bcx.ins().iconst(fx.pointer_type, unsized_offset_unadjusted as i64);
227-
let sized_align = layout.align.abi.bytes();
227+
let sized_align = layout.align.bytes();
228228
let sized_align = fx.bcx.ins().iconst(fx.pointer_type, sized_align as i64);
229229

230230
// Recurse to get the size of the dynamically sized field (must be

compiler/rustc_codegen_cranelift/src/value_and_place.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ impl<'tcx> CPlace<'tcx> {
383383

384384
let stack_slot = fx.create_stack_slot(
385385
u32::try_from(layout.size.bytes()).unwrap(),
386-
u32::try_from(layout.align.abi.bytes()).unwrap(),
386+
u32::try_from(layout.align.bytes()).unwrap(),
387387
);
388388
CPlace { inner: CPlaceInner::Addr(stack_slot, None), layout }
389389
}
@@ -641,8 +641,8 @@ impl<'tcx> CPlace<'tcx> {
641641
let size = dst_layout.size.bytes();
642642
// `emit_small_memory_copy` uses `u8` for alignments, just use the maximum
643643
// alignment that fits in a `u8` if the actual alignment is larger.
644-
let src_align = src_layout.align.abi.bytes().try_into().unwrap_or(128);
645-
let dst_align = dst_layout.align.abi.bytes().try_into().unwrap_or(128);
644+
let src_align = src_layout.align.bytes().try_into().unwrap_or(128);
645+
let dst_align = dst_layout.align.bytes().try_into().unwrap_or(128);
646646
fx.bcx.emit_small_memory_copy(
647647
fx.target_config,
648648
to_addr,

compiler/rustc_codegen_gcc/src/context.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
147147
let layout = tcx
148148
.layout_of(ty::TypingEnv::fully_monomorphized().as_query_input(rust_type))
149149
.unwrap();
150-
let align = layout.align.abi.bytes();
150+
let align = layout.align.bytes();
151151
// For types with size 1, the alignment can be 1 and only 1
152152
// So, we can skip the call to ``get_aligned`.
153153
// In the future, we can add a GCC API to query the type align,
@@ -186,9 +186,9 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
186186
(i128_type, u128_type)
187187
} else {
188188
/*let layout = tcx.layout_of(ParamEnv::reveal_all().and(tcx.types.i128)).unwrap();
189-
let i128_align = layout.align.abi.bytes();
189+
let i128_align = layout.align.bytes();
190190
let layout = tcx.layout_of(ParamEnv::reveal_all().and(tcx.types.u128)).unwrap();
191-
let u128_align = layout.align.abi.bytes();*/
191+
let u128_align = layout.align.bytes();*/
192192

193193
// TODO(antoyo): re-enable the alignment when libgccjit fixed the issue in
194194
// gcc_jit_context_new_array_constructor (it should not use reinterpret_cast).

0 commit comments

Comments
 (0)