Skip to content

Commit 8c4d5af

Browse files
committed
rustc: remove Ty::layout and move everything to layout_of.
1 parent 8864668 commit 8c4d5af

File tree

19 files changed

+201
-250
lines changed

19 files changed

+201
-250
lines changed

src/librustc/lint/context.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ use middle::privacy::AccessLevels;
3434
use rustc_serialize::{Decoder, Decodable, Encoder, Encodable};
3535
use session::{config, early_error, Session};
3636
use traits::Reveal;
37-
use ty::{self, TyCtxt};
37+
use ty::{self, TyCtxt, Ty};
38+
use ty::layout::{FullLayout, LayoutError, LayoutOf};
3839
use util::nodemap::FxHashMap;
3940

4041
use std::default::Default as StdDefault;
@@ -626,6 +627,14 @@ impl<'a, 'tcx> LateContext<'a, 'tcx> {
626627
}
627628
}
628629

630+
impl<'a, 'tcx> LayoutOf<Ty<'tcx>> for &'a LateContext<'a, 'tcx> {
631+
type FullLayout = Result<FullLayout<'tcx>, LayoutError<'tcx>>;
632+
633+
fn layout_of(self, ty: Ty<'tcx>) -> Self::FullLayout {
634+
(self.tcx, self.param_env.reveal_all()).layout_of(ty)
635+
}
636+
}
637+
629638
impl<'a, 'tcx> hir_visit::Visitor<'tcx> for LateContext<'a, 'tcx> {
630639
/// Because lints are scoped lexically, we want to walk nested
631640
/// items in the context of the outer item, so enable

src/librustc/ty/layout.rs

Lines changed: 158 additions & 163 deletions
Large diffs are not rendered by default.

src/librustc/ty/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2617,9 +2617,10 @@ fn original_crate_name<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
26172617
}
26182618

26192619
pub fn provide(providers: &mut ty::maps::Providers) {
2620-
util::provide(providers);
26212620
context::provide(providers);
26222621
erase_regions::provide(providers);
2622+
layout::provide(providers);
2623+
util::provide(providers);
26232624
*providers = ty::maps::Providers {
26242625
associated_item,
26252626
associated_item_def_ids,

src/librustc/ty/util.rs

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ use middle::const_val::ConstVal;
1919
use traits::{self, Reveal};
2020
use ty::{self, Ty, TyCtxt, TypeFoldable};
2121
use ty::fold::TypeVisitor;
22-
use ty::layout::{Layout, LayoutError};
2322
use ty::subst::{Subst, Kind};
2423
use ty::TypeVariants::*;
2524
use util::common::ErrorReported;
@@ -852,30 +851,6 @@ impl<'a, 'tcx> ty::TyS<'tcx> {
852851
tcx.needs_drop_raw(param_env.and(self))
853852
}
854853

855-
/// Computes the layout of a type. Note that this implicitly
856-
/// executes in "reveal all" mode.
857-
#[inline]
858-
pub fn layout<'lcx>(&'tcx self,
859-
tcx: TyCtxt<'a, 'tcx, 'tcx>,
860-
param_env: ty::ParamEnv<'tcx>)
861-
-> Result<&'tcx Layout, LayoutError<'tcx>> {
862-
let ty = tcx.erase_regions(&self);
863-
let layout = tcx.layout_raw(param_env.reveal_all().and(ty));
864-
865-
// NB: This recording is normally disabled; when enabled, it
866-
// can however trigger recursive invocations of `layout()`.
867-
// Therefore, we execute it *after* the main query has
868-
// completed, to avoid problems around recursive structures
869-
// and the like. (Admitedly, I wasn't able to reproduce a problem
870-
// here, but it seems like the right thing to do. -nmatsakis)
871-
if let Ok(l) = layout {
872-
Layout::record_layout_for_printing(tcx, ty, param_env, l);
873-
}
874-
875-
layout
876-
}
877-
878-
879854
/// Check whether a type is representable. This means it cannot contain unboxed
880855
/// structural recursion. This check is needed for structs and enums.
881856
pub fn is_representable(&'tcx self,
@@ -1184,26 +1159,6 @@ fn needs_drop_raw<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
11841159
}
11851160
}
11861161

1187-
fn layout_raw<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
1188-
query: ty::ParamEnvAnd<'tcx, Ty<'tcx>>)
1189-
-> Result<&'tcx Layout, LayoutError<'tcx>>
1190-
{
1191-
let (param_env, ty) = query.into_parts();
1192-
1193-
let rec_limit = tcx.sess.recursion_limit.get();
1194-
let depth = tcx.layout_depth.get();
1195-
if depth > rec_limit {
1196-
tcx.sess.fatal(
1197-
&format!("overflow representing the type `{}`", ty));
1198-
}
1199-
1200-
tcx.layout_depth.set(depth+1);
1201-
let layout = Layout::compute_uncached(tcx, param_env, ty);
1202-
tcx.layout_depth.set(depth);
1203-
1204-
layout
1205-
}
1206-
12071162
pub enum ExplicitSelf<'tcx> {
12081163
ByValue,
12091164
ByReference(ty::Region<'tcx>, hir::Mutability),
@@ -1262,7 +1217,6 @@ pub fn provide(providers: &mut ty::maps::Providers) {
12621217
is_sized_raw,
12631218
is_freeze_raw,
12641219
needs_drop_raw,
1265-
layout_raw,
12661220
..*providers
12671221
};
12681222
}

