Skip to content

Commit 7ed27b5

Browse files
committed
Shink NodeId, CrateNum, Name and Mrk down to 32 bits on x64.
1 parent b42c438 commit 7ed27b5

File tree

10 files changed

+74
-78
lines changed

10 files changed

+74
-78
lines changed

src/librustc/driver/session.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ use syntax::abi;
2828
use syntax::parse::token;
2929
use syntax;
3030

31-
use std::int;
3231
use std::hashmap::{HashMap,HashSet};
3332

3433
#[deriving(Clone)]
@@ -209,7 +208,7 @@ pub struct Session_ {
209208
building_library: @mut bool,
210209
working_dir: Path,
211210
lints: @mut HashMap<ast::NodeId, ~[(lint::lint, codemap::Span, ~str)]>,
212-
node_id: @mut uint,
211+
node_id: @mut ast::NodeId,
213212
}
214213

215214
pub type Session = @Session_;
@@ -274,13 +273,15 @@ impl Session_ {
274273
pub fn next_node_id(&self) -> ast::NodeId {
275274
self.reserve_node_ids(1)
276275
}
277-
pub fn reserve_node_ids(&self, count: uint) -> ast::NodeId {
276+
pub fn reserve_node_ids(&self, count: ast::NodeId) -> ast::NodeId {
278277
let v = *self.node_id;
279-
*self.node_id += count;
280-
if v > (int::max_value as uint) {
281-
self.bug("Input too large, ran out of node ids!");
278+
279+
match v.checked_add(&count) {
280+
Some(next) => { *self.node_id = next; }
281+
None => self.bug("Input too large, ran out of node ids!")
282282
}
283-
v as int
283+
284+
v
284285
}
285286
pub fn diagnostic(&self) -> @mut diagnostic::span_handler {
286287
self.span_diagnostic

src/librustc/metadata/creader.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ impl visit::Visitor<()> for ReadCrateVisitor {
6767

6868
#[deriving(Clone)]
6969
struct cache_entry {
70-
cnum: int,
70+
cnum: ast::CrateNum,
7171
span: Span,
7272
hash: @str,
7373
metas: @~[@ast::MetaItem]
@@ -242,7 +242,7 @@ fn metas_with_ident(ident: @str, metas: ~[@ast::MetaItem])
242242
}
243243

244244
fn existing_match(e: &Env, metas: &[@ast::MetaItem], hash: &str)
245-
-> Option<int> {
245+
-> Option<ast::CrateNum> {
246246
for c in e.crate_cache.iter() {
247247
if loader::metadata_matches(*c.metas, metas)
248248
&& (hash.is_empty() || c.hash.as_slice() == hash) {

src/librustc/metadata/decoder.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -76,18 +76,18 @@ fn lookup_hash(d: ebml::Doc, eq_fn: |&[u8]| -> bool, hash: u64) ->
7676

7777
pub type GetCrateDataCb<'self> = &'self fn(ast::CrateNum) -> Cmd;
7878

79-
pub fn maybe_find_item(item_id: int, items: ebml::Doc) -> Option<ebml::Doc> {
80-
fn eq_item(bytes: &[u8], item_id: int) -> bool {
79+
pub fn maybe_find_item(item_id: ast::NodeId, items: ebml::Doc) -> Option<ebml::Doc> {
80+
fn eq_item(bytes: &[u8], item_id: ast::NodeId) -> bool {
8181
return u64_from_be_bytes(
82-
bytes.slice(0u, 4u), 0u, 4u) as int
82+
bytes.slice(0u, 4u), 0u, 4u) as ast::NodeId
8383
== item_id;
8484
}
8585
lookup_hash(items,
8686
|a| eq_item(a, item_id),
8787
(item_id as i64).hash())
8888
}
8989

90-
fn find_item(item_id: int, items: ebml::Doc) -> ebml::Doc {
90+
fn find_item(item_id: ast::NodeId, items: ebml::Doc) -> ebml::Doc {
9191
match maybe_find_item(item_id, items) {
9292
None => fail!("lookup_item: id not found: {}", item_id),
9393
Some(d) => d
@@ -96,7 +96,7 @@ fn find_item(item_id: int, items: ebml::Doc) -> ebml::Doc {
9696

9797
// Looks up an item in the given metadata and returns an ebml doc pointing
9898
// to the item data.
99-
pub fn lookup_item(item_id: int, data: @~[u8]) -> ebml::Doc {
99+
pub fn lookup_item(item_id: ast::NodeId, data: @~[u8]) -> ebml::Doc {
100100
let items = reader::get_doc(reader::Doc(data), tag_items);
101101
find_item(item_id, items)
102102
}
@@ -343,7 +343,7 @@ fn item_name(intr: @ident_interner, item: ebml::Doc) -> ast::Ident {
343343
let string = name.as_str_slice();
344344
match intr.find_equiv(&string) {
345345
None => token::str_to_ident(string),
346-
Some(val) => ast::Ident::new(val),
346+
Some(val) => ast::Ident::new(val as ast::Name),
347347
}
348348
}
349349

src/librustc/metadata/tydecode.rs

+13-13
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ type conv_did<'self> =
5858

5959
pub struct PState<'self> {
6060
data: &'self [u8],
61-
crate: int,
61+
crate: ast::CrateNum,
6262
pos: uint,
6363
tcx: ty::ctxt
6464
}
@@ -101,7 +101,7 @@ fn parse_ident_(st: &mut PState, is_last: |char| -> bool) -> ast::Ident {
101101
return st.tcx.sess.ident_of(rslt);
102102
}
103103

104-
pub fn parse_state_from_data<'a>(data: &'a [u8], crate_num: int,
104+
pub fn parse_state_from_data<'a>(data: &'a [u8], crate_num: ast::CrateNum,
105105
pos: uint, tcx: ty::ctxt) -> PState<'a> {
106106
PState {
107107
data: data,
@@ -111,19 +111,19 @@ pub fn parse_state_from_data<'a>(data: &'a [u8], crate_num: int,
111111
}
112112
}
113113

114-
pub fn parse_ty_data(data: &[u8], crate_num: int, pos: uint, tcx: ty::ctxt,
114+
pub fn parse_ty_data(data: &[u8], crate_num: ast::CrateNum, pos: uint, tcx: ty::ctxt,
115115
conv: conv_did) -> ty::t {
116116
let mut st = parse_state_from_data(data, crate_num, pos, tcx);
117117
parse_ty(&mut st, conv)
118118
}
119119

120-
pub fn parse_bare_fn_ty_data(data: &[u8], crate_num: int, pos: uint, tcx: ty::ctxt,
120+
pub fn parse_bare_fn_ty_data(data: &[u8], crate_num: ast::CrateNum, pos: uint, tcx: ty::ctxt,
121121
conv: conv_did) -> ty::BareFnTy {
122122
let mut st = parse_state_from_data(data, crate_num, pos, tcx);
123123
parse_bare_fn_ty(&mut st, conv)
124124
}
125125

126-
pub fn parse_trait_ref_data(data: &[u8], crate_num: int, pos: uint, tcx: ty::ctxt,
126+
pub fn parse_trait_ref_data(data: &[u8], crate_num: ast::CrateNum, pos: uint, tcx: ty::ctxt,
127127
conv: conv_did) -> ty::TraitRef {
128128
let mut st = parse_state_from_data(data, crate_num, pos, tcx);
129129
parse_trait_ref(&mut st, conv)
@@ -251,15 +251,15 @@ fn parse_region(st: &mut PState, conv: conv_did) -> ty::Region {
251251
match next(st) {
252252
'b' => {
253253
assert_eq!(next(st), '[');
254-
let id = parse_uint(st) as int;
254+
let id = parse_uint(st) as ast::NodeId;
255255
assert_eq!(next(st), '|');
256256
let br = parse_bound_region(st, |x,y| conv(x,y));
257257
assert_eq!(next(st), ']');
258258
ty::ReLateBound(id, br)
259259
}
260260
'B' => {
261261
assert_eq!(next(st), '[');
262-
let node_id = parse_uint(st) as int;
262+
let node_id = parse_uint(st) as ast::NodeId;
263263
assert_eq!(next(st), '|');
264264
let index = parse_uint(st);
265265
assert_eq!(next(st), '|');
@@ -268,15 +268,15 @@ fn parse_region(st: &mut PState, conv: conv_did) -> ty::Region {
268268
}
269269
'f' => {
270270
assert_eq!(next(st), '[');
271-
let id = parse_uint(st) as int;
271+
let id = parse_uint(st) as ast::NodeId;
272272
assert_eq!(next(st), '|');
273273
let br = parse_bound_region(st, |x,y| conv(x,y));
274274
assert_eq!(next(st), ']');
275275
ty::ReFree(ty::FreeRegion {scope_id: id,
276276
bound_region: br})
277277
}
278278
's' => {
279-
let id = parse_uint(st) as int;
279+
let id = parse_uint(st) as ast::NodeId;
280280
assert_eq!(next(st), '|');
281281
ty::ReScope(id)
282282
}
@@ -539,7 +539,7 @@ fn parse_bare_fn_ty(st: &mut PState, conv: conv_did) -> ty::BareFnTy {
539539

540540
fn parse_sig(st: &mut PState, conv: conv_did) -> ty::FnSig {
541541
assert_eq!(next(st), '[');
542-
let id = parse_uint(st) as int;
542+
let id = parse_uint(st) as ast::NodeId;
543543
assert_eq!(next(st), '|');
544544
let mut inputs = ~[];
545545
while peek(st) != ']' {
@@ -572,20 +572,20 @@ pub fn parse_def_id(buf: &[u8]) -> ast::DefId {
572572
let def_part = buf.slice(colon_idx + 1u, len);
573573

574574
let crate_num = match uint::parse_bytes(crate_part, 10u) {
575-
Some(cn) => cn as int,
575+
Some(cn) => cn as ast::CrateNum,
576576
None => fail!("internal error: parse_def_id: crate number expected, but found {:?}",
577577
crate_part)
578578
};
579579
let def_num = match uint::parse_bytes(def_part, 10u) {
580-
Some(dn) => dn as int,
580+
Some(dn) => dn as ast::NodeId,
581581
None => fail!("internal error: parse_def_id: id expected, but found {:?}",
582582
def_part)
583583
};
584584
ast::DefId { crate: crate_num, node: def_num }
585585
}
586586

587587
pub fn parse_type_param_def_data(data: &[u8], start: uint,
588-
crate_num: int, tcx: ty::ctxt,
588+
crate_num: ast::CrateNum, tcx: ty::ctxt,
589589
conv: conv_did) -> ty::TypeParameterDef
590590
{
591591
let mut st = parse_state_from_data(data, crate_num, start, tcx);

src/librustc/middle/astencode.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,7 @@ fn reserve_id_range(sess: Session,
161161
// Handle the case of an empty range:
162162
if from_id_range.empty() { return from_id_range; }
163163
let cnt = from_id_range.max - from_id_range.min;
164-
assert!(cnt >= 0);
165-
let to_id_min = sess.reserve_node_ids(cnt as uint);
164+
let to_id_min = sess.reserve_node_ids(cnt);
166165
let to_id_max = to_id_min + cnt;
167166
ast_util::id_range { min: to_id_min, max: to_id_max }
168167
}
@@ -1210,7 +1209,7 @@ fn decode_side_tables(xcx: @ExtendedDecodeContext,
12101209
let tbl_doc = ast_doc.get(c::tag_table as uint);
12111210
do reader::docs(tbl_doc) |tag, entry_doc| {
12121211
let id0 = entry_doc.get(c::tag_table_id as uint).as_int();
1213-
let id = xcx.tr_id(id0);
1212+
let id = xcx.tr_id(id0 as ast::NodeId);
12141213

12151214
debug!(">> Side table document with tag 0x{:x} \
12161215
found for id {} (orig {})",

src/librustc/middle/ty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ pub struct field_ty {
169169
// the types of AST nodes.
170170
#[deriving(Eq,IterBytes)]
171171
pub struct creader_cache_key {
172-
cnum: int,
172+
cnum: CrateNum,
173173
pos: uint,
174174
len: uint
175175
}

src/libsyntax/ast.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ impl Eq for Ident {
6969

7070
// this uint is a reference to a table stored in thread-local
7171
// storage.
72-
pub type SyntaxContext = uint;
72+
pub type SyntaxContext = u32;
7373

7474
// the SCTable contains a table of SyntaxContext_'s. It
7575
// represents a flattened tree structure, to avoid having
@@ -87,8 +87,8 @@ pub struct SCTable {
8787
}
8888

8989
// NB: these must be placed in any SCTable...
90-
pub static EMPTY_CTXT : uint = 0;
91-
pub static ILLEGAL_CTXT : uint = 1;
90+
pub static EMPTY_CTXT : SyntaxContext = 0;
91+
pub static ILLEGAL_CTXT : SyntaxContext = 1;
9292

9393
#[deriving(Eq, Encodable, Decodable,IterBytes)]
9494
pub enum SyntaxContext_ {
@@ -109,10 +109,10 @@ pub enum SyntaxContext_ {
109109

110110
/// A name is a part of an identifier, representing a string or gensym. It's
111111
/// the result of interning.
112-
pub type Name = uint;
112+
pub type Name = u32;
113113

114114
/// A mark represents a unique id associated with a macro expansion
115-
pub type Mrk = uint;
115+
pub type Mrk = u32;
116116

117117
impl<S:Encoder> Encodable<S> for Ident {
118118
fn encode(&self, s: &mut S) {
@@ -163,9 +163,9 @@ pub struct PathSegment {
163163
types: OptVec<Ty>,
164164
}
165165

166-
pub type CrateNum = int;
166+
pub type CrateNum = u32;
167167

168-
pub type NodeId = int;
168+
pub type NodeId = u32;
169169

170170
#[deriving(Clone, TotalEq, TotalOrd, Eq, Encodable, Decodable, IterBytes, ToStr)]
171171
pub struct DefId {

src/libsyntax/ast_util.rs

+9-15
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use visit::Visitor;
1818
use visit;
1919

2020
use std::hashmap::HashMap;
21-
use std::int;
21+
use std::u32;
2222
use std::local_data;
2323
use std::num;
2424
use std::option;
@@ -382,8 +382,8 @@ pub struct id_range {
382382
impl id_range {
383383
pub fn max() -> id_range {
384384
id_range {
385-
min: int::max_value,
386-
max: int::min_value,
385+
min: u32::max_value,
386+
max: u32::min_value,
387387
}
388388
}
389389

@@ -803,9 +803,9 @@ pub fn display_sctable(table : &SCTable) {
803803

804804

805805
/// Add a value to the end of a vec, return its index
806-
fn idx_push<T>(vec: &mut ~[T], val: T) -> uint {
806+
fn idx_push<T>(vec: &mut ~[T], val: T) -> u32 {
807807
vec.push(val);
808-
vec.len() - 1
808+
(vec.len() - 1) as u32
809809
}
810810

811811
/// Resolve a syntax object to a name, per MTWT.
@@ -917,7 +917,7 @@ pub fn mtwt_outer_mark(ctxt: SyntaxContext) -> Mrk {
917917

918918
/// Push a name... unless it matches the one on top, in which
919919
/// case pop and discard (so two of the same marks cancel)
920-
pub fn xorPush(marks: &mut ~[uint], mark: uint) {
920+
pub fn xorPush(marks: &mut ~[Mrk], mark: Mrk) {
921921
if ((marks.len() > 0) && (getLast(marks) == mark)) {
922922
marks.pop();
923923
} else {
@@ -927,7 +927,7 @@ pub fn xorPush(marks: &mut ~[uint], mark: uint) {
927927

928928
// get the last element of a mutable array.
929929
// FIXME #4903: , must be a separate procedure for now.
930-
pub fn getLast(arr: &~[Mrk]) -> uint {
930+
pub fn getLast(arr: &~[Mrk]) -> Mrk {
931931
*arr.last()
932932
}
933933

@@ -1000,14 +1000,8 @@ mod test {
10001000
assert_eq!(s.clone(),~[14]);
10011001
}
10021002

1003-
// convert a list of uints to an @[ident]
1004-
// (ignores the interner completely)
1005-
fn uints_to_idents (uints: &~[uint]) -> @~[Ident] {
1006-
@uints.map(|u| Ident {name:*u, ctxt: EMPTY_CTXT})
1007-
}
1008-
1009-
fn id (u : uint, s: SyntaxContext) -> Ident {
1010-
Ident{name:u, ctxt: s}
1003+
fn id(n: Name, s: SyntaxContext) -> Ident {
1004+
Ident {name: n, ctxt: s}
10111005
}
10121006

10131007
// because of the SCTable, I now need a tidy way of

src/libsyntax/parse/token.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -502,12 +502,12 @@ fn mk_fresh_ident_interner() -> @ident_interner {
502502
@interner::StrInterner::prefill(init_vec)
503503
}
504504

505-
static SELF_KEYWORD_NAME: uint = 8;
506-
static STATIC_KEYWORD_NAME: uint = 27;
507-
static STRICT_KEYWORD_START: uint = 32;
508-
static STRICT_KEYWORD_FINAL: uint = 65;
509-
static RESERVED_KEYWORD_START: uint = 66;
510-
static RESERVED_KEYWORD_FINAL: uint = 72;
505+
static SELF_KEYWORD_NAME: Name = 8;
506+
static STATIC_KEYWORD_NAME: Name = 27;
507+
static STRICT_KEYWORD_START: Name = 32;
508+
static STRICT_KEYWORD_FINAL: Name = 65;
509+
static RESERVED_KEYWORD_START: Name = 66;
510+
static RESERVED_KEYWORD_FINAL: Name = 72;
511511

512512
// if an interner exists in TLS, return it. Otherwise, prepare a
513513
// fresh one.

0 commit comments

Comments
 (0)