mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-29 10:13:54 +00:00
rustc: move layout::Struct into FieldPlacement/Abi.
This commit is contained in:
parent
08f9f134fd
commit
18d54aa7d5
@ -41,7 +41,7 @@ use ty::{PolyFnSig, InferTy, ParamTy, ProjectionTy, ExistentialPredicate, Predic
|
||||
use ty::RegionKind;
|
||||
use ty::{TyVar, TyVid, IntVar, IntVid, FloatVar, FloatVid};
|
||||
use ty::TypeVariants::*;
|
||||
use ty::layout::{Layout, TargetDataLayout};
|
||||
use ty::layout::{CachedLayout, TargetDataLayout};
|
||||
use ty::maps;
|
||||
use ty::steal::Steal;
|
||||
use ty::BindingMode;
|
||||
@ -78,7 +78,7 @@ use hir;
|
||||
/// Internal storage
|
||||
pub struct GlobalArenas<'tcx> {
|
||||
// internings
|
||||
layout: TypedArena<Layout<'tcx>>,
|
||||
layout: TypedArena<CachedLayout>,
|
||||
|
||||
// references
|
||||
generics: TypedArena<ty::Generics>,
|
||||
@ -918,7 +918,7 @@ pub struct GlobalCtxt<'tcx> {
|
||||
|
||||
stability_interner: RefCell<FxHashSet<&'tcx attr::Stability>>,
|
||||
|
||||
layout_interner: RefCell<FxHashSet<&'tcx Layout<'tcx>>>,
|
||||
layout_interner: RefCell<FxHashSet<&'tcx CachedLayout>>,
|
||||
|
||||
/// A vector of every trait accessible in the whole crate
|
||||
/// (i.e. including those from subcrates). This is used only for
|
||||
@ -1016,7 +1016,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
||||
interned
|
||||
}
|
||||
|
||||
pub fn intern_layout(self, layout: Layout<'gcx>) -> &'gcx Layout<'gcx> {
|
||||
pub fn intern_layout(self, layout: CachedLayout) -> &'gcx CachedLayout {
|
||||
if let Some(layout) = self.layout_interner.borrow().get(&layout) {
|
||||
return layout;
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -264,7 +264,7 @@ define_maps! { <'tcx>
|
||||
[] fn is_freeze_raw: is_freeze_dep_node(ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool,
|
||||
[] fn needs_drop_raw: needs_drop_dep_node(ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool,
|
||||
[] fn layout_raw: layout_dep_node(ty::ParamEnvAnd<'tcx, Ty<'tcx>>)
|
||||
-> Result<ty::layout::CachedLayout<'tcx>,
|
||||
-> Result<&'tcx ty::layout::CachedLayout,
|
||||
ty::layout::LayoutError<'tcx>>,
|
||||
|
||||
[] fn dylib_dependency_formats: DylibDepFormats(CrateNum)
|
||||
|
@ -316,7 +316,7 @@ impl<'tcx> LayoutExt<'tcx> for FullLayout<'tcx> {
|
||||
let mut total = Size::from_bytes(0);
|
||||
let mut result = None;
|
||||
|
||||
let is_union = match self.fields {
|
||||
let is_union = match *self.fields {
|
||||
layout::FieldPlacement::Linear { stride, .. } => {
|
||||
stride.bytes() == 0
|
||||
}
|
||||
|
@ -72,7 +72,7 @@ pub fn finish_type_of<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
|
||||
return;
|
||||
}
|
||||
match *l.layout {
|
||||
layout::Univariant(_) => {
|
||||
layout::Univariant => {
|
||||
let is_enum = if let ty::TyAdt(def, _) = t.sty {
|
||||
def.is_enum()
|
||||
} else {
|
||||
@ -100,7 +100,7 @@ fn generic_type_of<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
|
||||
return cx.llvm_type_of(value.to_ty(cx.tcx()));
|
||||
}
|
||||
match *l.layout {
|
||||
layout::Univariant(_) => {
|
||||
layout::Univariant => {
|
||||
match name {
|
||||
None => {
|
||||
Type::struct_(cx, &struct_llfields(cx, l), l.is_packed())
|
||||
@ -152,11 +152,7 @@ pub fn struct_llfields<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
|
||||
|
||||
let mut offset = Size::from_bytes(0);
|
||||
let mut result: Vec<Type> = Vec::with_capacity(1 + field_count * 2);
|
||||
let field_index_by_increasing_offset = match *layout.layout {
|
||||
layout::Univariant(ref variant) => variant.field_index_by_increasing_offset(),
|
||||
_ => bug!("unexpected {:#?}", layout)
|
||||
};
|
||||
for i in field_index_by_increasing_offset {
|
||||
for i in layout.fields.index_by_increasing_offset() {
|
||||
let field = layout.field(cx, i);
|
||||
let target_offset = layout.fields.offset(i as usize);
|
||||
debug!("struct_llfields: {}: {:?} offset: {:?} target_offset: {:?}",
|
||||
|
@ -64,8 +64,8 @@ pub fn type_is_imm_pair<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, ty: Ty<'tcx>)
|
||||
-> bool {
|
||||
let layout = ccx.layout_of(ty);
|
||||
match *layout.layout {
|
||||
Layout::FatPointer { .. } => true,
|
||||
Layout::Univariant(_) => {
|
||||
Layout::FatPointer => true,
|
||||
Layout::Univariant => {
|
||||
// There must be only 2 fields.
|
||||
if layout.fields.count() != 2 {
|
||||
return false;
|
||||
|
@ -1159,7 +1159,7 @@ impl<'tcx> EnumMemberDescriptionFactory<'tcx> {
|
||||
}
|
||||
}).collect()
|
||||
},
|
||||
layout::Univariant(_) => {
|
||||
layout::Univariant => {
|
||||
assert!(adt.variants.len() <= 1);
|
||||
|
||||
if adt.variants.is_empty() {
|
||||
@ -1194,7 +1194,6 @@ impl<'tcx> EnumMemberDescriptionFactory<'tcx> {
|
||||
layout::NullablePointer {
|
||||
nndiscr,
|
||||
discr,
|
||||
discr_offset,
|
||||
..
|
||||
} => {
|
||||
let variant = self.type_rep.for_variant(nndiscr as usize);
|
||||
@ -1239,7 +1238,7 @@ impl<'tcx> EnumMemberDescriptionFactory<'tcx> {
|
||||
}
|
||||
compute_field_path(cx, &mut name,
|
||||
self.type_rep,
|
||||
discr_offset,
|
||||
self.type_rep.fields.offset(0),
|
||||
discr.size(cx));
|
||||
name.push_str(&adt.variants[(1 - nndiscr) as usize].name.as_str());
|
||||
|
||||
|
@ -1117,11 +1117,11 @@ fn trans_const_adt<'a, 'tcx>(
|
||||
|
||||
Const::new(C_struct(ccx, &contents, l.is_packed()), t)
|
||||
}
|
||||
layout::Univariant(_) => {
|
||||
layout::Univariant => {
|
||||
assert_eq!(variant_index, 0);
|
||||
build_const_struct(ccx, l, vals, None)
|
||||
}
|
||||
layout::Vector { .. } => {
|
||||
layout::Vector => {
|
||||
Const::new(C_vector(&vals.iter().map(|x| x.llval).collect::<Vec<_>>()), t)
|
||||
}
|
||||
layout::NullablePointer { nndiscr, .. } => {
|
||||
@ -1162,11 +1162,7 @@ fn build_const_struct<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
|
||||
offset = ccx.size_of(discr.ty);
|
||||
}
|
||||
|
||||
let field_index_by_increasing_offset = match *layout.layout {
|
||||
layout::Univariant(ref variant) => variant.field_index_by_increasing_offset(),
|
||||
_ => bug!("unexpected {:#?}", layout)
|
||||
};
|
||||
let parts = field_index_by_increasing_offset.map(|i| {
|
||||
let parts = layout.fields.index_by_increasing_offset().map(|i| {
|
||||
(vals[i], layout.fields.offset(i))
|
||||
});
|
||||
for (val, target_offset) in parts {
|
||||
|
@ -240,25 +240,18 @@ impl<'tcx> LayoutLlvmExt for FullLayout<'tcx> {
|
||||
if let layout::Abi::Scalar(_) = self.abi {
|
||||
bug!("FullLayout::llvm_field_index({:?}): not applicable", self);
|
||||
}
|
||||
let index = self.fields.memory_index(index);
|
||||
match *self.layout {
|
||||
Layout::Scalar { .. } |
|
||||
Layout::UntaggedUnion { .. } |
|
||||
Layout::NullablePointer { .. } |
|
||||
Layout::General { .. } => {
|
||||
bug!("FullLayout::llvm_field_index({:?}): not applicable", self)
|
||||
}
|
||||
|
||||
Layout::Vector { .. } |
|
||||
Layout::Array { .. } => {
|
||||
Layout::Vector | Layout::Array => {
|
||||
index as u64
|
||||
}
|
||||
|
||||
Layout::FatPointer { .. } => {
|
||||
Layout::FatPointer | Layout::Univariant => {
|
||||
adt::memory_index_to_gep(index as u64)
|
||||
}
|
||||
|
||||
Layout::Univariant(ref variant) => {
|
||||
adt::memory_index_to_gep(variant.memory_index[index] as u64)
|
||||
_ => {
|
||||
bug!("FullLayout::llvm_field_index({:?}): not applicable", self)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user