diff options
| author | bors <bors@rust-lang.org> | 2013-11-26 22:07:44 -0800 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2013-11-26 22:07:44 -0800 |
| commit | faf4c939fb6c55f0b9d19b1292fa4601169b3c17 (patch) | |
| tree | d4fdf4e1c58c32bed0e3811978e2269edf9bd9f1 /src/libsyntax | |
| parent | 82d9033b67d618d5bc51e9b22190c369214db4b9 (diff) | |
| parent | 7ed27b5531ef25a366ab9e0fe537b7053244b947 (diff) | |
| download | rust-faf4c939fb6c55f0b9d19b1292fa4601169b3c17.tar.gz rust-faf4c939fb6c55f0b9d19b1292fa4601169b3c17.zip | |
auto merge of #10670 : eddyb/rust/node-u32, r=alexcrichton
### Rationale There is no reason to support more than 2³² nodes or names at this moment, as compiling something that big (even without considering the quadratic space usage of some analysis passes) would take at least **64GB**. Meanwhile, some can't (or barely can) compile rustc because it requires almost **1.5GB**. ### Potential problems Can someone confirm this doesn't affect metadata (de)serialization? I can't tell myself, I know nothing about it. ### Results Some structures have a size reduction of 25% to 50%: [before](https://gist.github.com/luqmana/3a82a51fa9c86d9191fa) - [after](https://gist.github.com/eddyb/5a75f8973d3d8018afd3). Sadly, there isn't a massive change in the memory used for compiling stage2 librustc (it doesn't go over **1.4GB** as [before](http://huonw.github.io/isrustfastyet/mem/), but I can barely see the difference). However, my own testcase (previously peaking at **1.6GB** in typeck) shows a reduction of **200**-**400MB**.
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/ast.rs | 14 | ||||
| -rw-r--r-- | src/libsyntax/ast_util.rs | 24 | ||||
| -rw-r--r-- | src/libsyntax/parse/token.rs | 12 | ||||
| -rw-r--r-- | src/libsyntax/util/interner.rs | 38 |
4 files changed, 42 insertions, 46 deletions
diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index dacd7a09f9b..b888c8772d0 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -69,7 +69,7 @@ impl Eq for Ident { // this uint is a reference to a table stored in thread-local // storage. -pub type SyntaxContext = uint; +pub type SyntaxContext = u32; // the SCTable contains a table of SyntaxContext_'s. It // represents a flattened tree structure, to avoid having @@ -87,8 +87,8 @@ pub struct SCTable { } // NB: these must be placed in any SCTable... -pub static EMPTY_CTXT : uint = 0; -pub static ILLEGAL_CTXT : uint = 1; +pub static EMPTY_CTXT : SyntaxContext = 0; +pub static ILLEGAL_CTXT : SyntaxContext = 1; #[deriving(Eq, Encodable, Decodable,IterBytes)] pub enum SyntaxContext_ { @@ -109,10 +109,10 @@ pub enum SyntaxContext_ { /// A name is a part of an identifier, representing a string or gensym. It's /// the result of interning. -pub type Name = uint; +pub type Name = u32; /// A mark represents a unique id associated with a macro expansion -pub type Mrk = uint; +pub type Mrk = u32; impl<S:Encoder> Encodable<S> for Ident { fn encode(&self, s: &mut S) { @@ -163,9 +163,9 @@ pub struct PathSegment { types: OptVec<Ty>, } -pub type CrateNum = int; +pub type CrateNum = u32; -pub type NodeId = int; +pub type NodeId = u32; #[deriving(Clone, TotalEq, TotalOrd, Eq, Encodable, Decodable, IterBytes, ToStr)] pub struct DefId { diff --git a/src/libsyntax/ast_util.rs b/src/libsyntax/ast_util.rs index ef3c23f5153..07380de9381 100644 --- a/src/libsyntax/ast_util.rs +++ b/src/libsyntax/ast_util.rs @@ -18,7 +18,7 @@ use visit::Visitor; use visit; use std::hashmap::HashMap; -use std::int; +use std::u32; use std::local_data; use std::num; use std::option; @@ -382,8 +382,8 @@ pub struct id_range { impl id_range { pub fn max() -> id_range { id_range { - min: int::max_value, - max: int::min_value, + min: u32::max_value, + max: u32::min_value, } } @@ -803,9 +803,9 @@ pub fn display_sctable(table : &SCTable) { /// Add a value to the end of a vec, return its index -fn idx_push<T>(vec: &mut ~[T], val: T) -> uint { +fn idx_push<T>(vec: &mut ~[T], val: T) -> u32 { vec.push(val); - vec.len() - 1 + (vec.len() - 1) as u32 } /// Resolve a syntax object to a name, per MTWT. @@ -917,7 +917,7 @@ pub fn mtwt_outer_mark(ctxt: SyntaxContext) -> Mrk { /// Push a name... unless it matches the one on top, in which /// case pop and discard (so two of the same marks cancel) -pub fn xorPush(marks: &mut ~[uint], mark: uint) { +pub fn xorPush(marks: &mut ~[Mrk], mark: Mrk) { if ((marks.len() > 0) && (getLast(marks) == mark)) { marks.pop(); } else { @@ -927,7 +927,7 @@ pub fn xorPush(marks: &mut ~[uint], mark: uint) { // get the last element of a mutable array. // FIXME #4903: , must be a separate procedure for now. -pub fn getLast(arr: &~[Mrk]) -> uint { +pub fn getLast(arr: &~[Mrk]) -> Mrk { *arr.last() } @@ -1000,14 +1000,8 @@ mod test { assert_eq!(s.clone(),~[14]); } - // convert a list of uints to an @[ident] - // (ignores the interner completely) - fn uints_to_idents (uints: &~[uint]) -> @~[Ident] { - @uints.map(|u| Ident {name:*u, ctxt: EMPTY_CTXT}) - } - - fn id (u : uint, s: SyntaxContext) -> Ident { - Ident{name:u, ctxt: s} + fn id(n: Name, s: SyntaxContext) -> Ident { + Ident {name: n, ctxt: s} } // because of the SCTable, I now need a tidy way of diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs index 870c1bd74b1..4ad2c9a32c9 100644 --- a/src/libsyntax/parse/token.rs +++ b/src/libsyntax/parse/token.rs @@ -502,12 +502,12 @@ fn mk_fresh_ident_interner() -> @ident_interner { @interner::StrInterner::prefill(init_vec) } -static SELF_KEYWORD_NAME: uint = 8; -static STATIC_KEYWORD_NAME: uint = 27; -static STRICT_KEYWORD_START: uint = 32; -static STRICT_KEYWORD_FINAL: uint = 65; -static RESERVED_KEYWORD_START: uint = 66; -static RESERVED_KEYWORD_FINAL: uint = 72; +static SELF_KEYWORD_NAME: Name = 8; +static STATIC_KEYWORD_NAME: Name = 27; +static STRICT_KEYWORD_START: Name = 32; +static STRICT_KEYWORD_FINAL: Name = 65; +static RESERVED_KEYWORD_START: Name = 66; +static RESERVED_KEYWORD_FINAL: Name = 72; // if an interner exists in TLS, return it. Otherwise, prepare a // fresh one. diff --git a/src/libsyntax/util/interner.rs b/src/libsyntax/util/interner.rs index 82249453ac2..c144b36a86f 100644 --- a/src/libsyntax/util/interner.rs +++ b/src/libsyntax/util/interner.rs @@ -12,15 +12,17 @@ // allows bidirectional lookup; i.e. given a value, one can easily find the // type, and vice versa. +use ast::Name; + use std::cmp::Equiv; use std::hashmap::HashMap; pub struct Interner<T> { - priv map: @mut HashMap<T, uint>, + priv map: @mut HashMap<T, Name>, priv vect: @mut ~[T], } -// when traits can extend traits, we should extend index<uint,T> to get [] +// when traits can extend traits, we should extend index<Name,T> to get [] impl<T:Eq + IterBytes + Hash + Freeze + Clone + 'static> Interner<T> { pub fn new() -> Interner<T> { Interner { @@ -37,37 +39,37 @@ impl<T:Eq + IterBytes + Hash + Freeze + Clone + 'static> Interner<T> { rv } - pub fn intern(&self, val: T) -> uint { + pub fn intern(&self, val: T) -> Name { match self.map.find(&val) { Some(&idx) => return idx, None => (), } let vect = &mut *self.vect; - let new_idx = vect.len(); + let new_idx = vect.len() as Name; self.map.insert(val.clone(), new_idx); vect.push(val); new_idx } - pub fn gensym(&self, val: T) -> uint { + pub fn gensym(&self, val: T) -> Name { let new_idx = { let vect = &*self.vect; - vect.len() + vect.len() as Name }; // leave out of .map to avoid colliding self.vect.push(val); new_idx } - pub fn get(&self, idx: uint) -> T { + pub fn get(&self, idx: Name) -> T { self.vect[idx].clone() } pub fn len(&self) -> uint { let vect = &*self.vect; vect.len() } pub fn find_equiv<Q:Hash + IterBytes + Equiv<T>>(&self, val: &Q) - -> Option<uint> { + -> Option<Name> { match self.map.find_equiv(val) { Some(v) => Some(*v), None => None, @@ -78,11 +80,11 @@ impl<T:Eq + IterBytes + Hash + Freeze + Clone + 'static> Interner<T> { // A StrInterner differs from Interner<String> in that it accepts // borrowed pointers rather than @ ones, resulting in less allocation. pub struct StrInterner { - priv map: @mut HashMap<@str, uint>, + priv map: @mut HashMap<@str, Name>, priv vect: @mut ~[@str], } -// when traits can extend traits, we should extend index<uint,T> to get [] +// when traits can extend traits, we should extend index<Name,T> to get [] impl StrInterner { pub fn new() -> StrInterner { StrInterner { @@ -97,21 +99,21 @@ impl StrInterner { rv } - pub fn intern(&self, val: &str) -> uint { + pub fn intern(&self, val: &str) -> Name { match self.map.find_equiv(&val) { Some(&idx) => return idx, None => (), } - let new_idx = self.len(); + let new_idx = self.len() as Name; let val = val.to_managed(); self.map.insert(val, new_idx); self.vect.push(val); new_idx } - pub fn gensym(&self, val: &str) -> uint { - let new_idx = self.len(); + pub fn gensym(&self, val: &str) -> Name { + let new_idx = self.len() as Name; // leave out of .map to avoid colliding self.vect.push(val.to_managed()); new_idx @@ -127,19 +129,19 @@ impl StrInterner { // create a gensym with the same name as an existing // entry. - pub fn gensym_copy(&self, idx : uint) -> uint { - let new_idx = self.len(); + pub fn gensym_copy(&self, idx : Name) -> Name { + let new_idx = self.len() as Name; // leave out of map to avoid colliding self.vect.push(self.vect[idx]); new_idx } - pub fn get(&self, idx: uint) -> @str { self.vect[idx] } + pub fn get(&self, idx: Name) -> @str { self.vect[idx] } pub fn len(&self) -> uint { let vect = &*self.vect; vect.len() } pub fn find_equiv<Q:Hash + IterBytes + Equiv<@str>>(&self, val: &Q) - -> Option<uint> { + -> Option<Name> { match self.map.find_equiv(val) { Some(v) => Some(*v), None => None, |
