Skip to content

Commit 3dcc409

Browse files
committed
auto merge of rust-lang#19549 : huonw/rust/middle-ty-2, r=nikomatsakis
This takes building `librustc/lib.rs` from using 696 MB to 588 (`rustc --no-trans`), and 1.99 GB to 1.87 (`rustc -O`). It also reduces `sty` down to 32 bytes on platforms with 64-bit pointers, at the expense of some more side-tables in `ctxt`. I'm sure there's more gains to be had from reducing the size of the side tables (e.g. by making the actual things they're storing smaller). r? @nikomatsakis
2 parents 25fb12b + 91db254 commit 3dcc409

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+697
-499
lines changed

src/librustc/lint/builtin.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1598,15 +1598,15 @@ impl LintPass for MissingCopyImplementations {
15981598
}
15991599
ty::mk_struct(cx.tcx,
16001600
ast_util::local_def(item.id),
1601-
Substs::empty())
1601+
cx.tcx.mk_substs(Substs::empty()))
16021602
}
16031603
ast::ItemEnum(_, ref ast_generics) => {
16041604
if ast_generics.is_parameterized() {
16051605
return
16061606
}
16071607
ty::mk_enum(cx.tcx,
16081608
ast_util::local_def(item.id),
1609-
Substs::empty())
1609+
cx.tcx.mk_substs(Substs::empty()))
16101610
}
16111611
_ => return,
16121612
};

src/librustc/metadata/decoder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1449,7 +1449,7 @@ fn doc_generics<'tcx>(base_doc: rbml::Doc,
14491449
let space = subst::ParamSpace::from_uint(reader::doc_as_u64(doc) as uint);
14501450

14511451
let doc = reader::get_doc(rp_doc, tag_region_param_def_index);
1452-
let index = reader::doc_as_u64(doc) as uint;
1452+
let index = reader::doc_as_u64(doc) as u32;
14531453

