Skip to content

Commit

Permalink
Make type_is_immediate not depend on LLVM.
Browse files Browse the repository at this point in the history
This has the nice benefit of making it much simpler to work with,
since it now consists of a single match statement.
  • Loading branch information
Mark-Simulacrum committed Jan 11, 2017
1 parent 0500fbf commit 7461038
Showing 1 changed file with 16 additions and 17 deletions.
33 changes: 16 additions & 17 deletions src/librustc_trans/common.rs
Expand Up @@ -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)
}
}

Expand Down

0 comments on commit 7461038

Please sign in to comment.