Skip to content

Commit a33a7d2

Browse files
committed
Switch Region information from uint to u32.
This reduces memory use for building librustc with -O from 1.88 to 1.76 GB.
1 parent a548f89 commit a33a7d2

File tree

17 files changed

+157
-138
lines changed

17 files changed

+157
-138
lines changed

src/librustc/metadata/decoder.rs

Lines changed: 1 addition & 1 deletion
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

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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)
@@ -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), '|');
@@ -535,6 +535,13 @@ fn parse_uint(st: &mut PState) -> uint {
535535
};
536536
}
537537

538+
fn parse_u32(st: &mut PState) -> u32 {
539+
let n = parse_uint(st);
540+
let m = n as u32;
541+
assert_eq!(m as uint, n);
542+
m
543+
}
544+
538545
fn parse_param_space(st: &mut PState) -> subst::ParamSpace {
539546
subst::ParamSpace::from_uint(parse_uint(st))
540547
}
@@ -697,7 +704,7 @@ fn parse_type_param_def<'a, 'tcx>(st: &mut PState<'a, 'tcx>, conv: conv_did)
697704
let def_id = parse_def(st, NominalType, |x,y| conv(x,y));
698705
let space = parse_param_space(st);
699706
assert_eq!(next(st), '|');
700-
let index = parse_uint(st);
707+
let index = parse_u32(st);
701708
assert_eq!(next(st), '|');
702709
let associated_with = parse_opt(st, |st| {
703710
parse_def(st, NominalType, |x,y| conv(x,y))

src/librustc/middle/def.rs

Lines changed: 1 addition & 1 deletion
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/infer/error_reporting.rs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -870,11 +870,11 @@ impl<'a, 'tcx> ErrorReporting<'tcx> for InferCtxt<'a, 'tcx> {
870870
struct RebuildPathInfo<'a> {
871871
path: &'a ast::Path,
872872
// indexes to insert lifetime on path.lifetimes
873-
indexes: Vec<uint>,
873+
indexes: Vec<u32>,
874874
// number of lifetimes we expect to see on the type referred by `path`
875875
// (e.g., expected=1 for struct Foo<'a>)
876-
expected: uint,
877-
anon_nums: &'a HashSet<uint>,
876+
expected: u32,
877+
anon_nums: &'a HashSet<u32>,
878878
region_names: &'a HashSet<ast::Name>
879879
}
880880

@@ -885,8 +885,8 @@ struct Rebuilder<'a, 'tcx: 'a> {
885885
generics: &'a ast::Generics,
886886
same_regions: &'a [SameRegions],
887887
life_giver: &'a LifeGiver,
888-
cur_anon: Cell<uint>,
889-
inserted_anons: RefCell<HashSet<uint>>,
888+
cur_anon: Cell<u32>,
889+
inserted_anons: RefCell<HashSet<u32>>,
890890
}
891891