src/librustc_lint/types.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
use rustc::hir::def_id::DefId;
1414
use rustc::ty::subst::Substs;
1515
use rustc::ty::{self, AdtKind, Ty, TyCtxt};
16-
use rustc::ty::layout::{Layout, Primitive};
16+
use rustc::ty::layout::{Layout, LayoutOf, Primitive};
1717
use middle::const_val::ConstVal;
1818
use rustc_const_eval::ConstContext;
1919
use util::nodemap::FxHashSet;
@@ -748,9 +748,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for VariantSizeDifferences {
748748
// sizes only make sense for non-generic types
749749
let item_def_id = cx.tcx.hir.local_def_id(it.id);
750750
let t = cx.tcx.type_of(item_def_id);
751-
let param_env = cx.param_env.reveal_all();
752751
let ty = cx.tcx.erase_regions(&t);
753-
let layout = ty.layout(cx.tcx, param_env).unwrap_or_else(|e| {
752+
let layout = cx.layout_of(ty).unwrap_or_else(|e| {
754753
bug!("failed to get layout for `{}`: {}", t, e)
755754
});
756755

src/librustc_mir/transform/inline.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use rustc_data_structures::indexed_vec::{Idx, IndexVec};
1919
use rustc::mir::*;
2020
use rustc::mir::visit::*;
2121
use rustc::ty::{self, Instance, Ty, TyCtxt, TypeFoldable};
22+
use rustc::ty::layout::LayoutOf;
2223
use rustc::ty::subst::{Subst,Substs};
2324

2425
use std::collections::VecDeque;
@@ -625,9 +626,7 @@ impl<'a, 'tcx> Inliner<'a, 'tcx> {
625626
fn type_size_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
626627
param_env: ty::ParamEnv<'tcx>,
627628
ty: Ty<'tcx>) -> Option<u64> {
628-
ty.layout(tcx, param_env).ok().map(|layout| {
629-
layout.size(&tcx.data_layout).bytes()
630-
})
629+
(tcx, param_env).layout_of(ty).ok().map(|layout| layout.size(tcx).bytes())
631630
}
632631

633632
fn subst_and_normalize<'a, 'tcx: 'a>(

src/librustc_trans/abi.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ impl<'tcx> LayoutExt<'tcx> for FullLayout<'tcx> {
330330
}
331331
}
332332

333-
Layout::Univariant { ref variant, .. } => {
333+
Layout::Univariant(ref variant) => {
334334
let mut unaligned_offset = Size::from_bytes(0);
335335
let mut result = None;
336336

src/librustc_trans/adt.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ pub fn finish_type_of<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
7474
layout::Univariant { ..}
7575
| layout::StructWrappedNullablePointer { .. } => {
7676
let (variant_layout, variant) = match *l {
77-
layout::Univariant { ref variant, .. } => {
77+
layout::Univariant(ref variant) => {
7878
let is_enum = if let ty::TyAdt(def, _) = t.sty {
7979
def.is_enum()
8080
} else {
@@ -123,7 +123,7 @@ fn generic_type_of<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
123123
}
124124
}
125125
}
126-
layout::Univariant { ref variant, .. } => {
126+
layout::Univariant(ref variant) => {
127127
match name {
128128
None => {
129129
Type::struct_(cx, &struct_llfields(cx, l, &variant),
@@ -134,16 +134,16 @@ fn generic_type_of<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
134134
}
135135
}
136136
}
137-
layout::UntaggedUnion { ref variants, .. }=> {
137+
layout::UntaggedUnion(ref un) => {
138138
// Use alignment-sized ints to fill all the union storage.
139-
let fill = union_fill(cx, variants.stride(), variants.align);
139+
let fill = union_fill(cx, un.stride(), un.align);
140140
match name {
141141
None => {
142-
Type::struct_(cx, &[fill], variants.packed)
142+
Type::struct_(cx, &[fill], un.packed)
143143
}
144144
Some(name) => {
145145
let mut llty = Type::named_struct(cx, name);
146-
llty.set_struct_body(&[fill], variants.packed);
146+
llty.set_struct_body(&[fill], un.packed);
147147
llty
148148
}
149149
}

src/librustc_trans/cabi_x86_64.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ fn classify_arg<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, arg: &ArgType<'tcx>)
101101
}
102102
}
103103

104-
Layout::Univariant { ref variant, .. } => {
104+
Layout::Univariant(ref variant) => {
105105
for i in 0..layout.field_count() {
106106
let field_off = off + variant.offsets[i];
107107
classify(ccx, layout.field(ccx, i), cls, field_off)?;

src/librustc_trans/common.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ pub fn type_is_imm_pair<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, ty: Ty<'tcx>)
7474
let layout = ccx.layout_of(ty);
7575
match *layout {
7676
Layout::FatPointer { .. } => true,
77-
Layout::Univariant { ref variant, .. } => {
77+
Layout::Univariant(ref variant) => {
7878
// There must be only 2 fields.
7979
if variant.offsets.len() != 2 {
8080
return false;

0 commit comments

Comments
 (0)