Skip to content

Commit 96441d5

Browse files
committed
local optimizations and dead code removal
1 parent ad3f9df commit 96441d5

File tree

1 file changed

+12
-57
lines changed

1 file changed

+12
-57
lines changed

compiler/rustc_ty_utils/src/alignment.rs

Lines changed: 12 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use rustc_hir as hir;
22
use rustc_index::bit_set::BitSet;
3-
use rustc_index::vec::{Idx, IndexVec};
3+
use rustc_index::vec::IndexVec;
44
use rustc_middle::mir::{GeneratorLayout, GeneratorSavedLocal};
55
use rustc_middle::ty::layout::{
66
IntegerExt, LayoutCx, LayoutError, LayoutOf, TyAndLayout, MAX_SIMD_LANES,
@@ -201,44 +201,16 @@ fn align_of_uncached<'tcx>(
201201

202202
let count = count.try_eval_usize(tcx, param_env).ok_or(LayoutError::Unknown(ty))?;
203203
let element = cx.layout_of(element)?;
204-
let size = element.size.checked_mul(count, dl).ok_or(LayoutError::SizeOverflow(ty))?;
204+
element.size.checked_mul(count, dl).ok_or(LayoutError::SizeOverflow(ty))?;
205205

206-
let abi = if count != 0 && ty.is_privately_uninhabited(tcx, param_env) {
207-
Abi::Uninhabited
208-
} else {
209-
Abi::Aggregate { sized: true }
210-
};
211-
212-
let largest_niche = if count != 0 { element.largest_niche } else { None };
213-
214-
tcx.intern_layout(LayoutS {
215-
variants: Variants::Single { index: VariantIdx::new(0) },
216-
fields: FieldsShape::Array { stride: element.size, count },
217-
abi,
218-
largest_niche,
219-
align: element.align,
220-
size,
221-
}).align()
206+
element.align
222207
}
223208
ty::Slice(element) => {
224209
let element = cx.layout_of(element)?;
225-
tcx.intern_layout(LayoutS {
226-
variants: Variants::Single { index: VariantIdx::new(0) },
227-
fields: FieldsShape::Array { stride: element.size, count: 0 },
228-
abi: Abi::Aggregate { sized: false },
229-
largest_niche: None,
230-
align: element.align,
231-
size: Size::ZERO,
232-
}).align()
233-
}
234-
ty::Str => tcx.intern_layout(LayoutS {
235-
variants: Variants::Single { index: VariantIdx::new(0) },
236-
fields: FieldsShape::Array { stride: Size::from_bytes(1), count: 0 },
237-
abi: Abi::Aggregate { sized: false },
238-
largest_niche: None,
239-
align: dl.i8_align,
240-
size: Size::ZERO,
241-
}).align(),
210+
element.align
211+
},
212+
213+
ty::Str => dl.i8_align,
242214

243215
// Odd unit types.
244216
ty::FnDef(..) => univariant(&[], &ReprOptions::default(), StructKind::AlwaysSized)?.align(),
@@ -322,7 +294,7 @@ fn align_of_uncached<'tcx>(
322294
// the first field is of array type, or
323295
//
324296
// * the homogeneous field type and the number of fields.
325-
let (e_ty, e_len, is_array) = if let ty::Array(e_ty, _) = f0_ty.kind() {
297+
let (e_ty, e_len) = if let ty::Array(e_ty, _) = f0_ty.kind() {
326298
// First ADT field is an array:
327299

328300
// SIMD vectors with multiple array fields are not supported:
@@ -339,10 +311,10 @@ fn align_of_uncached<'tcx>(
339311
return Err(LayoutError::Unknown(ty));
340312
};
341313

342-
(*e_ty, *count, true)
314+
(*e_ty, *count)
343315
} else {
344316
// First ADT field is not an array:
345-
(f0_ty, def.non_enum_variant().fields.len() as _, false)
317+
(f0_ty, def.non_enum_variant().fields.len() as _)
346318
};
347319

348320
// SIMD vectors of zero length are not supported.
@@ -361,7 +333,7 @@ fn align_of_uncached<'tcx>(
361333

362334
// Compute the ABI of the element type:
363335
let e_ly = cx.layout_of(e_ty)?;
364-
let Abi::Scalar(e_abi) = e_ly.abi else {
336+
let Abi::Scalar(_) = e_ly.abi else {
365337
// This error isn't caught in typeck, e.g., if
366338
// the element type of the vector is generic.
367339
tcx.sess.fatal(&format!(
@@ -373,24 +345,7 @@ fn align_of_uncached<'tcx>(
373345

374346
// Compute the size and alignment of the vector:
375347
let size = e_ly.size.checked_mul(e_len, dl).ok_or(LayoutError::SizeOverflow(ty))?;
376-
let align = dl.vector_align(size);
377-
let size = size.align_to(align.abi);
378-
379-
// Compute the placement of the vector fields:
380-
let fields = if is_array {
381-
FieldsShape::Arbitrary { offsets: vec![Size::ZERO], memory_index: vec![0] }
382-
} else {
383-
FieldsShape::Array { stride: e_ly.size, count: e_len }
384-
};
385-
386-
tcx.intern_layout(LayoutS {
387-
variants: Variants::Single { index: VariantIdx::new(0) },
388-
fields,
389-
abi: Abi::Vector { element: e_abi, count: e_len },
390-
largest_niche: e_ly.largest_niche,
391-
size,
392-
align,
393-
}).align()
348+
dl.vector_align(size)
394349
}
395350

396351
// ADTs.

0 commit comments

Comments
 (0)