Skip to content

Commit 8a55cd9

Browse files
committed
auto merge of #12711 : edwardw/rust/mtwt, r=pcwalton
- Moves mtwt hygiene code into its own file - Fixes FIXME's which leads to ~2x speed gain in expansion pass - It is now @-free
2 parents db4f757 + 2302ce9 commit 8a55cd9

File tree

8 files changed

+558
-562
lines changed

8 files changed

+558
-562
lines changed

src/librustc/middle/resolve.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ use middle::pat_util::pat_bindings;
1919

2020
use syntax::ast::*;
2121
use syntax::ast;
22-
use syntax::ast_util::{def_id_of_def, local_def, mtwt_resolve};
22+
use syntax::ast_util::{def_id_of_def, local_def};
2323
use syntax::ast_util::{path_to_ident, walk_pat, trait_method_to_ty_method};
24+
use syntax::ext::mtwt;
2425
use syntax::parse::token::special_idents;
2526
use syntax::parse::token;
2627
use syntax::print::pprust::path_to_str;
@@ -4176,7 +4177,7 @@ impl Resolver {
41764177
fn binding_mode_map(&mut self, pat: @Pat) -> BindingMap {
41774178
let mut result = HashMap::new();
41784179
pat_bindings(self.def_map, pat, |binding_mode, _id, sp, path| {
4179-
let name = mtwt_resolve(path_to_ident(path));
4180+
let name = mtwt::resolve(path_to_ident(path));
41804181
result.insert(name,
41814182
binding_info {span: sp,
41824183
binding_mode: binding_mode});
@@ -4411,7 +4412,7 @@ impl Resolver {
44114412
// what you want).
44124413

44134414
let ident = path.segments.get(0).identifier;
4414-
let renamed = mtwt_resolve(ident);
4415+
let renamed = mtwt::resolve(ident);
44154416

44164417
match self.resolve_bare_identifier_pattern(ident) {
44174418
FoundStructOrEnumVariant(def, lp)
@@ -4965,7 +4966,7 @@ impl Resolver {
49654966
let search_result;
49664967
match namespace {
49674968
ValueNS => {
4968-
let renamed = mtwt_resolve(ident);
4969+
let renamed = mtwt::resolve(ident);
49694970
let mut value_ribs = self.value_ribs.borrow_mut();
49704971
search_result = self.search_ribs(value_ribs.get(),
49714972
renamed,
@@ -5213,7 +5214,7 @@ impl Resolver {
52135214
let rib = label_ribs.get()[label_ribs.get().len() -
52145215
1];
52155216
let mut bindings = rib.bindings.borrow_mut();
5216-
let renamed = mtwt_resolve(label);
5217+
let renamed = mtwt::resolve(label);
52175218
bindings.get().insert(renamed, def_like);
52185219
}
52195220

@@ -5225,7 +5226,7 @@ impl Resolver {
52255226

52265227
ExprBreak(Some(label)) | ExprAgain(Some(label)) => {
52275228
let mut label_ribs = self.label_ribs.borrow_mut();
5228-
let renamed = mtwt_resolve(label);
5229+
let renamed = mtwt::resolve(label);
52295230
match self.search_ribs(label_ribs.get(), renamed, expr.span) {
52305231
None =>
52315232
self.resolve_error(expr.span,

src/libsyntax/ast.rs

+4-37
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ use parse::token;
1919

2020
use std::fmt;
2121
use std::fmt::Show;
22-
use std::cell::RefCell;
23-
use collections::HashMap;
2422
use std::option::Option;
2523
use std::rc::Rc;
2624
use std::vec_ng::Vec;
@@ -42,7 +40,10 @@ pub fn P<T: 'static>(value: T) -> P<T> {
4240
// macro expansion per Flatt et al., "Macros
4341
// That Work Together"
4442
#[deriving(Clone, Hash, TotalEq, TotalOrd, Show)]
45-
pub struct Ident { name: Name, ctxt: SyntaxContext }
43+
pub struct Ident {
44+
name: Name,
45+
ctxt: SyntaxContext
46+
}
4647

4748
impl Ident {
4849
/// Construct an identifier with the given name and an empty context:
@@ -88,43 +89,9 @@ impl Eq for Ident {
8889
// this uint is a reference to a table stored in thread-local
8990
// storage.
9091
pub type SyntaxContext = u32;
91-
92-
// the SCTable contains a table of SyntaxContext_'s. It
93-
// represents a flattened tree structure, to avoid having
94-
// managed pointers everywhere (that caused an ICE).
95-
// the mark_memo and rename_memo fields are side-tables
96-
// that ensure that adding the same mark to the same context
97-
// gives you back the same context as before. This shouldn't
98-
// change the semantics--everything here is immutable--but
99-
// it should cut down on memory use *a lot*; applying a mark
100-
// to a tree containing 50 identifiers would otherwise generate
101-
pub struct SCTable {
102-
table: RefCell<Vec<SyntaxContext_> >,
103-
mark_memo: RefCell<HashMap<(SyntaxContext,Mrk),SyntaxContext>>,
104-
rename_memo: RefCell<HashMap<(SyntaxContext,Ident,Name),SyntaxContext>>,
105-
}
106-
107-
// NB: these must be placed in any SCTable...
10892
pub static EMPTY_CTXT : SyntaxContext = 0;
10993
pub static ILLEGAL_CTXT : SyntaxContext = 1;
11094

111-
#[deriving(Eq, Encodable, Decodable, Hash)]
112-
pub enum SyntaxContext_ {
113-
EmptyCtxt,
114-
Mark (Mrk,SyntaxContext),
115-
// flattening the name and syntaxcontext into the rename...
116-
// HIDDEN INVARIANTS:
117-
// 1) the first name in a Rename node
118-
// can only be a programmer-supplied name.
119-
// 2) Every Rename node with a given Name in the
120-
// "to" slot must have the same name and context
121-
// in the "from" slot. In essence, they're all
122-
// pointers to a single "rename" event node.
123-
Rename (Ident,Name,SyntaxContext),
124-
// actually, IllegalCtxt may not be necessary.
125-
IllegalCtxt
126-
}
127-
12895
/// A name is a part of an identifier, representing a string or gensym. It's
12996
/// the result of interning.
13097
pub type Name = u32;

0 commit comments

Comments
 (0)