Skip to content

Commit bd51a2b

Browse files
committed
rustc: move size/alignment from Layout into layout::Abi.
1 parent bd86f37 commit bd51a2b

File tree

16 files changed

+257
-214
lines changed

16 files changed

+257
-214
lines changed

src/librustc/ty/layout.rs

Lines changed: 199 additions & 160 deletions
Large diffs are not rendered by default.

src/librustc_lint/types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -753,7 +753,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for VariantSizeDifferences {
753753
bug!("failed to get layout for `{}`: {}", t, e)
754754
});
755755

756-
if let Layout::General { ref variants, ref size, discr, .. } = *layout {
756+
if let Layout::General { ref variants, size, discr, .. } = *layout.layout {
757757
let discr_size = discr.size(cx.tcx).bytes();
758758

759759
debug!("enum `{}` is {} bytes large with layout:\n{:#?}",

src/librustc_trans/abi.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -278,8 +278,8 @@ impl<'tcx> LayoutExt<'tcx> for FullLayout<'tcx> {
278278
fn is_aggregate(&self) -> bool {
279279
match self.abi {
280280
layout::Abi::Scalar(_) |
281-
layout::Abi::Vector => false,
282-
layout::Abi::Aggregate => true
281+
layout::Abi::Vector { .. } => false,
282+
layout::Abi::Aggregate { .. } => true
283283
}
284284
}
285285

@@ -299,14 +299,14 @@ impl<'tcx> LayoutExt<'tcx> for FullLayout<'tcx> {
299299
})
300300
}
301301

