Incorporate review comments.
This commit is contained in:
parent
f2f7ace213
commit
467454b0d2
@ -489,7 +489,7 @@ pub struct GlobalCtxt<'tcx> {
|
||||
/// Cache for layouts computed from types.
|
||||
pub layout_cache: RefCell<FnvHashMap<Ty<'tcx>, &'tcx Layout>>,
|
||||
|
||||
//Used to prevent layout from recursing too deeply.
|
||||
/// Used to prevent layout from recursing too deeply.
|
||||
pub layout_depth: Cell<usize>,
|
||||
|
||||
/// Map from function to the `#[derive]` mode that it's defining. Only used
|
||||
|
@ -328,7 +328,6 @@ pub enum Integer {
|
||||
}
|
||||
|
||||
impl Integer {
|
||||
|
||||
pub fn size(&self) -> Size {
|
||||
match *self {
|
||||
I1 => Size::from_bits(1),
|
||||
@ -350,7 +349,7 @@ impl Integer {
|
||||
}
|
||||
|
||||
pub fn to_ty<'a, 'tcx>(&self, tcx: &ty::TyCtxt<'a, 'tcx, 'tcx>,
|
||||
signed: bool) -> Ty<'tcx> {
|
||||
signed: bool) -> Ty<'tcx> {
|
||||
match (*self, signed) {
|
||||
(I1, false) => tcx.types.u8,
|
||||
(I8, false) => tcx.types.u8,
|
||||
@ -387,7 +386,7 @@ impl Integer {
|
||||
}
|
||||
}
|
||||
|
||||
//Find the smallest integer with the given alignment.
|
||||
/// Find the smallest integer with the given alignment.
|
||||
pub fn for_abi_align(dl: &TargetDataLayout, align: Align) -> Option<Integer> {
|
||||
let wanted = align.abi();
|
||||
for &candidate in &[I8, I16, I32, I64] {
|
||||
@ -1030,7 +1029,7 @@ impl<'a, 'gcx, 'tcx> Layout {
|
||||
});
|
||||
}
|
||||
|
||||
if def.variants.len() == 1 {
|
||||
if !def.is_enum() || def.variants.len() == 1 && hint == attr::ReprAny {
|
||||
// Struct, or union, or univariant enum equivalent to a struct.
|
||||
// (Typechecking will reject discriminant-sizing attrs.)
|
||||
|
||||
@ -1061,16 +1060,6 @@ impl<'a, 'gcx, 'tcx> Layout {
|
||||
}
|
||||
}
|
||||
|
||||
if def.variants.len() == 1 && hint == attr::ReprAny{
|
||||
// Equivalent to a struct/tuple/newtype.
|
||||
let fields = def.variants[0].fields.iter().map(|field| {
|
||||
field.ty(tcx, substs).layout(infcx)
|
||||
});
|
||||
let mut st = Struct::new(dl, false);
|
||||
st.extend(dl, fields, ty)?;
|
||||
return success(Univariant { variant: st, non_zero: false });
|
||||
}
|
||||
|
||||
// Cache the substituted and normalized variant field types.
|
||||
let variants = def.variants.iter().map(|v| {
|
||||
v.fields.iter().map(|field| field.ty(tcx, substs)).collect::<Vec<_>>()
|
||||
|
@ -94,10 +94,10 @@ impl MaybeSizedValue {
|
||||
}
|
||||
}
|
||||
|
||||
//Given an enum, struct, closure, or tuple, extracts fields.
|
||||
//treats closures as a struct with one variant.
|
||||
//`empty_if_no_variants` is a switch to deal with empty enums.
|
||||
//if true, `variant_index` is disregarded and an empty Vec returned in this case.
|
||||
/// Given an enum, struct, closure, or tuple, extracts fields.
|
||||
/// Treats closures as a struct with one variant.
|
||||
/// `empty_if_no_variants` is a switch to deal with empty enums.
|
||||
/// If true, `variant_index` is disregarded and an empty Vec returned in this case.
|
||||
fn compute_fields<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, t: Ty<'tcx>,
|
||||
variant_index: usize,
|
||||
empty_if_no_variants: bool) -> Vec<Ty<'tcx>> {
|
||||
@ -156,11 +156,9 @@ pub fn finish_type_of<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
|
||||
layout::CEnum { .. } | layout::General { .. }
|
||||
| layout::UntaggedUnion { .. } | layout::RawNullablePointer { .. } => { }
|
||||
layout::Univariant { ..}
|
||||
| layout::StructWrappedNullablePointer { .. }
|
||||
| layout::Vector { .. } => {
|
||||
| layout::StructWrappedNullablePointer { .. } => {
|
||||
let (nonnull_variant, packed) = match *l {
|
||||
layout::Univariant { ref variant, .. } => (0, variant.packed),
|
||||
layout::Vector { .. } => (0, true),
|
||||
layout::StructWrappedNullablePointer { nndiscr, ref nonnull, .. } =>
|
||||
(nndiscr, nonnull.packed),
|
||||
_ => unreachable!()
|
||||
@ -206,8 +204,8 @@ fn generic_type_of<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
|
||||
}
|
||||
}
|
||||
layout::Univariant { ref variant, .. } => {
|
||||
//note that this case also handles empty enums.
|
||||
//Thus the true as the final parameter here.
|
||||
// Note that this case also handles empty enums.
|
||||
// Thus the true as the final parameter here.
|
||||
let fields = compute_fields(cx, t, 0, true);
|
||||
match name {
|
||||
None => {
|
||||
@ -425,7 +423,7 @@ pub fn trans_case<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, t: Ty<'tcx>, value: Disr)
|
||||
C_integral(Type::from_integer(bcx.ccx(), discr), value.0, true)
|
||||
}
|
||||
layout::RawNullablePointer { .. } |
|
||||
layout::StructWrappedNullablePointer { .. } => {
|
||||
layout::StructWrappedNullablePointer { .. } => {
|
||||
assert!(value == Disr(0) || value == Disr(1));
|
||||
C_bool(bcx.ccx(), value != Disr(0))
|
||||
}
|
||||
@ -774,10 +772,8 @@ fn build_const_struct<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
|
||||
// offset of current value
|
||||
let mut offset = 0;
|
||||
let mut cfields = Vec::new();
|
||||
for (&val, target_offset) in
|
||||
vals.iter().zip(
|
||||
offset_after_field.iter().map(|i| i.bytes())
|
||||
) {
|
||||
let target_offsets = offset_after_field.iter().map(|i| i.bytes());
|
||||
for (&val, target_offset) in vals.iter().zip(target_offsets) {
|
||||
assert!(!is_undef(val));
|
||||
cfields.push(val);
|
||||
offset += machine::llsize_of_alloc(ccx, val_ty(val));
|
||||
|
@ -1293,7 +1293,7 @@ impl<'tcx> EnumMemberDescriptionFactory<'tcx> {
|
||||
let adt = &self.enum_type.ty_adt_def().unwrap();
|
||||
let substs = match self.enum_type.sty {
|
||||
ty::TyAdt(def, ref s) if def.adt_kind() == AdtKind::Enum => s,
|
||||
ref t @ _ => bug!("{} is not an enum", t)
|
||||
_ => bug!("{} is not an enum", self.enum_type)
|
||||
};
|
||||
match *self.type_rep {
|
||||
layout::General { ref variants, .. } => {
|
||||
|
@ -733,7 +733,7 @@ impl<'a, 'tcx> MirConstContext<'a, 'tcx> {
|
||||
|
||||
let base = match tr_lvalue.base {
|
||||
Base::Value(llval) => {
|
||||
//Fixme: may be wrong for &*(&simd_vec as &fmt::Debug)
|
||||
// FIXME: may be wrong for &*(&simd_vec as &fmt::Debug)
|
||||
let align = if type_is_sized(self.ccx.tcx(), ty) {
|
||||
type_of::align_of(self.ccx, ty)
|
||||
} else {
|
||||
|
@ -301,7 +301,7 @@ impl Type {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn from_integer(cx: &CrateContext, i: layout::Integer)->Type {
|
||||
pub fn from_integer(cx: &CrateContext, i: layout::Integer) -> Type {
|
||||
use rustc::ty::layout::Integer::*;
|
||||
match i {
|
||||
I1 => Type::i1(cx),
|
||||
@ -312,7 +312,7 @@ impl Type {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn from_primitive(ccx: &CrateContext, p: layout::Primitive)->Type {
|
||||
pub fn from_primitive(ccx: &CrateContext, p: layout::Primitive) -> Type {
|
||||
match p {
|
||||
layout::Int(i) => Type::from_integer(ccx, i),
|
||||
layout::F32 => Type::f32(ccx),
|
||||
|
Loading…
x
Reference in New Issue
Block a user