892892
enum FreshOrKept {
@@ -976,7 +976,7 @@ impl<'a, 'tcx> Rebuilder<'a, 'tcx> {
976976
}
977977

978978
fn extract_anon_nums_and_names(&self, same_regions: &SameRegions)
979-
-> (HashSet<uint>, HashSet<ast::Name>) {
979+
-> (HashSet<u32>, HashSet<ast::Name>) {
980980
let mut anon_nums = HashSet::new();
981981
let mut region_names = HashSet::new();
982982
for br in same_regions.regions.iter() {
@@ -1008,7 +1008,7 @@ impl<'a, 'tcx> Rebuilder<'a, 'tcx> {
10081008
all_region_names
10091009
}
10101010

1011-
fn inc_cur_anon(&self, n: uint) {
1011+
fn inc_cur_anon(&self, n: u32) {
10121012
let anon = self.cur_anon.get();
10131013
self.cur_anon.set(anon+n);
10141014
}
@@ -1021,12 +1021,12 @@ impl<'a, 'tcx> Rebuilder<'a, 'tcx> {
10211021
self.cur_anon.set(anon);
10221022
}
10231023

1024-
fn inc_and_offset_cur_anon(&self, n: uint) {
1024+
fn inc_and_offset_cur_anon(&self, n: u32) {
10251025
self.inc_cur_anon(n);
10261026
self.offset_cur_anon();
10271027
}
10281028

1029-
fn track_anon(&self, anon: uint) {
1029+
fn track_anon(&self, anon: u32) {
10301030
self.inserted_anons.borrow_mut().insert(anon);
10311031
}
10321032

@@ -1070,13 +1070,13 @@ impl<'a, 'tcx> Rebuilder<'a, 'tcx> {
10701070
let lifetimes = last_seg.parameters.lifetimes();
10711071
for (i, lt) in lifetimes.iter().enumerate() {
10721072
if region_names.contains(&lt.name) {
1073-
insert.push(i);
1073+
insert.push(i as u32);
10741074
}
10751075
}
10761076
let rebuild_info = RebuildPathInfo {
10771077
path: &tr.path,
10781078
indexes: insert,
1079-
expected: lifetimes.len(),
1079+
expected: lifetimes.len() as u32,
10801080
anon_nums: &HashSet::new(),
10811081
region_names: region_names
10821082
};
@@ -1096,7 +1096,7 @@ impl<'a, 'tcx> Rebuilder<'a, 'tcx> {
10961096
fn rebuild_expl_self(&self,
10971097
expl_self_opt: Option<ast::ExplicitSelf_>,
10981098
lifetime: ast::Lifetime,
1099-
anon_nums: &HashSet<uint>,
1099+
anon_nums: &HashSet<u32>,
11001100
region_names: &HashSet<ast::Name>)
11011101
-> Option<ast::ExplicitSelf_> {
11021102
match expl_self_opt {
@@ -1150,7 +1150,7 @@ impl<'a, 'tcx> Rebuilder<'a, 'tcx> {
11501150
fn rebuild_args_ty(&self,
11511151
inputs: &[ast::Arg],
11521152
lifetime: ast::Lifetime,
1153-
anon_nums: &HashSet<uint>,
1153+
anon_nums: &HashSet<u32>,
11541154
region_names: &HashSet<ast::Name>)
11551155
-> Vec<ast::Arg> {
11561156
let mut new_inputs = Vec::new();
@@ -1169,7 +1169,7 @@ impl<'a, 'tcx> Rebuilder<'a, 'tcx> {
11691169

11701170
fn rebuild_output(&self, ty: &ast::FunctionRetTy,
11711171
lifetime: ast::Lifetime,
1172-
anon_nums: &HashSet<uint>,
1172+
anon_nums: &HashSet<u32>,
11731173
region_names: &HashSet<ast::Name>) -> ast::FunctionRetTy {
11741174
match *ty {
11751175
ast::Return(ref ret_ty) => ast::Return(
@@ -1182,7 +1182,7 @@ impl<'a, 'tcx> Rebuilder<'a, 'tcx> {
11821182
fn rebuild_arg_ty_or_output(&self,
11831183
ty: &ast::Ty,
11841184
lifetime: ast::Lifetime,
1185-
anon_nums: &HashSet<uint>,
1185+
anon_nums: &HashSet<u32>,
11861186
region_names: &HashSet<ast::Name>)
11871187
-> P<ast::Ty> {
11881188
let mut new_ty = P(ty.clone());
@@ -1229,7 +1229,7 @@ impl<'a, 'tcx> Rebuilder<'a, 'tcx> {
12291229
let generics = ty::lookup_item_type(self.tcx, did).generics;
12301230

12311231
let expected =
1232-
generics.regions.len(subst::TypeSpace);
1232+
generics.regions.len(subst::TypeSpace) as u32;
12331233
let lifetimes =
12341234
path.segments.last().unwrap().parameters.lifetimes();
12351235
let mut insert = Vec::new();
@@ -1238,15 +1238,15 @@ impl<'a, 'tcx> Rebuilder<'a, 'tcx> {
12381238
for (i, a) in range(anon,
12391239
anon+expected).enumerate() {
12401240
if anon_nums.contains(&a) {
1241-
insert.push(i);
1241+
insert.push(i as u32);
12421242
}
12431243
self.track_anon(a);
12441244
}
12451245
self.inc_and_offset_cur_anon(expected);
12461246
} else {
12471247
for (i, lt) in lifetimes.iter().enumerate() {
12481248
if region_names.contains(&lt.name) {
1249-
insert.push(i);
1249+
insert.push(i as u32);
12501250
}
12511251
}
12521252
}
@@ -1363,7 +1363,7 @@ impl<'a, 'tcx> Rebuilder<'a, 'tcx> {
13631363
}
13641364
} else {
13651365
for (i, lt) in data.lifetimes.iter().enumerate() {
1366-
if indexes.contains(&i) {
1366+
if indexes.contains(&(i as u32)) {
13671367
new_lts.push(lifetime);
13681368
} else {
13691369
new_lts.push(*lt);

src/librustc/middle/infer/freshen.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ use super::unify::InferCtxtMethodsForSimplyUnifiableTypes;
4141

4242
pub struct TypeFreshener<'a, 'tcx:'a> {
4343
infcx: &'a InferCtxt<'a, 'tcx>,
44-
freshen_count: uint,
44+
freshen_count: u32,
4545
freshen_map: hash_map::HashMap<ty::InferTy, Ty<'tcx>>,
4646
}
4747

@@ -59,7 +59,7 @@ impl<'a, 'tcx> TypeFreshener<'a, 'tcx> {
5959
key: ty::InferTy,
6060
freshener: F)
6161
-> Ty<'tcx> where
62-
F: FnOnce(uint) -> ty::InferTy,
62+
F: FnOnce(u32) -> ty::InferTy,
6363
{
6464
match opt_ty {
6565
Some(ty) => { return ty.fold_with(self); }

0 commit comments

Comments
 (0)