302-
layout::Abi::Vector => {
302+
layout::Abi::Vector { .. } => {
303303
Some(Reg {
304304
kind: RegKind::Vector,
305305
size: self.size(ccx)
306306
})
307307
}
308308

309-
layout::Abi::Aggregate => {
309+
layout::Abi::Aggregate { .. } => {
310310
if let Layout::Array { count, .. } = *self.layout {
311311
if count > 0 {
312312
return self.field(ccx, 0).homogeneous_aggregate(ccx);
@@ -767,7 +767,7 @@ impl<'a, 'tcx> FnType<'tcx> {
767767
for ty in inputs.iter().chain(extra_args.iter()) {
768768
let mut arg = arg_of(ty, false);
769769

770-
if let ty::layout::FatPointer { .. } = *arg.layout {
770+
if let ty::layout::FatPointer { .. } = *arg.layout.layout {
771771
let mut data = ArgType::new(arg.layout.field(ccx, 0));
772772
let mut info = ArgType::new(arg.layout.field(ccx, 1));
773773

@@ -809,7 +809,7 @@ impl<'a, 'tcx> FnType<'tcx> {
809809
abi == Abi::RustIntrinsic || abi == Abi::PlatformIntrinsic {
810810
let fixup = |arg: &mut ArgType<'tcx>| {
811811
match arg.layout.abi {
812-
layout::Abi::Aggregate => {}
812+
layout::Abi::Aggregate { .. } => {}
813813
_ => return
814814
}
815815

src/librustc_trans/adt.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ pub fn finish_type_of<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
7171
if let layout::Abi::Scalar(_) = l.abi {
7272
return;
7373
}
74-
match *l {
74+
match *l.layout {
7575
layout::NullablePointer { .. } |
7676
layout::General { .. } |
7777
layout::UntaggedUnion { .. } => { }
@@ -101,7 +101,7 @@ fn generic_type_of<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
101101
if let layout::Abi::Scalar(value) = l.abi {
102102
return cx.llvm_type_of(value.to_ty(cx.tcx()));
103103
}
104-
match *l {
104+
match *l.layout {
105105
layout::Univariant(ref variant) => {
106106
match name {
107107
None => {

src/librustc_trans/cabi_s390x.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ fn is_single_fp_element<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
2929
match layout.abi {
3030
layout::Abi::Scalar(layout::F32) |
3131
layout::Abi::Scalar(layout::F64) => true,
32-
layout::Abi::Aggregate => {
32+
layout::Abi::Aggregate { .. } => {
3333
if layout.fields.count() == 1 && layout.fields.offset(0).bytes() == 0 {
3434
is_single_fp_element(ccx, layout.field(ccx, 0))
3535
} else {

src/librustc_trans/cabi_x86.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ fn is_single_fp_element<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
2424
match layout.abi {
2525
layout::Abi::Scalar(layout::F32) |
2626
layout::Abi::Scalar(layout::F64) => true,
27-
layout::Abi::Aggregate => {
27+
layout::Abi::Aggregate { .. } => {
2828
if layout.fields.count() == 1 && layout.fields.offset(0).bytes() == 0 {
2929
is_single_fp_element(ccx, layout.field(ccx, 0))
3030
} else {

src/librustc_trans/cabi_x86_64.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,22 +75,22 @@ fn classify_arg<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, arg: &ArgType<'tcx>)
7575
unify(cls, off, reg);
7676
}
7777

78-
layout::Abi::Vector => {
78+
layout::Abi::Vector { element, count } => {
7979
unify(cls, off, Class::Sse);
8080

8181
// everything after the first one is the upper
8282
// half of a register.
83-
let eltsz = layout.field(ccx, 0).size(ccx);
84-
for i in 1..layout.fields.count() {
83+
let eltsz = element.size(ccx);
84+
for i in 1..count {
8585
unify(cls, off + eltsz * (i as u64), Class::SseUp);
8686
}
8787
}
8888

89-
layout::Abi::Aggregate => {
89+
layout::Abi::Aggregate { .. } => {
9090
// FIXME(eddyb) have to work around Rust enums for now.
9191
// Fix is either guarantee no data where there is no field,
9292
// by putting variants in fields, or be more clever.
93-
match *layout {
93+
match *layout.layout {
9494
Layout::General { .. } |
9595
Layout::NullablePointer { .. } => return Err(Memory),
9696
_ => {}

src/librustc_trans/cabi_x86_win64.rs

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,32 +8,36 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use abi::{ArgType, FnType, LayoutExt, Reg};
11+
use abi::{ArgType, FnType, Reg};
1212
use common::CrateContext;
1313

14-
use rustc::ty::layout::Layout;
14+
use rustc::ty::layout;
1515

1616
// Win64 ABI: http://msdn.microsoft.com/en-us/library/zthk2dkh.aspx
1717

1818
pub fn compute_abi_info<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, fty: &mut FnType<'tcx>) {
1919
let fixup = |a: &mut ArgType<'tcx>| {
2020
let size = a.layout.size(ccx);
21-
if a.layout.is_aggregate() {
22-
match size.bits() {
23-
8 => a.cast_to(Reg::i8()),
24-
16 => a.cast_to(Reg::i16()),
25-
32 => a.cast_to(Reg::i32()),
26-
64 => a.cast_to(Reg::i64()),
27-
_ => a.make_indirect(ccx)
28-
};
29-
} else {
30-
if let Layout::Vector { .. } = *a.layout {
21+
match a.layout.abi {
22+
layout::Abi::Aggregate { .. } => {
23+
match size.bits() {
24+
8 => a.cast_to(Reg::i8()),
25+
16 => a.cast_to(Reg::i16()),
26+
32 => a.cast_to(Reg::i32()),
27+
64 => a.cast_to(Reg::i64()),
28+
_ => a.make_indirect(ccx)
29+
}
30+
}
31+
layout::Abi::Vector { .. } => {
3132
// FIXME(eddyb) there should be a size cap here
3233
// (probably what clang calls "illegal vectors").
33-
} else if size.bytes() > 8 {
34-
a.make_indirect(ccx);
35-
} else {
36-
a.extend_integer_width_to(32);
34+
}
35+
layout::Abi::Scalar(_) => {
36+
if size.bytes() > 8 {
37+
a.make_indirect(ccx);
38+
} else {
39+
a.extend_integer_width_to(32);
40+
}
3741
}
3842
}
3943
};

src/librustc_trans/common.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ use syntax_pos::{Span, DUMMY_SP};
4141
pub use context::{CrateContext, SharedCrateContext};
4242

4343
pub fn type_is_fat_ptr<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, ty: Ty<'tcx>) -> bool {
44-
if let Layout::FatPointer { .. } = *ccx.layout_of(ty) {
44+
if let Layout::FatPointer { .. } = *ccx.layout_of(ty).layout {
4545
true
4646
} else {
4747
false
@@ -51,9 +51,9 @@ pub fn type_is_fat_ptr<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, ty: Ty<'tcx>) ->
5151
pub fn type_is_immediate<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, ty: Ty<'tcx>) -> bool {
5252
let layout = ccx.layout_of(ty);
5353
match layout.abi {
54-
layout::Abi::Scalar(_) | layout::Abi::Vector => true,
54+
layout::Abi::Scalar(_) | layout::Abi::Vector { .. } => true,
5555

56-
layout::Abi::Aggregate => {
56+
layout::Abi::Aggregate { .. } => {
5757
!layout.is_unsized() && layout.size(ccx).bytes() == 0
5858
}
5959
}
@@ -63,7 +63,7 @@ pub fn type_is_immediate<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, ty: Ty<'tcx>) -
6363
pub fn type_is_imm_pair<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, ty: Ty<'tcx>)
6464
-> bool {
6565
let layout = ccx.layout_of(ty);
66-
match *layout {
66+
match *layout.layout {
6767
Layout::FatPointer { .. } => true,
6868
Layout::Univariant(ref variant) => {
6969
// There must be only 2 fields.

src/librustc_trans/debuginfo/metadata.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -941,7 +941,7 @@ impl<'tcx> StructMemberDescriptionFactory<'tcx> {
941941
let layout = cx.layout_of(self.ty);
942942

943943
let tmp;
944-
let offsets = match *layout {
944+
let offsets = match *layout.layout {
945945
layout::Univariant(ref variant) => &variant.offsets,
946946
layout::Vector { element, count } => {
947947
let element_size = element.size(cx).bytes();
@@ -1022,7 +1022,7 @@ impl<'tcx> TupleMemberDescriptionFactory<'tcx> {
10221022
fn create_member_descriptions<'a>(&self, cx: &CrateContext<'a, 'tcx>)
10231023
-> Vec<MemberDescription> {
10241024
let layout = cx.layout_of(self.ty);
1025-
let offsets = if let layout::Univariant(ref variant) = *layout {
1025+
let offsets = if let layout::Univariant(ref variant) = *layout.layout {
10261026
&variant.offsets
10271027
} else {
10281028
bug!("{} is not a tuple", self.ty);
@@ -1339,7 +1339,7 @@ fn describe_enum_variant<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
13391339
span: Span)
13401340
-> (DICompositeType, MemberDescriptionFactory<'tcx>) {
13411341
let layout = cx.layout_of(enum_type);
1342-
let maybe_discr = match *layout {
1342+
let maybe_discr = match *layout.layout {
13431343
layout::General { .. } => Some(layout.field(cx, 0).ty),
13441344
_ => None,
13451345
};
@@ -1491,7 +1491,7 @@ fn prepare_enum_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
14911491

14921492
let type_rep = cx.layout_of(enum_type);
14931493

1494-
let discriminant_type_metadata = match *type_rep {
1494+
let discriminant_type_metadata = match *type_rep.layout {
14951495
layout::NullablePointer { .. } | layout::Univariant { .. } => None,
14961496
layout::General { discr, .. } => Some(discriminant_type_metadata(discr)),
14971497
ref l @ _ => bug!("Not an enum layout: {:#?}", l)

0 commit comments

Comments
 (0)