diff options
| author | bors <bors@rust-lang.org> | 2013-06-05 13:10:45 -0700 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2013-06-05 13:10:45 -0700 |
| commit | 0409f8610612e8261a0139ec9c57396089cea060 (patch) | |
| tree | adb67739bc831dd5487911eb2f721613ecc0aa9f /src/libsyntax/parse/mod.rs | |
| parent | c5fea4a6738cea28402c905cd81d6f2eb8d355ea (diff) | |
| parent | 91b652695b97c5aef51fdc37c0111b0453ee584e (diff) | |
auto merge of #6938 : jbclements/rust/hygiene_fns_and_cleanup, r=jbclements
I'm close to flipping the switch on hygiene for let-bound identifiers. This commit adds a bunch of support functions for that change... but also a huge amount of cleanup in syntax.rc. The most interesting of these are - the use of TLS for the interners everywhere. We had already breached the "no-global-state" dam by using TLS for encoding, and it saves a lot of code just to use it everywhere. Also, there were many places where two or more interners were passed in attached to different structures, and the danger of having those diverge seemed greater that the danger of having a single one get big and heavy. If the interner size proves to be a problem, it should be quite simple to add a "parameterize"-like dynamic binding form--because we don't have interesting continuation operations (or tail calling, mostly) this should just be a case of a mutation followed by another later mutation. Again, this is only if the interner gets too big. - I renamed the "repr" field of the identifier to "name". I can see the case for "repr" when there's only one field in the structure, but that's no longer the case; there's now a name and a context (both are uints). - the interner now just maps between strings and uints, rather than between idents and uints. The former state made perfect sense when identifiers didn't have syntax contexts, but that's no longer the case. I've run this patch against a fairly recent incoming, and it appears to pass all tests. Let's see if it can be merged....
Diffstat (limited to 'src/libsyntax/parse/mod.rs')
| -rw-r--r-- | src/libsyntax/parse/mod.rs | 46 |
1 files changed, 16 insertions, 30 deletions
diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index 9c716f5631f..d7248204e1c 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -19,7 +19,6 @@ use diagnostic::{span_handler, mk_span_handler, mk_handler, Emitter}; use parse::attr::parser_attr; use parse::lexer::reader; use parse::parser::Parser; -use parse::token::{ident_interner, get_ident_interner}; use core::io; use core::option::{None, Option, Some}; @@ -43,14 +42,10 @@ pub mod classify; pub mod obsolete; // info about a parsing session. -// This structure and the reader both have -// an interner associated with them. If they're -// not the same, bad things can happen. pub struct ParseSess { cm: @codemap::CodeMap, // better be the same as the one in the reader! next_id: node_id, span_diagnostic: @span_handler, // better be the same as the one in the reader! - interner: @ident_interner, } pub fn new_parse_sess(demitter: Option<Emitter>) -> @mut ParseSess { @@ -59,7 +54,6 @@ pub fn new_parse_sess(demitter: Option<Emitter>) -> @mut ParseSess { cm: cm, next_id: 1, span_diagnostic: mk_span_handler(mk_handler(demitter), cm), - interner: get_ident_interner(), } } @@ -70,7 +64,6 @@ pub fn new_parse_sess_special_handler(sh: @span_handler, cm: cm, next_id: 1, span_diagnostic: sh, - interner: get_ident_interner(), } } @@ -312,9 +305,7 @@ pub fn filemap_to_tts(sess: @mut ParseSess, filemap: @FileMap) // it appears to me that the cfg doesn't matter here... indeed, // parsing tt's probably shouldn't require a parser at all. let cfg = ~[]; - let srdr = lexer::new_string_reader(copy sess.span_diagnostic, - filemap, - sess.interner); + let srdr = lexer::new_string_reader(copy sess.span_diagnostic, filemap); let p1 = Parser(sess, cfg, srdr as @reader); p1.parse_all_token_trees() } @@ -325,7 +316,6 @@ pub fn tts_to_parser(sess: @mut ParseSess, cfg: ast::crate_cfg) -> Parser { let trdr = lexer::new_tt_reader( copy sess.span_diagnostic, - sess.interner, None, tts ); @@ -351,12 +341,13 @@ mod test { use codemap::{span, BytePos, spanned}; use opt_vec; use ast; + use ast::{new_ident}; use abi; use parse::parser::Parser; - use parse::token::intern; - use util::parser_testing::{string_to_tts_and_sess,string_to_parser}; + use parse::token::{intern, str_to_ident}; + use util::parser_testing::{string_to_tts_and_sess, string_to_parser}; use util::parser_testing::{string_to_expr, string_to_item}; - use util::parser_testing::{string_to_stmt}; + use util::parser_testing::{string_to_stmt, strs_to_idents}; // map a string to tts, return the tt without its parsesess fn string_to_tts_only(source_str : @~str) -> ~[ast::token_tree] { @@ -377,17 +368,12 @@ mod test { span{lo:BytePos(a),hi:BytePos(b),expn_info:None} } - // convert a vector of uints to a vector of ast::idents - fn ints_to_idents(ids: ~[~str]) -> ~[ast::ident] { - ids.map(|u| intern(*u)) - } - #[test] fn path_exprs_1 () { assert_eq!(string_to_expr(@~"a"), @ast::expr{id:1, node:ast::expr_path(@ast::Path {span:sp(0,1), global:false, - idents:~[intern("a")], + idents:~[str_to_ident("a")], rp:None, types:~[]}), span:sp(0,1)}) @@ -399,7 +385,7 @@ mod test { node:ast::expr_path( @ast::Path {span:sp(0,6), global:true, - idents:ints_to_idents(~[~"a",~"b"]), + idents:strs_to_idents(~["a","b"]), rp:None, types:~[]}), span:sp(0,6)}) @@ -449,7 +435,7 @@ mod test { node:ast::expr_path( @ast::Path{span:sp(7,8), global:false, - idents:~[intern("d")], + idents:~[str_to_ident("d")], rp:None, types:~[] }), @@ -466,7 +452,7 @@ mod test { @ast::Path{ span:sp(0,1), global:false, - idents:~[intern("b")], + idents:~[str_to_ident("b")], rp:None, types: ~[]}), span: sp(0,1)}, @@ -487,7 +473,7 @@ mod test { @ast::Path{ span:sp(0,1), global:false, - idents:~[intern("b")], + idents:~[str_to_ident("b")], rp: None, types: ~[]}, None // no idea @@ -506,7 +492,7 @@ mod test { span:sp(4,4), // this is bizarre... // check this in the original parser? global:false, - idents:~[intern("int")], + idents:~[str_to_ident("int")], rp: None, types: ~[]}, 2), @@ -516,7 +502,7 @@ mod test { @ast::Path{ span:sp(0,1), global:false, - idents:~[intern("b")], + idents:~[str_to_ident("b")], rp: None, types: ~[]}, None // no idea @@ -532,7 +518,7 @@ mod test { // assignment order of the node_ids. assert_eq!(string_to_item(@~"fn a (b : int) { b; }"), Some( - @ast::item{ident:intern("a"), + @ast::item{ident:str_to_ident("a"), attrs:~[], id: 9, // fixme node: ast::item_fn(ast::fn_decl{ @@ -542,7 +528,7 @@ mod test { node: ast::ty_path(@ast::Path{ span:sp(10,13), global:false, - idents:~[intern("int")], + idents:~[str_to_ident("int")], rp: None, types: ~[]}, 2), @@ -553,7 +539,7 @@ mod test { @ast::Path{ span:sp(6,7), global:false, - idents:~[intern("b")], + idents:~[str_to_ident("b")], rp: None, types: ~[]}, None // no idea @@ -583,7 +569,7 @@ mod test { @ast::Path{ span:sp(17,18), global:false, - idents:~[intern("b")], + idents:~[str_to_ident("b")], rp:None, types: ~[]}), span: sp(17,18)}, |
