Skip to content

Commit 9a0efea

Browse files
committed
rustc: pre-compute field placements out of Layout.
1 parent 8c4d5af commit 9a0efea

File tree

11 files changed

+228
-141
lines changed

11 files changed

+228
-141
lines changed

src/librustc/ty/layout.rs

Lines changed: 210 additions & 124 deletions
Large diffs are not rendered by default.

src/librustc/ty/maps/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ use session::config::OutputFilenames;
3434
use traits::Vtable;
3535
use traits::specialization_graph;
3636
use ty::{self, CrateInherentImpls, Ty, TyCtxt};
37-
use ty::layout::{Layout, LayoutError};
3837
use ty::steal::Steal;
3938
use ty::subst::Substs;
4039
use util::nodemap::{DefIdSet, DefIdMap, ItemLocalSet};
@@ -265,7 +264,8 @@ define_maps! { <'tcx>
265264
[] fn is_freeze_raw: is_freeze_dep_node(ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool,
266265
[] fn needs_drop_raw: needs_drop_dep_node(ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool,
267266
[] fn layout_raw: layout_dep_node(ty::ParamEnvAnd<'tcx, Ty<'tcx>>)
268-
-> Result<&'tcx Layout, LayoutError<'tcx>>,
267+
-> Result<ty::layout::CachedLayout<'tcx>,
268+
ty::layout::LayoutError<'tcx>>,
269269

270270
[] fn dylib_dependency_formats: DylibDepFormats(CrateNum)
271271
-> Rc<Vec<(CrateNum, LinkagePreference)>>,

src/librustc_const_eval/eval.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use rustc::hir::map::blocks::FnLikeNode;
1717
use rustc::hir::def::{Def, CtorKind};
1818
use rustc::hir::def_id::DefId;
1919
use rustc::ty::{self, Ty, TyCtxt};
20+
use rustc::ty::layout::LayoutOf;
2021
use rustc::ty::maps::Providers;
2122
use rustc::ty::util::IntTypeExt;
2223
use rustc::ty::subst::{Substs, Subst};
@@ -313,7 +314,7 @@ fn eval_const_expr_partial<'a, 'tcx>(cx: &ConstContext<'a, 'tcx>,
313314
if tcx.fn_sig(def_id).abi() == Abi::RustIntrinsic {
314315
let layout_of = |ty: Ty<'tcx>| {
315316
let ty = tcx.erase_regions(&ty);
316-
tcx.at(e.span).layout_raw(cx.param_env.reveal_all().and(ty)).map_err(|err| {
317+
(tcx.at(e.span), cx.param_env).layout_of(ty).map_err(|err| {
317318
ConstEvalErr { span: e.span, kind: LayoutError(err) }
318319
})
319320
};

src/librustc_trans/abi.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ impl<'tcx> LayoutExt<'tcx> for FullLayout<'tcx> {
334334
let mut unaligned_offset = Size::from_bytes(0);
335335
let mut result = None;
336336

337-
for i in 0..self.field_count() {
337+
for i in 0..self.fields.count() {
338338
if unaligned_offset != variant.offsets[i] {
339339
return None;
340340
}
@@ -371,7 +371,7 @@ impl<'tcx> LayoutExt<'tcx> for FullLayout<'tcx> {
371371
let mut max = Size::from_bytes(0);
372372
let mut result = None;
373373

374-
for i in 0..self.field_count() {
374+
for i in 0..self.fields.count() {
375375
let field = self.field(ccx, i);
376376
match (result, field.homogeneous_aggregate(ccx)) {
377377
// The field itself must be a homogeneous aggregate.

src/librustc_trans/adt.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ pub fn memory_index_to_gep(index: u64) -> u64 {
209209
pub fn struct_llfields<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
210210
layout: FullLayout<'tcx>,
211211
variant: &layout::Struct) -> Vec<Type> {
212-
let field_count = layout.field_count();
212+
let field_count = layout.fields.count();
213213
debug!("struct_llfields: variant: {:?}", variant);
214214
let mut offset = Size::from_bytes(0);
215215
let mut result: Vec<Type> = Vec::with_capacity(1 + field_count * 2);

src/librustc_trans/cabi_s390x.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ fn is_single_fp_element<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
3030
Layout::Scalar { value: layout::F32, .. } |
3131
Layout::Scalar { value: layout::F64, .. } => true,
3232
Layout::Univariant { .. } => {
33-
if layout.field_count() == 1 {
33+
if layout.fields.count() == 1 {
3434
is_single_fp_element(ccx, layout.field(ccx, 0))
3535
} else {
3636
false

src/librustc_trans/cabi_x86.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ fn is_single_fp_element<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
2525
Layout::Scalar { value: layout::F32, .. } |
2626
Layout::Scalar { value: layout::F64, .. } => true,
2727
Layout::Univariant { .. } => {
28-
if layout.field_count() == 1 {
28+
if layout.fields.count() == 1 {
2929
is_single_fp_element(ccx, layout.field(ccx, 0))
3030
} else {
3131
false

src/librustc_trans/cabi_x86_64.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,14 +102,14 @@ fn classify_arg<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, arg: &ArgType<'tcx>)
102102
}
103103

104104
Layout::Univariant(ref variant) => {
105-
for i in 0..layout.field_count() {
105+
for i in 0..layout.fields.count() {
106106
let field_off = off + variant.offsets[i];
107107
classify(ccx, layout.field(ccx, i), cls, field_off)?;
108108
}
109109
}
110110

111111
Layout::UntaggedUnion { .. } => {
112-
for i in 0..layout.field_count() {
112+
for i in 0..layout.fields.count() {
113113
classify(ccx, layout.field(ccx, i), cls, off)?;
114114
}
115115
}

src/librustc_trans/debuginfo/metadata.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -429,15 +429,15 @@ fn trait_pointer_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
429429
type_metadata: type_metadata(cx,
430430
cx.tcx().mk_mut_ptr(cx.tcx().types.u8),
431431
syntax_pos::DUMMY_SP),
432-
offset: layout.field_offset(cx, 0),
432+
offset: layout.fields.offset(0),
433433
size: data_ptr_field.size(cx),
434434
align: data_ptr_field.align(cx),
435435
flags: DIFlags::FlagArtificial,
436436
},
437437
MemberDescription {
438438
name: "vtable".to_string(),
439439
type_metadata: type_metadata(cx, vtable_field.ty, syntax_pos::DUMMY_SP),
440-
offset: layout.field_offset(cx, 1),
440+
offset: layout.fields.offset(1),
441441
size: vtable_field.size(cx),
442442
align: vtable_field.align(cx),
443443
flags: DIFlags::FlagArtificial,
@@ -1321,8 +1321,8 @@ impl<'tcx> EnumMemberDescriptionFactory<'tcx> {
13211321
layout: FullLayout<'tcx>,
13221322
offset: Size,
13231323
size: Size) {
1324-
for i in 0..layout.field_count() {
1325-
let field_offset = layout.field_offset(ccx, i);
1324+
for i in 0..layout.fields.count() {
1325+
let field_offset = layout.fields.offset(i);
13261326
if field_offset > offset {
13271327
continue;
13281328
}
@@ -1414,7 +1414,7 @@ fn describe_enum_variant<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
14141414
};
14151415

14161416
let layout = layout.for_variant(variant_index);
1417-
let mut field_tys = (0..layout.field_count()).map(|i| {
1417+
let mut field_tys = (0..layout.fields.count()).map(|i| {
14181418
layout.field(cx, i).ty
14191419
}).collect::<Vec<_>>();
14201420

src/librustc_trans/glue.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ pub fn size_and_align_of_dst<'a, 'tcx>(bcx: &Builder<'a, 'tcx>, t: Ty<'tcx>, inf
7474

7575
// Recurse to get the size of the dynamically sized field (must be
7676
// the last field).
77-
let field_ty = layout.field(ccx, layout.field_count() - 1).ty;
77+
let field_ty = layout.field(ccx, layout.fields.count() - 1).ty;
7878
let (unsized_size, unsized_align) = size_and_align_of_dst(bcx, field_ty, info);
7979

8080
// FIXME (#26403, #27023): We should be adding padding

0 commit comments

Comments
 (0)