14541454
let mut bounds = Vec::new();
14551455
reader::tagged_docs(rp_doc, tag_items_data_region, |p| {

src/librustc/metadata/tydecode.rs

+25-15
Original file line numberDiff line numberDiff line change
@@ -262,8 +262,8 @@ fn parse_substs<'a, 'tcx>(st: &mut PState<'a, 'tcx>,
262262
let types =
263263
parse_vec_per_param_space(st, |st| parse_ty(st, |x,y| conv(x,y)));
264264

265-
return subst::Substs { types: types,
266-
regions: regions };
265+
subst::Substs { types: types,
266+
regions: regions }
267267
}
268268

269269
fn parse_region_substs(st: &mut PState, conv: conv_did) -> subst::RegionSubsts {
@@ -281,7 +281,7 @@ fn parse_region_substs(st: &mut PState, conv: conv_did) -> subst::RegionSubsts {
281281
fn parse_bound_region(st: &mut PState, conv: conv_did) -> ty::BoundRegion {
282282
match next(st) {
283283
'a' => {
284-
let id = parse_uint(st);
284+
let id = parse_u32(st);
285285
assert_eq!(next(st), '|');
286286
ty::BrAnon(id)
287287
}
@@ -291,7 +291,7 @@ fn parse_bound_region(st: &mut PState, conv: conv_did) -> ty::BoundRegion {
291291
ty::BrNamed(def, ident.name)
292292
}
293293
'f' => {
294-
let id = parse_uint(st);
294+
let id = parse_u32(st);
295295
assert_eq!(next(st), '|');
296296
ty::BrFresh(id)
297297
}
@@ -304,7 +304,7 @@ fn parse_region(st: &mut PState, conv: conv_did) -> ty::Region {
304304
match next(st) {
305305
'b' => {
306306
assert_eq!(next(st), '[');
307-
let id = ty::DebruijnIndex::new(parse_uint(st));
307+
let id = ty::DebruijnIndex::new(parse_u32(st));
308308
assert_eq!(next(st), '|');
309309
let br = parse_bound_region(st, |x,y| conv(x,y));
310310
assert_eq!(next(st), ']');
@@ -316,7 +316,7 @@ fn parse_region(st: &mut PState, conv: conv_did) -> ty::Region {
316316
assert_eq!(next(st), '|');
317317
let space = parse_param_space(st);
318318
assert_eq!(next(st), '|');
319-
let index = parse_uint(st);
319+
let index = parse_u32(st);
320320
assert_eq!(next(st), '|');
321321
let nm = token::str_to_ident(parse_str(st, ']')[]);
322322
ty::ReEarlyBound(node_id, space, index, nm.name)
@@ -380,7 +380,7 @@ fn parse_trait_ref<'a, 'tcx>(st: &mut PState<'a, 'tcx>, conv: conv_did)
380380
-> ty::TraitRef<'tcx> {
381381
let def = parse_def(st, NominalType, |x,y| conv(x,y));
382382
let substs = parse_substs(st, |x,y| conv(x,y));
383-
ty::TraitRef {def_id: def, substs: substs}
383+
ty::TraitRef {def_id: def, substs: st.tcx.mk_substs(substs)}
384384
}
385385

386386
fn parse_ty<'a, 'tcx>(st: &mut PState<'a, 'tcx>, conv: conv_did) -> Ty<'tcx> {
@@ -409,7 +409,7 @@ fn parse_ty<'a, 'tcx>(st: &mut PState<'a, 'tcx>, conv: conv_did) -> Ty<'tcx> {
409409
let def = parse_def(st, NominalType, |x,y| conv(x,y));
410410
let substs = parse_substs(st, |x,y| conv(x,y));
411411
assert_eq!(next(st), ']');
412-
return ty::mk_enum(st.tcx, def, substs);
412+
return ty::mk_enum(st.tcx, def, st.tcx.mk_substs(substs));
413413
}
414414
'x' => {
415415
assert_eq!(next(st), '[');
@@ -421,7 +421,7 @@ fn parse_ty<'a, 'tcx>(st: &mut PState<'a, 'tcx>, conv: conv_did) -> Ty<'tcx> {
421421
'p' => {
422422
let did = parse_def(st, TypeParameter, |x,y| conv(x,y));
423423
debug!("parsed ty_param: did={}", did);
424-
let index = parse_uint(st);
424+
let index = parse_u32(st);
425425
assert_eq!(next(st), '|');
426426
let space = parse_param_space(st);
427427
assert_eq!(next(st), '|');
@@ -432,7 +432,7 @@ fn parse_ty<'a, 'tcx>(st: &mut PState<'a, 'tcx>, conv: conv_did) -> Ty<'tcx> {
432432
'&' => {
433433
let r = parse_region(st, |x,y| conv(x,y));
434434
let mt = parse_mt(st, |x,y| conv(x,y));
435-
return ty::mk_rptr(st.tcx, r, mt);
435+
return ty::mk_rptr(st.tcx, st.tcx.mk_region(r), mt);
436436
}
437437
'V' => {
438438
let t = parse_ty(st, |x,y| conv(x,y));
@@ -454,10 +454,12 @@ fn parse_ty<'a, 'tcx>(st: &mut PState<'a, 'tcx>, conv: conv_did) -> Ty<'tcx> {
454454
}
455455
'F' => {
456456
let def_id = parse_def(st, NominalType, |x,y| conv(x,y));
457-
return ty::mk_bare_fn(st.tcx, Some(def_id), parse_bare_fn_ty(st, |x,y| conv(x,y)));
457+
return ty::mk_bare_fn(st.tcx, Some(def_id),
458+
st.tcx.mk_bare_fn(parse_bare_fn_ty(st, |x,y| conv(x,y))));
458459
}
459460
'G' => {
460-
return ty::mk_bare_fn(st.tcx, None, parse_bare_fn_ty(st, |x,y| conv(x,y)));
461+
return ty::mk_bare_fn(st.tcx, None,
462+
st.tcx.mk_bare_fn(parse_bare_fn_ty(st, |x,y| conv(x,y))));
461463
}
462464
'#' => {
463465
let pos = parse_hex(st);
@@ -490,15 +492,16 @@ fn parse_ty<'a, 'tcx>(st: &mut PState<'a, 'tcx>, conv: conv_did) -> Ty<'tcx> {
490492
let did = parse_def(st, NominalType, |x,y| conv(x,y));
491493
let substs = parse_substs(st, |x,y| conv(x,y));
492494
assert_eq!(next(st), ']');
493-
return ty::mk_struct(st.tcx, did, substs);
495+
return ty::mk_struct(st.tcx, did, st.tcx.mk_substs(substs));
494496
}
495497
'k' => {
496498
assert_eq!(next(st), '[');
497499
let did = parse_def(st, UnboxedClosureSource, |x,y| conv(x,y));
498500
let region = parse_region(st, |x,y| conv(x,y));
499501
let substs = parse_substs(st, |x,y| conv(x,y));
500502
assert_eq!(next(st), ']');
501-
return ty::mk_unboxed_closure(st.tcx, did, region, substs);
503+
return ty::mk_unboxed_closure(st.tcx, did,
504+
st.tcx.mk_region(region), st.tcx.mk_substs(substs));
502505
}
503506
'e' => {
504507
return ty::mk_err();
@@ -535,6 +538,13 @@ fn parse_uint(st: &mut PState) -> uint {
535538
};
536539
}
537540

541+
fn parse_u32(st: &mut PState) -> u32 {
542+
let n = parse_uint(st);
543+
let m = n as u32;
544+
assert_eq!(m as uint, n);
545+
m
546+
}
547+
538548
fn parse_param_space(st: &mut PState) -> subst::ParamSpace {
539549
subst::ParamSpace::from_uint(parse_uint(st))
540550
}
@@ -697,7 +707,7 @@ fn parse_type_param_def<'a, 'tcx>(st: &mut PState<'a, 'tcx>, conv: conv_did)
697707
let def_id = parse_def(st, NominalType, |x,y| conv(x,y));
698708
let space = parse_param_space(st);
699709
assert_eq!(next(st), '|');
700-
let index = parse_uint(st);
710+
let index = parse_u32(st);
701711
assert_eq!(next(st), '|');
702712
let associated_with = parse_opt(st, |st| {
703713
parse_def(st, NominalType, |x,y| conv(x,y))

src/librustc/metadata/tyencode.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ pub fn enc_ty<'a, 'tcx>(w: &mut SeekableMemWriter, cx: &ctxt<'a, 'tcx>, t: Ty<'t
8383
ast::TyF64 => mywrite!(w, "MF"),
8484
}
8585
}
86-
ty::ty_enum(def, ref substs) => {
86+
ty::ty_enum(def, substs) => {
8787
mywrite!(w, "t[{}|", (cx.ds)(def));
8888
enc_substs(w, cx, substs);
8989
mywrite!(w, "]");
@@ -104,7 +104,7 @@ pub fn enc_ty<'a, 'tcx>(w: &mut SeekableMemWriter, cx: &ctxt<'a, 'tcx>, t: Ty<'t
104104
ty::ty_ptr(mt) => { mywrite!(w, "*"); enc_mt(w, cx, mt); }
105105
ty::ty_rptr(r, mt) => {
106106
mywrite!(w, "&");
107-
enc_region(w, cx, r);
107+
enc_region(w, cx, *r);
108108
enc_mt(w, cx, mt);
109109
}
110110
ty::ty_vec(t, sz) => {
@@ -123,12 +123,12 @@ pub fn enc_ty<'a, 'tcx>(w: &mut SeekableMemWriter, cx: &ctxt<'a, 'tcx>, t: Ty<'t
123123
mywrite!(w, "f");
124124
enc_closure_ty(w, cx, &**f);
125125
}
126-
ty::ty_bare_fn(Some(def_id), ref f) => {
126+
ty::ty_bare_fn(Some(def_id), f) => {
127127
mywrite!(w, "F");
128128
mywrite!(w, "{}|", (cx.ds)(def_id));
129129
enc_bare_fn_ty(w, cx, f);
130130
}
131-
ty::ty_bare_fn(None, ref f) => {
131+
ty::ty_bare_fn(None, f) => {
132132
mywrite!(w, "G");
133133
enc_bare_fn_ty(w, cx, f);
134134
}
@@ -138,14 +138,14 @@ pub fn enc_ty<'a, 'tcx>(w: &mut SeekableMemWriter, cx: &ctxt<'a, 'tcx>, t: Ty<'t
138138
ty::ty_param(ParamTy {space, idx: id, def_id: did}) => {
139139
mywrite!(w, "p{}|{}|{}|", (cx.ds)(did), id, space.to_uint())
140140
}
141-
ty::ty_struct(def, ref substs) => {
141+
ty::ty_struct(def, substs) => {
142142
mywrite!(w, "a[{}|", (cx.ds)(def));
143143
enc_substs(w, cx, substs);
144144
mywrite!(w, "]");
145145
}
146-
ty::ty_unboxed_closure(def, region, ref substs) => {
146+
ty::ty_unboxed_closure(def, region, substs) => {
147147
mywrite!(w, "k[{}|", (cx.ds)(def));
148-
enc_region(w, cx, region);
148+
enc_region(w, cx, *region);
149149
enc_substs(w, cx, substs);
150150
mywrite!(w, "]");
151151
}
@@ -301,7 +301,7 @@ fn enc_bound_region(w: &mut SeekableMemWriter, cx: &ctxt, br: ty::BoundRegion) {
301301
pub fn enc_trait_ref<'a, 'tcx>(w: &mut SeekableMemWriter, cx: &ctxt<'a, 'tcx>,
302302
s: &ty::TraitRef<'tcx>) {
303303
mywrite!(w, "{}|", (cx.ds)(s.def_id));
304-
enc_substs(w, cx, &s.substs);
304+
enc_substs(w, cx, s.substs);
305305
}
306306

307307
pub fn enc_trait_store(w: &mut SeekableMemWriter, cx: &ctxt, s: ty::TraitStore) {

src/librustc/middle/def.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ pub enum Def {
3939
DefAssociatedPath(TyParamProvenance, ast::Ident),
4040
DefTrait(ast::DefId),
4141
DefPrimTy(ast::PrimTy),
42-
DefTyParam(ParamSpace, ast::DefId, uint),
42+
DefTyParam(ParamSpace, ast::DefId, u32),
4343
DefUse(ast::DefId),
4444
DefUpvar(ast::NodeId, // id of closed over local
4545
ast::NodeId, // expr node that creates the closure

src/librustc/middle/expr_use_visitor.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -767,7 +767,7 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,'tcx,TYPER> {
767767
// Select just those fields of the `with`
768768
// expression that will actually be used
769769
let with_fields = match with_cmt.ty.sty {
770-
ty::ty_struct(did, ref substs) => {
770+
ty::ty_struct(did, substs) => {
771771
ty::struct_fields(self.tcx(), did, substs)
772772
}
773773
_ => {
@@ -861,7 +861,7 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,'tcx,TYPER> {
861861
};
862862
let bk = ty::BorrowKind::from_mutbl(m);
863863
self.delegate.borrow(expr.id, expr.span, cmt,
864-
r, bk, AutoRef);
864+
*r, bk, AutoRef);
865865
}
866866
}
867867
}
@@ -1271,4 +1271,3 @@ fn copy_or_move<'tcx>(tcx: &ty::ctxt<'tcx>,
12711271
Copy
12721272
}
12731273
}
1274-

src/librustc/middle/infer/coercion.rs

+10-9
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
174174

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

232232
let a_borrowed = ty::mk_rptr(self.tcx(),
233-
r_borrow,
233+
self.tcx().mk_region(r_borrow),
234234
mt {ty: inner_ty, mutbl: mutbl_b});
235235
try!(sub.tys(a_borrowed, b));
236236

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

426426
self.coerce_object(a, b, b_mutbl,
427-
|tr| ty::mk_rptr(tcx, r_a, ty::mt{ mutbl: b_mutbl, ty: tr }),
427+
|tr| ty::mk_rptr(tcx, tcx.mk_region(r_a),
428+
ty::mt{ mutbl: b_mutbl, ty: tr }),
428429
|| AutoPtr(r_a, b_mutbl, None))
429430
}
430431

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

488489
match a.sty {
489-
ty::ty_bare_fn(Some(a_def_id), ref f) => {
490+
ty::ty_bare_fn(Some(a_def_id), f) => {
490491
self.coerce_from_fn_item(a, a_def_id, f, b)
491492
}
492493
_ => {
@@ -498,7 +499,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
498499
fn coerce_from_fn_item(&self,
499500
a: Ty<'tcx>,
500501
fn_def_id_a: ast::DefId,
501-
fn_ty_a: &ty::BareFnTy<'tcx>,
502+
fn_ty_a: &'tcx ty::BareFnTy<'tcx>,
502503
b: Ty<'tcx>)
503504
-> CoerceResult<'tcx> {
504505
/*!
@@ -527,7 +528,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
527528
Ok(Some(adj))
528529
}
529530
ty::ty_bare_fn(None, _) => {
530-
let a_fn_pointer = ty::mk_bare_fn(self.tcx(), None, (*fn_ty_a).clone());
531+
let a_fn_pointer = ty::mk_bare_fn(self.tcx(), None, fn_ty_a);
531532
try!(self.subtype(a_fn_pointer, b));
532533
Ok(Some(ty::AdjustReifyFnPointer(fn_def_id_a)))
533534
}

0 commit comments

Comments
 (0)