Skip to content

Commit 4e2382f

Browse files
committed
add Primitive.pref_pos
1 parent 14a8b0a commit 4e2382f

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

src/librustc/ty/layout.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -251,12 +251,15 @@ fn invert_mapping(map: &[u32]) -> Vec<u32> {
251251
impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
252252
fn scalar_pair(&self, a: Scalar, b: Scalar) -> LayoutDetails {
253253
let dl = self.data_layout();
254-
let b_align = b.value.align(dl);
255-
let align = a.value.align(dl).max(b_align).max(dl.aggregate_align);
256-
let b_offset = a.value.size(dl).align_to(b_align.abi);
257-
let size = (b_offset + b.value.size(dl)).align_to(align.abi);
258254

259-
let pref_pos = LayoutPositionPref::new(size, align);
255+
let a_pref_pos = a.value.pref_pos(dl);
256+
let b_pref_pos = b.value.pref_pos(dl);
257+
258+
let b_align = b_pref_pos.align;
259+
260+
let pref_pos = a_pref_pos.align_to(b_align).align_to(dl.aggregate_align);
261+
let (pref_pos, b_offset) = pref_pos.extend(b_pref_pos);
262+
let pref_pos = pref_pos.strided();
260263

261264
// HACK(nox): We iter on `b` and then `a` because `max_by_key`
262265
// returns the last maximum.

src/librustc_target/abi/mod.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,17 @@ pub enum Primitive {
696696
}
697697

698698
impl Primitive {
699+
pub fn pref_pos<C: HasDataLayout>(self, cx: &C) -> LayoutPositionPref {
700+
let dl = cx.data_layout();
701+
702+
match self {
703+
Int(i, _) => LayoutPositionPref::new(i.size(), i.align(dl)),
704+
F32 => LayoutPositionPref::new(Size::from_bits(32), dl.f32_align),
705+
F64 => LayoutPositionPref::new(Size::from_bits(64), dl.f64_align),
706+
Pointer => dl.pointer_pos
707+
}
708+
}
709+
699710
pub fn size<C: HasDataLayout>(self, cx: &C) -> Size {
700711
let dl = cx.data_layout();
701712

@@ -1069,9 +1080,7 @@ pub struct LayoutDetails {
10691080
impl LayoutDetails {
10701081
pub fn scalar<C: HasDataLayout>(cx: &C, scalar: Scalar) -> Self {
10711082
let largest_niche = Niche::from_scalar(cx, Size::ZERO, scalar.clone());
1072-
let size = scalar.value.size(cx);
1073-
let align = scalar.value.align(cx);
1074-
let pref_pos = LayoutPositionPref::new(size, align);
1083+
let pref_pos = scalar.value.pref_pos(cx);
10751084
LayoutDetails {
10761085
variants: Variants::Single { index: VariantIdx::new(0) },
10771086
fields: FieldPlacement::Union(0),

0 commit comments

Comments
 (0)