diff options
| author | Eduard-Mihai Burtescu <edy.burt@gmail.com> | 2017-09-17 04:42:22 +0300 |
|---|---|---|
| committer | Eduard-Mihai Burtescu <edy.burt@gmail.com> | 2017-11-19 02:14:31 +0200 |
| commit | bd51a2bc192f323d0da2ea7716860b1699d315d8 (patch) | |
| tree | 67183938e89ad580214c020de42451531341bdc1 /src/librustc_trans | |
| parent | bd86f3739e76484e410ec5e651ab3ee9049f31ba (diff) | |
| download | rust-bd51a2bc192f323d0da2ea7716860b1699d315d8.tar.gz rust-bd51a2bc192f323d0da2ea7716860b1699d315d8.zip | |
rustc: move size/alignment from Layout into layout::Abi.
Diffstat (limited to 'src/librustc_trans')
| -rw-r--r-- | src/librustc_trans/abi.rs | 12 | ||||
| -rw-r--r-- | src/librustc_trans/adt.rs | 4 | ||||
| -rw-r--r-- | src/librustc_trans/cabi_s390x.rs | 2 | ||||
| -rw-r--r-- | src/librustc_trans/cabi_x86.rs | 2 | ||||
| -rw-r--r-- | src/librustc_trans/cabi_x86_64.rs | 10 | ||||
| -rw-r--r-- | src/librustc_trans/cabi_x86_win64.rs | 36 | ||||
| -rw-r--r-- | src/librustc_trans/common.rs | 8 | ||||
| -rw-r--r-- | src/librustc_trans/debuginfo/metadata.rs | 8 | ||||
| -rw-r--r-- | src/librustc_trans/glue.rs | 2 | ||||
| -rw-r--r-- | src/librustc_trans/mir/constant.rs | 2 | ||||
| -rw-r--r-- | src/librustc_trans/mir/lvalue.rs | 18 | ||||
| -rw-r--r-- | src/librustc_trans/mir/mod.rs | 2 | ||||
| -rw-r--r-- | src/librustc_trans/mir/rvalue.rs | 2 | ||||
| -rw-r--r-- | src/librustc_trans/type_of.rs | 2 |
14 files changed, 57 insertions, 53 deletions
diff --git a/src/librustc_trans/abi.rs b/src/librustc_trans/abi.rs index 93cfd967643..712108bf437 100644 --- a/src/librustc_trans/abi.rs +++ b/src/librustc_trans/abi.rs @@ -278,8 +278,8 @@ impl<'tcx> LayoutExt<'tcx> for FullLayout<'tcx> { fn is_aggregate(&self) -> bool { match self.abi { layout::Abi::Scalar(_) | - layout::Abi::Vector => false, - layout::Abi::Aggregate => true + layout::Abi::Vector { .. } => false, + layout::Abi::Aggregate { .. } => true } } @@ -299,14 +299,14 @@ impl<'tcx> LayoutExt<'tcx> for FullLayout<'tcx> { }) } - layout::Abi::Vector => { + layout::Abi::Vector { .. } => { Some(Reg { kind: RegKind::Vector, size: self.size(ccx) }) } - layout::Abi::Aggregate => { + layout::Abi::Aggregate { .. } => { if let Layout::Array { count, .. } = *self.layout { if count > 0 { return self.field(ccx, 0).homogeneous_aggregate(ccx); @@ -767,7 +767,7 @@ impl<'a, 'tcx> FnType<'tcx> { for ty in inputs.iter().chain(extra_args.iter()) { let mut arg = arg_of(ty, false); - if let ty::layout::FatPointer { .. } = *arg.layout { + if let ty::layout::FatPointer { .. } = *arg.layout.layout { let mut data = ArgType::new(arg.layout.field(ccx, 0)); let mut info = ArgType::new(arg.layout.field(ccx, 1)); @@ -809,7 +809,7 @@ impl<'a, 'tcx> FnType<'tcx> { abi == Abi::RustIntrinsic || abi == Abi::PlatformIntrinsic { let fixup = |arg: &mut ArgType<'tcx>| { match arg.layout.abi { - layout::Abi::Aggregate => {} + layout::Abi::Aggregate { .. } => {} _ => return } diff --git a/src/librustc_trans/adt.rs b/src/librustc_trans/adt.rs index 634dba3660e..314d929fe8c 100644 --- a/src/librustc_trans/adt.rs +++ b/src/librustc_trans/adt.rs @@ -71,7 +71,7 @@ pub fn finish_type_of<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, if let layout::Abi::Scalar(_) = l.abi { return; } - match *l { + match *l.layout { layout::NullablePointer { .. } | layout::General { .. } | layout::UntaggedUnion { .. } => { } @@ -101,7 +101,7 @@ fn generic_type_of<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, if let layout::Abi::Scalar(value) = l.abi { return cx.llvm_type_of(value.to_ty(cx.tcx())); } - match *l { + match *l.layout { layout::Univariant(ref variant) => { match name { None => { diff --git a/src/librustc_trans/cabi_s390x.rs b/src/librustc_trans/cabi_s390x.rs index a45fe662bd6..2766edb59c1 100644 --- a/src/librustc_trans/cabi_s390x.rs +++ b/src/librustc_trans/cabi_s390x.rs @@ -29,7 +29,7 @@ fn is_single_fp_element<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, match layout.abi { layout::Abi::Scalar(layout::F32) | layout::Abi::Scalar(layout::F64) => true, - layout::Abi::Aggregate => { + layout::Abi::Aggregate { .. } => { if layout.fields.count() == 1 && layout.fields.offset(0).bytes() == 0 { is_single_fp_element(ccx, layout.field(ccx, 0)) } else { diff --git a/src/librustc_trans/cabi_x86.rs b/src/librustc_trans/cabi_x86.rs index bc7c9a3ed05..7d3621d53e0 100644 --- a/src/librustc_trans/cabi_x86.rs +++ b/src/librustc_trans/cabi_x86.rs @@ -24,7 +24,7 @@ fn is_single_fp_element<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, match layout.abi { layout::Abi::Scalar(layout::F32) | layout::Abi::Scalar(layout::F64) => true, - layout::Abi::Aggregate => { + layout::Abi::Aggregate { .. } => { if layout.fields.count() == 1 && layout.fields.offset(0).bytes() == 0 { is_single_fp_element(ccx, layout.field(ccx, 0)) } else { diff --git a/src/librustc_trans/cabi_x86_64.rs b/src/librustc_trans/cabi_x86_64.rs index f2208e4909e..d6d46307a4f 100644 --- a/src/librustc_trans/cabi_x86_64.rs +++ b/src/librustc_trans/cabi_x86_64.rs @@ -75,22 +75,22 @@ fn classify_arg<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, arg: &ArgType<'tcx>) unify(cls, off, reg); } - layout::Abi::Vector => { + layout::Abi::Vector { element, count } => { unify(cls, off, Class::Sse); // everything after the first one is the upper // half of a register. - let eltsz = layout.field(ccx, 0).size(ccx); - for i in 1..layout.fields.count() { + let eltsz = element.size(ccx); + for i in 1..count { unify(cls, off + eltsz * (i as u64), Class::SseUp); } } - layout::Abi::Aggregate => { + layout::Abi::Aggregate { .. } => { // FIXME(eddyb) have to work around Rust enums for now. // Fix is either guarantee no data where there is no field, // by putting variants in fields, or be more clever. - match *layout { + match *layout.layout { Layout::General { .. } | Layout::NullablePointer { .. } => return Err(Memory), _ => {} diff --git a/src/librustc_trans/cabi_x86_win64.rs b/src/librustc_trans/cabi_x86_win64.rs index 1d391da5993..b27ccc98861 100644 --- a/src/librustc_trans/cabi_x86_win64.rs +++ b/src/librustc_trans/cabi_x86_win64.rs @@ -8,32 +8,36 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use abi::{ArgType, FnType, LayoutExt, Reg}; +use abi::{ArgType, FnType, Reg}; use common::CrateContext; -use rustc::ty::layout::Layout; +use rustc::ty::layout; // Win64 ABI: http://msdn.microsoft.com/en-us/library/zthk2dkh.aspx pub fn compute_abi_info<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, fty: &mut FnType<'tcx>) { let fixup = |a: &mut ArgType<'tcx>| { let size = a.layout.size(ccx); - if a.layout.is_aggregate() { - match size.bits() { - 8 => a.cast_to(Reg::i8()), - 16 => a.cast_to(Reg::i16()), - 32 => a.cast_to(Reg::i32()), - 64 => a.cast_to(Reg::i64()), - _ => a.make_indirect(ccx) - }; - } else { - if let Layout::Vector { .. } = *a.layout { + match a.layout.abi { + layout::Abi::Aggregate { .. } => { + match size.bits() { + 8 => a.cast_to(Reg::i8()), + 16 => a.cast_to(Reg::i16()), + 32 => a.cast_to(Reg::i32()), + 64 => a.cast_to(Reg::i64()), + _ => a.make_indirect(ccx) + } + } + layout::Abi::Vector { .. } => { // FIXME(eddyb) there should be a size cap here // (probably what clang calls "illegal vectors"). - } else if size.bytes() > 8 { - a.make_indirect(ccx); - } else { - a.extend_integer_width_to(32); + } + layout::Abi::Scalar(_) => { + if size.bytes() > 8 { + a.make_indirect(ccx); + } else { + a.extend_integer_width_to(32); + } } } }; diff --git a/src/librustc_trans/common.rs b/src/librustc_trans/common.rs index b80fded638d..bc6ddef0e72 100644 --- a/src/librustc_trans/common.rs +++ b/src/librustc_trans/common.rs @@ -41,7 +41,7 @@ use syntax_pos::{Span, DUMMY_SP}; pub use context::{CrateContext, SharedCrateContext}; pub fn type_is_fat_ptr<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, ty: Ty<'tcx>) -> bool { - if let Layout::FatPointer { .. } = *ccx.layout_of(ty) { + if let Layout::FatPointer { .. } = *ccx.layout_of(ty).layout { true } else { false @@ -51,9 +51,9 @@ pub fn type_is_fat_ptr<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, ty: Ty<'tcx>) -> pub fn type_is_immediate<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, ty: Ty<'tcx>) -> bool { let layout = ccx.layout_of(ty); match layout.abi { - layout::Abi::Scalar(_) | layout::Abi::Vector => true, + layout::Abi::Scalar(_) | layout::Abi::Vector { .. } => true, - layout::Abi::Aggregate => { + layout::Abi::Aggregate { .. } => { !layout.is_unsized() && layout.size(ccx).bytes() == 0 } } @@ -63,7 +63,7 @@ pub fn type_is_immediate<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, ty: Ty<'tcx>) - pub fn type_is_imm_pair<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, ty: Ty<'tcx>) -> bool { let layout = ccx.layout_of(ty); - match *layout { + match *layout.layout { Layout::FatPointer { .. } => true, Layout::Univariant(ref variant) => { // There must be only 2 fields. diff --git a/src/librustc_trans/debuginfo/metadata.rs b/src/librustc_trans/debuginfo/metadata.rs index 0e74d985570..6ab89f5c3eb 100644 --- a/src/librustc_trans/debuginfo/metadata.rs +++ b/src/librustc_trans/debuginfo/metadata.rs @@ -941,7 +941,7 @@ impl<'tcx> StructMemberDescriptionFactory<'tcx> { let layout = cx.layout_of(self.ty); let tmp; - let offsets = match *layout { + let offsets = match *layout.layout { layout::Univariant(ref variant) => &variant.offsets, layout::Vector { element, count } => { let element_size = element.size(cx).bytes(); @@ -1022,7 +1022,7 @@ impl<'tcx> TupleMemberDescriptionFactory<'tcx> { fn create_member_descriptions<'a>(&self, cx: &CrateContext<'a, 'tcx>) -> Vec<MemberDescription> { let layout = cx.layout_of(self.ty); - let offsets = if let layout::Univariant(ref variant) = *layout { + let offsets = if let layout::Univariant(ref variant) = *layout.layout { &variant.offsets } else { bug!("{} is not a tuple", self.ty); @@ -1339,7 +1339,7 @@ fn describe_enum_variant<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, span: Span) -> (DICompositeType, MemberDescriptionFactory<'tcx>) { let layout = cx.layout_of(enum_type); - let maybe_discr = match *layout { + let maybe_discr = match *layout.layout { layout::General { .. } => Some(layout.field(cx, 0).ty), _ => None, }; @@ -1491,7 +1491,7 @@ fn prepare_enum_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, let type_rep = cx.layout_of(enum_type); - let discriminant_type_metadata = match *type_rep { + let discriminant_type_metadata = match *type_rep.layout { layout::NullablePointer { .. } | layout::Univariant { .. } => None, layout::General { discr, .. } => Some(discriminant_type_metadata(discr)), ref l @ _ => bug!("Not an enum layout: {:#?}", l) diff --git a/src/librustc_trans/glue.rs b/src/librustc_trans/glue.rs index 61c0820539d..209083a8e25 100644 --- a/src/librustc_trans/glue.rs +++ b/src/librustc_trans/glue.rs @@ -58,7 +58,7 @@ pub fn size_and_align_of_dst<'a, 'tcx>(bcx: &Builder<'a, 'tcx>, t: Ty<'tcx>, inf let layout = ccx.layout_of(t); debug!("DST {} layout: {:?}", t, layout); - let (sized_size, sized_align) = match *layout { + let (sized_size, sized_align) = match *layout.layout { ty::layout::Layout::Univariant(ref variant) => { (variant.offsets.last().map_or(0, |o| o.bytes()), variant.align.abi()) } diff --git a/src/librustc_trans/mir/constant.rs b/src/librustc_trans/mir/constant.rs index 4f7c91efccd..c64333fc044 100644 --- a/src/librustc_trans/mir/constant.rs +++ b/src/librustc_trans/mir/constant.rs @@ -1090,7 +1090,7 @@ fn trans_const_adt<'a, 'tcx>( mir::AggregateKind::Adt(_, index, _, _) => index, _ => 0, }; - match *l { + match *l.layout { layout::General { ref variants, .. } => { let discr = match *kind { mir::AggregateKind::Adt(adt_def, _, _, _) => { diff --git a/src/librustc_trans/mir/lvalue.rs b/src/librustc_trans/mir/lvalue.rs index 325ccd4fde3..00c76bee1a8 100644 --- a/src/librustc_trans/mir/lvalue.rs +++ b/src/librustc_trans/mir/lvalue.rs @@ -208,10 +208,10 @@ impl<'a, 'tcx> LvalueRef<'tcx> { let field = l.field(ccx, ix); let offset = l.fields.offset(ix).bytes(); - let alignment = self.alignment | Alignment::from(&*l); + let alignment = self.alignment | Alignment::from(l.layout); // Unions and newtypes only use an offset of 0. - match *l { + match *l.layout { // FIXME(eddyb) The fields of a fat pointer aren't correct, especially // to unsized structs, we can't represent their pointee types in `Ty`. Layout::FatPointer { .. } => {} @@ -234,7 +234,7 @@ impl<'a, 'tcx> LvalueRef<'tcx> { } // Discriminant field of enums. - match *l { + match *l.layout { layout::NullablePointer { .. } if l.variant_index.is_none() => { let ty = ccx.llvm_type_of(field.ty); let size = field.size(ccx).bytes(); @@ -271,7 +271,7 @@ impl<'a, 'tcx> LvalueRef<'tcx> { }; // Check whether the variant being used is packed, if applicable. - let is_packed = match (&*l, l.variant_index) { + let is_packed = match (l.layout, l.variant_index) { (&layout::Univariant(ref variant), _) => variant.packed, (&layout::NullablePointer { ref variants, .. }, Some(v)) | (&layout::General { ref variants, .. }, Some(v)) => variants[v].packed, @@ -354,7 +354,7 @@ impl<'a, 'tcx> LvalueRef<'tcx> { let l = bcx.ccx.layout_of(self.ty.to_ty(bcx.tcx())); let cast_to = bcx.ccx.immediate_llvm_type_of(cast_to); - match *l { + match *l.layout { layout::Univariant { .. } | layout::UntaggedUnion { .. } => return C_uint(cast_to, 0), _ => {} @@ -366,7 +366,7 @@ impl<'a, 'tcx> LvalueRef<'tcx> { layout::Abi::Scalar(discr) => discr, _ => bug!("discriminant not scalar: {:#?}", discr_layout) }; - let (min, max) = match *l { + let (min, max) = match *l.layout { layout::General { ref discr_range, .. } => (discr_range.start, discr_range.end), _ => (0, u64::max_value()), }; @@ -392,7 +392,7 @@ impl<'a, 'tcx> LvalueRef<'tcx> { bcx.load(discr.llval, discr.alignment.non_abi()) } }; - match *l { + match *l.layout { layout::General { .. } => { let signed = match discr_scalar { layout::Int(_, signed) => signed, @@ -416,7 +416,7 @@ impl<'a, 'tcx> LvalueRef<'tcx> { let to = l.ty.ty_adt_def().unwrap() .discriminant_for_variant(bcx.tcx(), variant_index) .to_u128_unchecked() as u64; - match *l { + match *l.layout { layout::General { .. } => { let ptr = self.project_field(bcx, 0); bcx.store(C_int(bcx.ccx.llvm_type_of(ptr.ty.to_ty(bcx.tcx())), to as i64), @@ -471,7 +471,7 @@ impl<'a, 'tcx> LvalueRef<'tcx> { // If this is an enum, cast to the appropriate variant struct type. let layout = bcx.ccx.layout_of(ty).for_variant(variant_index); - match *layout { + match *layout.layout { layout::NullablePointer { ref variants, .. } | layout::General { ref variants, .. } => { let st = &variants[variant_index]; diff --git a/src/librustc_trans/mir/mod.rs b/src/librustc_trans/mir/mod.rs index b1a9be881f7..a71bcf47838 100644 --- a/src/librustc_trans/mir/mod.rs +++ b/src/librustc_trans/mir/mod.rs @@ -576,7 +576,7 @@ fn arg_local_refs<'a, 'tcx>(bcx: &Builder<'a, 'tcx>, }; let layout = bcx.ccx.layout_of(closure_ty); - let offsets = match *layout { + let offsets = match *layout.layout { layout::Univariant(ref variant) => &variant.offsets[..], _ => bug!("Closures are only supposed to be Univariant") }; diff --git a/src/librustc_trans/mir/rvalue.rs b/src/librustc_trans/mir/rvalue.rs index b7143f23691..518f36a77b5 100644 --- a/src/librustc_trans/mir/rvalue.rs +++ b/src/librustc_trans/mir/rvalue.rs @@ -277,7 +277,7 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> { let llval = operand.immediate(); let l = bcx.ccx.layout_of(operand.ty); - if let Layout::General { ref discr_range, .. } = *l { + if let Layout::General { ref discr_range, .. } = *l.layout { if discr_range.end > discr_range.start { // We want `table[e as usize]` to not // have bound checks, and this is the most diff --git a/src/librustc_trans/type_of.rs b/src/librustc_trans/type_of.rs index eb52d58098d..b829d33600c 100644 --- a/src/librustc_trans/type_of.rs +++ b/src/librustc_trans/type_of.rs @@ -240,7 +240,7 @@ impl<'tcx> LayoutLlvmExt for FullLayout<'tcx> { if let layout::Abi::Scalar(_) = self.abi { bug!("FullLayout::llvm_field_index({:?}): not applicable", self); } - match **self { + match *self.layout { Layout::Scalar { .. } | Layout::UntaggedUnion { .. } => { bug!("FullLayout::llvm_field_index({:?}): not applicable", self) |
