Skip to content

Commit 1153b5d

Browse files
committed
intern identifiers
1 parent 7317bf8 commit 1153b5d

Some content is hidden

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

94 files changed

+1662
-1464
lines changed

src/cargo/cargo.rs

+17-15
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ fn load_link(mis: ~[@ast::meta_item]) -> (option<~str>,
225225
for mis.each |a| {
226226
match a.node {
227227
ast::meta_name_value(v, {node: ast::lit_str(s), span: _}) => {
228-
match *v {
228+
match v {
229229
~"name" => name = some(*s),
230230
~"vers" => vers = some(*s),
231231
~"uuid" => uuid = some(*s),
@@ -252,15 +252,15 @@ fn load_crate(filename: ~str) -> option<crate> {
252252
for c.node.attrs.each |a| {
253253
match a.node.value.node {
254254
ast::meta_name_value(v, {node: ast::lit_str(s), span: _}) => {
255-
match *v {
256-
~"desc" => desc = some(*v),
257-
~"sigs" => sigs = some(*v),
258-
~"crate_type" => crate_type = some(*v),
255+
match v {
256+
~"desc" => desc = some(v),
257+
~"sigs" => sigs = some(v),
258+
~"crate_type" => crate_type = some(v),
259259
_ => { }
260260
}
261261
}
262262
ast::meta_list(v, mis) => {
263-
if *v == ~"link" {
263+
if v == ~"link" {
264264
let (n, v, u) = load_link(mis);
265265
name = n;
266266
vers = v;
@@ -278,13 +278,15 @@ fn load_crate(filename: ~str) -> option<crate> {
278278
mut deps: ~[~str]
279279
};
280280

281-
fn goto_view_item(e: env, i: @ast::view_item) {
281+
fn goto_view_item(ps: syntax::parse::parse_sess, e: env,
282+
i: @ast::view_item) {
282283
match i.node {
283284
ast::view_item_use(ident, metas, id) => {
284285
let name_items =
285286
attr::find_meta_items_by_name(metas, ~"name");
286287
let m = if name_items.is_empty() {
287-
metas + ~[attr::mk_name_value_item_str(@~"name", *ident)]
288+
metas + ~[attr::mk_name_value_item_str(
289+
~"name", *ps.interner.get(ident))]
288290
} else {
289291
metas
290292
};
@@ -297,9 +299,9 @@ fn load_crate(filename: ~str) -> option<crate> {
297299
some(value) => {
298300
let name = attr::get_meta_item_name(item);
299301

300-
match *name {
301-
~"vers" => attr_vers = *value,
302-
~"from" => attr_from = *value,
302+
match name {
303+
~"vers" => attr_vers = value,
304+
~"from" => attr_from = value,
303305
_ => ()
304306
}
305307
}
@@ -311,11 +313,11 @@ fn load_crate(filename: ~str) -> option<crate> {
311313
attr_from
312314
} else {
313315
if !str::is_empty(attr_vers) {
314-
*attr_name + ~"@" + attr_vers
315-
} else { *attr_name }
316+
ps.interner.get(attr_name) + ~"@" + attr_vers
317+
} else { *ps.interner.get(attr_name) }
316318
};
317319

318-
match *attr_name {
320+
match *ps.interner.get(attr_name) {
319321
~"std" | ~"core" => (),
320322
_ => vec::push(e.deps, query)
321323
}
@@ -330,7 +332,7 @@ fn load_crate(filename: ~str) -> option<crate> {
330332
mut deps: ~[]
331333
};
332334
let v = visit::mk_simple_visitor(@{
333-
visit_view_item: |a| goto_view_item(e, a),
335+
visit_view_item: |a| goto_view_item(sess, e, a),
334336
visit_item: |a| goto_item(e, a),
335337
with *visit::default_simple_visitor()
336338
});

src/fuzzer/fuzzer.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -238,29 +238,31 @@ fn check_variants_T<T: copy>(
238238
filename: ~str,
239239
thing_label: ~str,
240240
things: ~[T],
241-
stringifier: fn@(@T) -> ~str,
241+
stringifier: fn@(@T, syntax::parse::token::ident_interner) -> ~str,
242242
replacer: fn@(ast::crate, uint, T, test_mode) -> ast::crate,
243243
cx: context
244244
) {
245245
error!{"%s contains %u %s objects", filename,
246246
vec::len(things), thing_label};
247247

248+
// Assuming we're not generating any token_trees
249+
let intr = syntax::parse::token::mk_fake_ident_interner();
250+
248251
let L = vec::len(things);
249252

250253
if L < 100u {
251254
do under(uint::min(L, 20u)) |i| {
252255
log(error, ~"Replacing... #" + uint::str(i));
253256
do under(uint::min(L, 30u)) |j| {
254-
log(error, ~"With... " + stringifier(@things[j]));
257+
log(error, ~"With... " + stringifier(@things[j], intr));
255258
let crate2 = @replacer(crate, i, things[j], cx.mode);
256259
// It would be best to test the *crate* for stability, but
257260
// testing the string for stability is easier and ok for now.
258261
let handler = diagnostic::mk_handler(none);
259262
let str3 =
260263
@as_str(|a|pprust::print_crate(
261264
codemap,
262-
// Assuming we're not generating any token_trees
263-
syntax::parse::token::mk_ident_interner(),
265+
intr,
264266
diagnostic::mk_span_handler(handler, codemap),
265267
crate2,
266268
filename,
@@ -422,7 +424,7 @@ fn parse_and_print(code: @~str) -> ~str {
422424
pprust::print_crate(
423425
sess.cm,
424426
// Assuming there are no token_trees
425-
syntax::parse::token::mk_ident_interner(),
427+
syntax::parse::token::mk_fake_ident_interner(),
426428
sess.span_diagnostic,
427429
crate,
428430
filename,
@@ -570,7 +572,7 @@ fn check_variants(files: ~[~str], cx: context) {
570572
as_str(|a| pprust::print_crate(
571573
sess.cm,
572574
// Assuming no token_trees
573-
syntax::parse::token::mk_ident_interner(),
575+
syntax::parse::token::mk_fake_ident_interner(),
574576
sess.span_diagnostic,
575577
crate,
576578
file,

src/libsyntax/ast.rs

+15-35
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,18 @@ fn deserialize_span<D>(_d: D) -> span {
3030
#[auto_serialize]
3131
type spanned<T> = {node: T, span: span};
3232

33-
#[auto_serialize]
34-
type ident = @~str;
33+
fn serialize_ident<S: serializer>(s: S, i: ident) {
34+
let intr = unsafe{ task::local_data_get(parse::token::interner_key) };
35+
36+
s.emit_str(*(*intr.get()).get(i));
37+
}
38+
fn deserialize_ident<D: deserializer>(d: D) -> ident {
39+
let intr = unsafe{ task::local_data_get(parse::token::interner_key) };
40+
41+
(*intr.get()).intern(@d.read_str())
42+
}
43+
44+
type ident = token::str_num;
3545

3646
// Functions may or may not have names.
3747
#[auto_serialize]
@@ -127,9 +137,9 @@ type meta_item = spanned<meta_item_>;
127137

128138
#[auto_serialize]
129139
enum meta_item_ {
130-
meta_word(ident),
131-
meta_list(ident, ~[@meta_item]),
132-
meta_name_value(ident, lit),
140+
meta_word(~str),
141+
meta_list(~str, ~[@meta_item]),
142+
meta_name_value(~str, lit),
133143
}
134144

135145
#[auto_serialize]
@@ -815,36 +825,6 @@ enum inlined_item {
815825
ii_dtor(class_dtor, ident, ~[ty_param], def_id /* parent id */)
816826
}
817827

818-
// Convenience functions
819-
820-
pure fn simple_path(id: ident, span: span) -> @path {
821-
@{span: span,
822-
global: false,
823-
idents: ~[id],
824-
rp: none,
825-
types: ~[]}
826-
}
827-
828-
pure fn empty_span() -> span {
829-
{lo: 0, hi: 0, expn_info: none}
830-
}
831-
832-
// Convenience implementations
833-
834-
impl ident: ops::add<ident,@path> {
835-
pure fn add(&&id: ident) -> @path {
836-
simple_path(self, empty_span()) + id
837-
}
838-
}
839-
840-
impl @path: ops::add<ident,@path> {
841-
pure fn add(&&id: ident) -> @path {
842-
@{
843-
idents: vec::append_one(self.idents, id)
844-
with *self
845-
}
846-
}
847-
}
848828

849829
//
850830
// Local Variables:

src/libsyntax/ast_map.rs

+19-18
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,33 @@ import ast::*;
44
import print::pprust;
55
import ast_util::{path_to_ident, stmt_id};
66
import diagnostic::span_handler;
7+
import parse::token::ident_interner;
78

89
enum path_elt { path_mod(ident), path_name(ident) }
910
type path = ~[path_elt];
1011

1112
/* FIXMEs that say "bad" are as per #2543 */
12-
fn path_to_str_with_sep(p: path, sep: ~str) -> ~str {
13+
fn path_to_str_with_sep(p: path, sep: ~str, itr: ident_interner) -> ~str {
1314
let strs = do vec::map(p) |e| {
1415
match e {
15-
path_mod(s) => /* FIXME (#2543) */ copy *s,
16-
path_name(s) => /* FIXME (#2543) */ copy *s
16+
path_mod(s) => *itr.get(s),
17+
path_name(s) => *itr.get(s)
1718
}
1819
};
1920
str::connect(strs, sep)
2021
}
2122

22-
fn path_ident_to_str(p: path, i: ident) -> ~str {
23+
fn path_ident_to_str(p: path, i: ident, itr: ident_interner) -> ~str {
2324
if vec::is_empty(p) {
24-
/* FIXME (#2543) */ copy *i
25+
//FIXME /* FIXME (#2543) */ copy *i
26+
*itr.get(i)
2527
} else {
26-
fmt!{"%s::%s", path_to_str(p), *i}
28+
fmt!{"%s::%s", path_to_str(p, itr), *itr.get(i)}
2729
}
2830
}
2931

30-
fn path_to_str(p: path) -> ~str {
31-
path_to_str_with_sep(p, ~"::")
32+
fn path_to_str(p: path, itr: ident_interner) -> ~str {
33+
path_to_str_with_sep(p, ~"::", itr)
3234
}
3335

3436
enum ast_node {
@@ -291,43 +293,42 @@ fn map_stmt(stmt: @stmt, cx: ctx, v: vt) {
291293
visit::visit_stmt(stmt, cx, v);
292294
}
293295

294-
fn node_id_to_str(map: map, id: node_id) -> ~str {
296+
fn node_id_to_str(map: map, id: node_id, itr: ident_interner) -> ~str {
295297
match map.find(id) {
296298
none => {
297299
fmt!{"unknown node (id=%d)", id}
298300
}
299301
some(node_item(item, path)) => {
300-
fmt!{"item %s (id=%?)", path_ident_to_str(*path, item.ident), id}
302+
fmt!{"item %s (id=%?)", path_ident_to_str(*path, item.ident, itr), id}
301303
}
302304
some(node_foreign_item(item, abi, path)) => {
303305
fmt!{"foreign item %s with abi %? (id=%?)",
304-
path_ident_to_str(*path, item.ident), abi, id}
306+
path_ident_to_str(*path, item.ident, itr), abi, id}
305307
}
306308
some(node_method(m, impl_did, path)) => {
307309
fmt!{"method %s in %s (id=%?)",
308-
*m.ident, path_to_str(*path), id}
310+
*itr.get(m.ident), path_to_str(*path, itr), id}
309311
}
310312
some(node_trait_method(tm, impl_did, path)) => {
311313
let m = ast_util::trait_method_to_ty_method(*tm);
312314
fmt!{"method %s in %s (id=%?)",
313-
*m.ident, path_to_str(*path), id}
315+
*itr.get(m.ident), path_to_str(*path, itr), id}
314316
}
315317
some(node_variant(variant, def_id, path)) => {
316318
fmt!{"variant %s in %s (id=%?)",
317-
*variant.node.name, path_to_str(*path), id}
319+
*itr.get(variant.node.name), path_to_str(*path, itr), id}
318320
}
319321
some(node_expr(expr)) => {
320-
fmt!{"expr %s (id=%?)",
321-
pprust::expr_to_str(expr), id}
322+
fmt!{"expr %s (id=%?)", pprust::expr_to_str(expr, itr), id}
322323
}
323324
some(node_stmt(stmt)) => {
324325
fmt!{"stmt %s (id=%?)",
325-
pprust::stmt_to_str(*stmt), id}
326+
pprust::stmt_to_str(*stmt, itr), id}
326327
}
327328
// FIXMEs are as per #2410
328329
some(node_export(_, path)) => {
329330
fmt!{"export %s (id=%?)", // add more info here
330-
path_to_str(*path), id}
331+
path_to_str(*path, itr), id}
331332
}
332333
some(node_arg(_, _)) => { // add more info here
333334
fmt!{"arg (id=%?)", id}

src/libsyntax/ast_util.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,14 @@ pure fn mk_sp(lo: uint, hi: uint) -> span {
2121
// make this a const, once the compiler supports it
2222
pure fn dummy_sp() -> span { return mk_sp(0u, 0u); }
2323

24-
pure fn path_name(p: @path) -> ~str { path_name_i(p.idents) }
2524

26-
pure fn path_name_i(idents: ~[ident]) -> ~str {
25+
26+
pure fn path_name_i(idents: ~[ident], intr: token::ident_interner) -> ~str {
2727
// FIXME: Bad copies (#2543 -- same for everything else that says "bad")
28-
str::connect(idents.map(|i|*i), ~"::")
28+
str::connect(idents.map(|i| *intr.get(i)), ~"::")
2929
}
3030

31+
3132
pure fn path_to_ident(p: @path) -> ident { vec::last(p.idents) }
3233

3334
pure fn local_def(id: node_id) -> def_id { {crate: local_crate, node: id} }
@@ -408,7 +409,8 @@ fn dtor_dec() -> fn_decl {
408409
let nil_t = @{id: 0, node: ty_nil, span: dummy_sp()};
409410
// dtor has one argument, of type ()
410411
{inputs: ~[{mode: ast::expl(ast::by_ref),
411-
ty: nil_t, ident: @~"_", id: 0}],
412+
ty: nil_t, ident: parse::token::special_idents::underscore,
413+
id: 0}],
412414
output: nil_t, purity: impure_fn, cf: return_val}
413415
}
414416

0 commit comments

Comments
 (0)