]> git.lizzy.rs Git - rust.git/commitdiff
Make type_is_immediate not depend on LLVM.
authorMark Simulacrum <mark.simulacrum@gmail.com>
Thu, 5 Jan 2017 18:31:47 +0000 (11:31 -0700)
committerMark Simulacrum <mark.simulacrum@gmail.com>
Wed, 11 Jan 2017 02:42:37 +0000 (19:42 -0700)
This has the nice benefit of making it much simpler to work with,
since it now consists of a single match statement.

src/librustc_trans/common.rs

index eb6ea8fa94b0ab06a2736c730f662db936865cb5..b72c1e553730d9644c81b700b38366c6f1c1f656 100644 (file)
@@ -58,24 +58,23 @@ 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 {
-    use machine::llsize_of_alloc;
-    use type_of::sizing_type_of;
-
-    let simple = ty.is_scalar() ||
-        ty.is_unique() || ty.is_region_ptr() ||
-        ty.is_simd();
-    if simple && !type_is_fat_ptr(ccx, ty) {
-        return true;
-    }
-    if !ccx.shared().type_is_sized(ty) {
-        return false;
-    }
-    match ty.sty {
-        ty::TyAdt(..) | ty::TyTuple(..) | ty::TyArray(..) | ty::TyClosure(..) => {
-            let llty = sizing_type_of(ccx, ty);
-            llsize_of_alloc(ccx, llty) <= llsize_of_alloc(ccx, ccx.int_type())
+    let layout = ccx.layout_of(ty);
+    match *layout {
+        Layout::CEnum { .. } |
+        Layout::Scalar { .. } |
+        Layout::Vector { .. } => true,
+
+        Layout::FatPointer { .. } => false,
+
+        Layout::Array { .. } |
+        Layout::Univariant { .. } |
+        Layout::General { .. } |
+        Layout::UntaggedUnion { .. } |
+        Layout::RawNullablePointer { .. } |
+        Layout::StructWrappedNullablePointer { .. } => {
+            let dl = &ccx.tcx().data_layout;
+            !layout.is_unsized() && layout.size(dl) <= dl.pointer_size
         }
-        _ => type_is_zero_size(ccx, ty)
     }
 }