Skip to content

Reduce memory use of sty #19549

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Dec 29, 2014
4 changes: 2 additions & 2 deletions src/librustc/lint/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1598,15 +1598,15 @@ impl LintPass for MissingCopyImplementations {
}
ty::mk_struct(cx.tcx,
ast_util::local_def(item.id),
Substs::empty())
cx.tcx.mk_substs(Substs::empty()))
}
ast::ItemEnum(_, ref ast_generics) => {
if ast_generics.is_parameterized() {
return
}
ty::mk_enum(cx.tcx,
ast_util::local_def(item.id),
Substs::empty())
cx.tcx.mk_substs(Substs::empty()))
}
_ => return,
};
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/metadata/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1449,7 +1449,7 @@ fn doc_generics<'tcx>(base_doc: rbml::Doc,
let space = subst::ParamSpace::from_uint(reader::doc_as_u64(doc) as uint);

let doc = reader::get_doc(rp_doc, tag_region_param_def_index);
let index = reader::doc_as_u64(doc) as uint;
let index = reader::doc_as_u64(doc) as u32;

let mut bounds = Vec::new();
reader::tagged_docs(rp_doc, tag_items_data_region, |p| {
Expand Down
40 changes: 25 additions & 15 deletions src/librustc/metadata/tydecode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,8 @@ fn parse_substs<'a, 'tcx>(st: &mut PState<'a, 'tcx>,
let types =
parse_vec_per_param_space(st, |st| parse_ty(st, |x,y| conv(x,y)));

return subst::Substs { types: types,
regions: regions };
subst::Substs { types: types,
regions: regions }
}

fn parse_region_substs(st: &mut PState, conv: conv_did) -> subst::RegionSubsts {
Expand All @@ -281,7 +281,7 @@ fn parse_region_substs(st: &mut PState, conv: conv_did) -> subst::RegionSubsts {
fn parse_bound_region(st: &mut PState, conv: conv_did) -> ty::BoundRegion {
match next(st) {
'a' => {
let id = parse_uint(st);
let id = parse_u32(st);
assert_eq!(next(st), '|');
ty::BrAnon(id)
}
Expand All @@ -291,7 +291,7 @@ fn parse_bound_region(st: &mut PState, conv: conv_did) -> ty::BoundRegion {
ty::BrNamed(def, ident.name)
}
'f' => {
let id = parse_uint(st);
let id = parse_u32(st);
assert_eq!(next(st), '|');
ty::BrFresh(id)
}
Expand All @@ -304,7 +304,7 @@ fn parse_region(st: &mut PState, conv: conv_did) -> ty::Region {
match next(st) {
'b' => {
assert_eq!(next(st), '[');
let id = ty::DebruijnIndex::new(parse_uint(st));
let id = ty::DebruijnIndex::new(parse_u32(st));
assert_eq!(next(st), '|');
let br = parse_bound_region(st, |x,y| conv(x,y));
assert_eq!(next(st), ']');
Expand All @@ -316,7 +316,7 @@ fn parse_region(st: &mut PState, conv: conv_did) -> ty::Region {
assert_eq!(next(st), '|');
let space = parse_param_space(st);
assert_eq!(next(st), '|');
let index = parse_uint(st);
let index = parse_u32(st);
assert_eq!(next(st), '|');
let nm = token::str_to_ident(parse_str(st, ']')[]);
ty::ReEarlyBound(node_id, space, index, nm.name)
Expand Down Expand Up @@ -380,7 +380,7 @@ fn parse_trait_ref<'a, 'tcx>(st: &mut PState<'a, 'tcx>, conv: conv_did)
-> ty::TraitRef<'tcx> {
let def = parse_def(st, NominalType, |x,y| conv(x,y));
let substs = parse_substs(st, |x,y| conv(x,y));
ty::TraitRef {def_id: def, substs: substs}
ty::TraitRef {def_id: def, substs: st.tcx.mk_substs(substs)}
}

fn parse_ty<'a, 'tcx>(st: &mut PState<'a, 'tcx>, conv: conv_did) -> Ty<'tcx> {
Expand Down Expand Up @@ -409,7 +409,7 @@ fn parse_ty<'a, 'tcx>(st: &mut PState<'a, 'tcx>, conv: conv_did) -> Ty<'tcx> {
let def = parse_def(st, NominalType, |x,y| conv(x,y));
let substs = parse_substs(st, |x,y| conv(x,y));
assert_eq!(next(st), ']');
return ty::mk_enum(st.tcx, def, substs);
return ty::mk_enum(st.tcx, def, st.tcx.mk_substs(substs));
}
'x' => {
assert_eq!(next(st), '[');
Expand All @@ -421,7 +421,7 @@ fn parse_ty<'a, 'tcx>(st: &mut PState<'a, 'tcx>, conv: conv_did) -> Ty<'tcx> {
'p' => {
let did = parse_def(st, TypeParameter, |x,y| conv(x,y));
debug!("parsed ty_param: did={}", did);
let index = parse_uint(st);
let index = parse_u32(st);
assert_eq!(next(st), '|');
let space = parse_param_space(st);
assert_eq!(next(st), '|');
Expand All @@ -432,7 +432,7 @@ fn parse_ty<'a, 'tcx>(st: &mut PState<'a, 'tcx>, conv: conv_did) -> Ty<'tcx> {
'&' => {
let r = parse_region(st, |x,y| conv(x,y));
let mt = parse_mt(st, |x,y| conv(x,y));
return ty::mk_rptr(st.tcx, r, mt);
return ty::mk_rptr(st.tcx, st.tcx.mk_region(r), mt);
}
'V' => {
let t = parse_ty(st, |x,y| conv(x,y));
Expand All @@ -454,10 +454,12 @@ fn parse_ty<'a, 'tcx>(st: &mut PState<'a, 'tcx>, conv: conv_did) -> Ty<'tcx> {
}
'F' => {
let def_id = parse_def(st, NominalType, |x,y| conv(x,y));
return ty::mk_bare_fn(st.tcx, Some(def_id), parse_bare_fn_ty(st, |x,y| conv(x,y)));
return ty::mk_bare_fn(st.tcx, Some(def_id),
st.tcx.mk_bare_fn(parse_bare_fn_ty(st, |x,y| conv(x,y))));
}
'G' => {
return ty::mk_bare_fn(st.tcx, None, parse_bare_fn_ty(st, |x,y| conv(x,y)));
return ty::mk_bare_fn(st.tcx, None,
st.tcx.mk_bare_fn(parse_bare_fn_ty(st, |x,y| conv(x,y))));
}
'#' => {
let pos = parse_hex(st);
Expand Down Expand Up @@ -490,15 +492,16 @@ fn parse_ty<'a, 'tcx>(st: &mut PState<'a, 'tcx>, conv: conv_did) -> Ty<'tcx> {
let did = parse_def(st, NominalType, |x,y| conv(x,y));
let substs = parse_substs(st, |x,y| conv(x,y));
assert_eq!(next(st), ']');
return ty::mk_struct(st.tcx, did, substs);
return ty::mk_struct(st.tcx, did, st.tcx.mk_substs(substs));
}
'k' => {
assert_eq!(next(st), '[');
let did = parse_def(st, UnboxedClosureSource, |x,y| conv(x,y));
let region = parse_region(st, |x,y| conv(x,y));
let substs = parse_substs(st, |x,y| conv(x,y));
assert_eq!(next(st), ']');
return ty::mk_unboxed_closure(st.tcx, did, region, substs);
return ty::mk_unboxed_closure(st.tcx, did,
st.tcx.mk_region(region), st.tcx.mk_substs(substs));
}
'e' => {
return ty::mk_err();
Expand Down Expand Up @@ -535,6 +538,13 @@ fn parse_uint(st: &mut PState) -> uint {
};
}

fn parse_u32(st: &mut PState) -> u32 {
let n = parse_uint(st);
let m = n as u32;
assert_eq!(m as uint, n);
m
}

fn parse_param_space(st: &mut PState) -> subst::ParamSpace {
subst::ParamSpace::from_uint(parse_uint(st))
}
Expand Down Expand Up @@ -697,7 +707,7 @@ fn parse_type_param_def<'a, 'tcx>(st: &mut PState<'a, 'tcx>, conv: conv_did)
let def_id = parse_def(st, NominalType, |x,y| conv(x,y));
let space = parse_param_space(st);
assert_eq!(next(st), '|');
let index = parse_uint(st);
let index = parse_u32(st);
assert_eq!(next(st), '|');
let associated_with = parse_opt(st, |st| {
parse_def(st, NominalType, |x,y| conv(x,y))
Expand Down
16 changes: 8 additions & 8 deletions src/librustc/metadata/tyencode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ pub fn enc_ty<'a, 'tcx>(w: &mut SeekableMemWriter, cx: &ctxt<'a, 'tcx>, t: Ty<'t
ast::TyF64 => mywrite!(w, "MF"),
}
}
ty::ty_enum(def, ref substs) => {
ty::ty_enum(def, substs) => {
mywrite!(w, "t[{}|", (cx.ds)(def));
enc_substs(w, cx, substs);
mywrite!(w, "]");
Expand All @@ -104,7 +104,7 @@ pub fn enc_ty<'a, 'tcx>(w: &mut SeekableMemWriter, cx: &ctxt<'a, 'tcx>, t: Ty<'t
ty::ty_ptr(mt) => { mywrite!(w, "*"); enc_mt(w, cx, mt); }
ty::ty_rptr(r, mt) => {
mywrite!(w, "&");
enc_region(w, cx, r);
enc_region(w, cx, *r);
enc_mt(w, cx, mt);
}
ty::ty_vec(t, sz) => {
Expand All @@ -123,12 +123,12 @@ pub fn enc_ty<'a, 'tcx>(w: &mut SeekableMemWriter, cx: &ctxt<'a, 'tcx>, t: Ty<'t
mywrite!(w, "f");
enc_closure_ty(w, cx, &**f);
}
ty::ty_bare_fn(Some(def_id), ref f) => {
ty::ty_bare_fn(Some(def_id), f) => {
mywrite!(w, "F");
mywrite!(w, "{}|", (cx.ds)(def_id));
enc_bare_fn_ty(w, cx, f);
}
ty::ty_bare_fn(None, ref f) => {
ty::ty_bare_fn(None, f) => {
mywrite!(w, "G");
enc_bare_fn_ty(w, cx, f);
}
Expand All @@ -138,14 +138,14 @@ pub fn enc_ty<'a, 'tcx>(w: &mut SeekableMemWriter, cx: &ctxt<'a, 'tcx>, t: Ty<'t
ty::ty_param(ParamTy {space, idx: id, def_id: did}) => {
mywrite!(w, "p{}|{}|{}|", (cx.ds)(did), id, space.to_uint())
}
ty::ty_struct(def, ref substs) => {
ty::ty_struct(def, substs) => {
mywrite!(w, "a[{}|", (cx.ds)(def));
enc_substs(w, cx, substs);
mywrite!(w, "]");
}
ty::ty_unboxed_closure(def, region, ref substs) => {
ty::ty_unboxed_closure(def, region, substs) => {
mywrite!(w, "k[{}|", (cx.ds)(def));
enc_region(w, cx, region);
enc_region(w, cx, *region);
enc_substs(w, cx, substs);
mywrite!(w, "]");
}
Expand Down Expand Up @@ -301,7 +301,7 @@ fn enc_bound_region(w: &mut SeekableMemWriter, cx: &ctxt, br: ty::BoundRegion) {
pub fn enc_trait_ref<'a, 'tcx>(w: &mut SeekableMemWriter, cx: &ctxt<'a, 'tcx>,
s: &ty::TraitRef<'tcx>) {
mywrite!(w, "{}|", (cx.ds)(s.def_id));
enc_substs(w, cx, &s.substs);
enc_substs(w, cx, s.substs);
}

pub fn enc_trait_store(w: &mut SeekableMemWriter, cx: &ctxt, s: ty::TraitStore) {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub enum Def {
DefAssociatedPath(TyParamProvenance, ast::Ident),
DefTrait(ast::DefId),
DefPrimTy(ast::PrimTy),
DefTyParam(ParamSpace, ast::DefId, uint),
DefTyParam(ParamSpace, ast::DefId, u32),
DefUse(ast::DefId),
DefUpvar(ast::NodeId, // id of closed over local
ast::NodeId, // expr node that creates the closure
Expand Down
5 changes: 2 additions & 3 deletions src/librustc/middle/expr_use_visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,7 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,'tcx,TYPER> {
// Select just those fields of the `with`
// expression that will actually be used
let with_fields = match with_cmt.ty.sty {
ty::ty_struct(did, ref substs) => {
ty::ty_struct(did, substs) => {
ty::struct_fields(self.tcx(), did, substs)
}
_ => {
Expand Down Expand Up @@ -861,7 +861,7 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,'tcx,TYPER> {
};
let bk = ty::BorrowKind::from_mutbl(m);
self.delegate.borrow(expr.id, expr.span, cmt,
r, bk, AutoRef);
*r, bk, AutoRef);
}
}
}
Expand Down Expand Up @@ -1271,4 +1271,3 @@ fn copy_or_move<'tcx>(tcx: &ty::ctxt<'tcx>,
Copy
}
}

19 changes: 10 additions & 9 deletions src/librustc/middle/infer/coercion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {

self.unpack_actual_value(a, |a| {
match a.sty {
ty::ty_bare_fn(Some(a_def_id), ref a_f) => {
ty::ty_bare_fn(Some(a_def_id), a_f) => {
// Function items are coercible to any closure
// type; function pointers are not (that would
// require double indirection).
Expand Down Expand Up @@ -230,7 +230,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
};

let a_borrowed = ty::mk_rptr(self.tcx(),
r_borrow,
self.tcx().mk_region(r_borrow),
mt {ty: inner_ty, mutbl: mutbl_b});
try!(sub.tys(a_borrowed, b));

Expand Down Expand Up @@ -271,7 +271,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
let coercion = Coercion(self.get_ref().trace.clone());
let r_borrow = self.get_ref().infcx.next_region_var(coercion);
let ty = ty::mk_rptr(self.tcx(),
r_borrow,
self.tcx().mk_region(r_borrow),
ty::mt{ty: ty, mutbl: mt_b.mutbl});
try!(self.get_ref().infcx.try(|_| sub.tys(ty, b)));
debug!("Success, coerced with AutoDerefRef(1, \
Expand Down Expand Up @@ -358,7 +358,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
bounds: bounds },
ty_a)))
}
(&ty::ty_struct(did_a, ref substs_a), &ty::ty_struct(did_b, ref substs_b))
(&ty::ty_struct(did_a, substs_a), &ty::ty_struct(did_b, substs_b))
if did_a == did_b => {
debug!("unsizing a struct");
// Try unsizing each type param in turn to see if we end up with ty_b.
Expand All @@ -383,7 +383,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
// Check that the whole types match.
let mut new_substs = substs_a.clone();
new_substs.types.get_mut_slice(subst::TypeSpace)[i] = new_tp;
let ty = ty::mk_struct(tcx, did_a, new_substs);
let ty = ty::mk_struct(tcx, did_a, tcx.mk_substs(new_substs));
if self.get_ref().infcx.try(|_| sub.tys(ty, ty_b)).is_err() {
debug!("Unsized type parameter '{}', but still \
could not match types {} and {}",
Expand Down Expand Up @@ -424,7 +424,8 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
let r_a = self.get_ref().infcx.next_region_var(coercion);

self.coerce_object(a, b, b_mutbl,
|tr| ty::mk_rptr(tcx, r_a, ty::mt{ mutbl: b_mutbl, ty: tr }),
|tr| ty::mk_rptr(tcx, tcx.mk_region(r_a),
ty::mt{ mutbl: b_mutbl, ty: tr }),
|| AutoPtr(r_a, b_mutbl, None))
}

Expand Down Expand Up @@ -486,7 +487,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
b.repr(self.tcx()));

match a.sty {
ty::ty_bare_fn(Some(a_def_id), ref f) => {
ty::ty_bare_fn(Some(a_def_id), f) => {
self.coerce_from_fn_item(a, a_def_id, f, b)
}
_ => {
Expand All @@ -498,7 +499,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
fn coerce_from_fn_item(&self,
a: Ty<'tcx>,
fn_def_id_a: ast::DefId,
fn_ty_a: &ty::BareFnTy<'tcx>,
fn_ty_a: &'tcx ty::BareFnTy<'tcx>,
b: Ty<'tcx>)
-> CoerceResult<'tcx> {
/*!
Expand Down Expand Up @@ -527,7 +528,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
Ok(Some(adj))
}
ty::ty_bare_fn(None, _) => {
let a_fn_pointer = ty::mk_bare_fn(self.tcx(), None, (*fn_ty_a).clone());
let a_fn_pointer = ty::mk_bare_fn(self.tcx(), None, fn_ty_a);
try!(self.subtype(a_fn_pointer, b));
Ok(Some(ty::AdjustReifyFnPointer(fn_def_id_a)))
}
Expand Down
Loading