Skip to content

Commit 7461038

Browse files
Make type_is_immediate not depend on LLVM.
This has the nice benefit of making it much simpler to work with, since it now consists of a single match statement.
1 parent 0500fbf commit 7461038

File tree

1 file changed

+16
-17
lines changed

1 file changed

+16
-17
lines changed

src/librustc_trans/common.rs

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -58,24 +58,23 @@ pub fn type_is_fat_ptr<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, ty: Ty<'tcx>) ->
5858
}
5959

6060
pub fn type_is_immediate<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, ty: Ty<'tcx>) -> bool {
61-
use machine::llsize_of_alloc;
62-
use type_of::sizing_type_of;
63-
64-
let simple = ty.is_scalar() ||
65-
ty.is_unique() || ty.is_region_ptr() ||
66-
ty.is_simd();
67-
if simple && !type_is_fat_ptr(ccx, ty) {
68-
return true;
69-
}
70-
if !ccx.shared().type_is_sized(ty) {
71-
return false;
72-
}
73-
match ty.sty {
74-
ty::TyAdt(..) | ty::TyTuple(..) | ty::TyArray(..) | ty::TyClosure(..) => {
75-
let llty = sizing_type_of(ccx, ty);
76-
llsize_of_alloc(ccx, llty) <= llsize_of_alloc(ccx, ccx.int_type())
61+
let layout = ccx.layout_of(ty);
62+
match *layout {
63+
Layout::CEnum { .. } |
64+
Layout::Scalar { .. } |
65+
Layout::Vector { .. } => true,
66+
67+
Layout::FatPointer { .. } => false,
68+
69+
Layout::Array { .. } |
70+
Layout::Univariant { .. } |
71+
Layout::General { .. } |
72+
Layout::UntaggedUnion { .. } |
73+
Layout::RawNullablePointer { .. } |
74+
Layout::StructWrappedNullablePointer { .. } => {
75+
let dl = &ccx.tcx().data_layout;
76+
!layout.is_unsized() && layout.size(dl) <= dl.pointer_size
7777
}
78-
_ => type_is_zero_size(ccx, ty)
7978
}
8079
}
8180

0 commit comments

Comments
 (0)