]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc_codegen_llvm/type_of.rs
Various minor/cosmetic improvements to code
[rust.git] / src / librustc_codegen_llvm / type_of.rs
index 90c02cddb2b6058c42f0d6dd2d0d3a7f4ec3dec0..52b560c6625405f3dab9d3af5af57a659f3adea2 100644 (file)
@@ -15,8 +15,8 @@
 use rustc::ty::layout::{self, Align, LayoutOf, Size, TyLayout};
 use rustc_target::abi::FloatTy;
 use rustc_mir::monomorphize::item::DefPathBasedNames;
-use type_::Type;
 use rustc_codegen_ssa::traits::*;
+use type_::Type;
 
 use std::fmt::Write;
 
@@ -80,14 +80,14 @@ fn uncached_llvm_type<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
 
     match layout.fields {
         layout::FieldPlacement::Union(_) => {
-            let fill = cx.type_padding_filler( layout.size, layout.align);
+            let fill = cx.type_padding_filler(layout.size, layout.align.abi);
             let packed = false;
             match name {
                 None => {
-                    cx.type_struct( &[fill], packed)
+                    cx.type_struct(&[fill], packed)
                 }
                 Some(ref name) => {
-                    let llty = cx.type_named_struct( name);
+                    let llty = cx.type_named_struct(name);
                     cx.set_struct_body(llty, &[fill], packed);
                     llty
                 }
@@ -120,23 +120,23 @@ fn struct_llfields<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
 
     let mut packed = false;
     let mut offset = Size::ZERO;
-    let mut prev_effective_align = layout.align;
+    let mut prev_effective_align = layout.align.abi;
     let mut result: Vec<_> = Vec::with_capacity(1 + field_count * 2);
     for i in layout.fields.index_by_increasing_offset() {
         let target_offset = layout.fields.offset(i as usize);
         let field = layout.field(cx, i);
-        let effective_field_align = layout.align
-            .min(field.align)
+        let effective_field_align = layout.align.abi
+            .min(field.align.abi)
             .restrict_for_offset(target_offset);
-        packed |= effective_field_align.abi() < field.align.abi();
+        packed |= effective_field_align < field.align.abi;
 
         debug!("struct_llfields: {}: {:?} offset: {:?} target_offset: {:?} \
                 effective_field_align: {}",
-               i, field, offset, target_offset, effective_field_align.abi());
+               i, field, offset, target_offset, effective_field_align.bytes());
         assert!(target_offset >= offset);
         let padding = target_offset - offset;
         let padding_align = prev_effective_align.min(effective_field_align);
-        assert_eq!(offset.abi_align(padding_align) + padding, target_offset);
+        assert_eq!(offset.align_to(padding_align) + padding, target_offset);
         result.push(cx.type_padding_filler( padding, padding_align));
         debug!("    padding before: {:?}", padding);
 
@@ -151,7 +151,7 @@ fn struct_llfields<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
         }
         let padding = layout.size - offset;
         let padding_align = prev_effective_align;
-        assert_eq!(offset.abi_align(padding_align) + padding, layout.size);
+        assert_eq!(offset.align_to(padding_align) + padding, layout.size);
         debug!("struct_llfields: pad_bytes: {:?} offset: {:?} stride: {:?}",
                padding, offset, layout.size);
         result.push(cx.type_padding_filler(padding, padding_align));
@@ -166,7 +166,7 @@ fn struct_llfields<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
 
 impl<'a, 'tcx> CodegenCx<'a, 'tcx> {
     pub fn align_of(&self, ty: Ty<'tcx>) -> Align {
-        self.layout_of(ty).align
+        self.layout_of(ty).align.abi
     }
 
     pub fn size_of(&self, ty: Ty<'tcx>) -> Size {
@@ -174,7 +174,8 @@ pub fn size_of(&self, ty: Ty<'tcx>) -> Size {
     }
 
     pub fn size_and_align_of(&self, ty: Ty<'tcx>) -> (Size, Align) {
-        self.layout_of(ty).size_and_align()
+        let layout = self.layout_of(ty);
+        (layout.size, layout.align.abi)
     }
 }
 
@@ -235,7 +236,7 @@ fn is_llvm_scalar_pair<'a>(&self) -> bool {
         }
     }
 
-    /// Get the LLVM type corresponding to a Rust type, i.e. `rustc::ty::Ty`.
+    /// Get the LLVM type corresponding to a Rust type, i.e., `rustc::ty::Ty`.
     /// The pointee type of the pointer in `PlaceRef` is always this type.
     /// For sized types, it is also the right LLVM type for an `alloca`
     /// containing a value of that type, and most immediates (except `bool`).
@@ -332,7 +333,7 @@ fn scalar_llvm_type_at<'a>(&self, cx: &CodegenCx<'a, 'tcx>,
             layout::Pointer => {
                 // If we know the alignment, pick something better than i8.
                 let pointee = if let Some(pointee) = self.pointee_info_at(cx, offset) {
-                    cx.type_pointee_for_abi_align( pointee.align)
+                    cx.type_pointee_for_align(pointee.align)
                 } else {
                     cx.type_i8()
                 };
@@ -376,7 +377,7 @@ fn scalar_pair_element_llvm_type<'a>(&self, cx: &CodegenCx<'a, 'tcx>,
         let offset = if index == 0 {
             Size::ZERO
         } else {
-            a.value.size(cx).abi_align(b.value.align(cx))
+            a.value.size(cx).align_to(b.value.align(cx).abi)
         };
         self.scalar_llvm_type_at(cx, scalar, offset)
     }
@@ -469,9 +470,9 @@ fn pointee_info_at<'a>(&self, cx: &CodegenCx<'a, 'tcx>, offset: Size)
                         // (according to its type), or null (which the
                         // niche field's scalar validity range encodes).
                         // This allows using `dereferenceable_or_null`
-                        // for e.g. `Option<&T>`, and this will continue
+                        // for e.g., `Option<&T>`, and this will continue
                         // to work as long as we don't start using more
-                        // niches than just null (e.g. the first page
+                        // niches than just null (e.g., the first page
                         // of the address space, or unaligned pointers).
                         if self.fields.offset(0) == offset {
                             Some(self.for_variant(cx, dataful_variant))