Skip to content

Refactor and fix FIXME's in mtwt hygiene code #12711

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 5, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions src/librustc/middle/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ use middle::pat_util::pat_bindings;

use syntax::ast::*;
use syntax::ast;
use syntax::ast_util::{def_id_of_def, local_def, mtwt_resolve};
use syntax::ast_util::{def_id_of_def, local_def};
use syntax::ast_util::{path_to_ident, walk_pat, trait_method_to_ty_method};
use syntax::ext::mtwt;
use syntax::parse::token::special_idents;
use syntax::parse::token;
use syntax::print::pprust::path_to_str;
Expand Down Expand Up @@ -4176,7 +4177,7 @@ impl Resolver {
fn binding_mode_map(&mut self, pat: @Pat) -> BindingMap {
let mut result = HashMap::new();
pat_bindings(self.def_map, pat, |binding_mode, _id, sp, path| {
let name = mtwt_resolve(path_to_ident(path));
let name = mtwt::resolve(path_to_ident(path));
result.insert(name,
binding_info {span: sp,
binding_mode: binding_mode});
Expand Down Expand Up @@ -4411,7 +4412,7 @@ impl Resolver {
// what you want).

let ident = path.segments.get(0).identifier;
let renamed = mtwt_resolve(ident);
let renamed = mtwt::resolve(ident);

match self.resolve_bare_identifier_pattern(ident) {
FoundStructOrEnumVariant(def, lp)
Expand Down Expand Up @@ -4965,7 +4966,7 @@ impl Resolver {
let search_result;
match namespace {
ValueNS => {
let renamed = mtwt_resolve(ident);
let renamed = mtwt::resolve(ident);
let mut value_ribs = self.value_ribs.borrow_mut();
search_result = self.search_ribs(value_ribs.get(),
renamed,
Expand Down Expand Up @@ -5213,7 +5214,7 @@ impl Resolver {
let rib = label_ribs.get()[label_ribs.get().len() -
1];
let mut bindings = rib.bindings.borrow_mut();
let renamed = mtwt_resolve(label);
let renamed = mtwt::resolve(label);
bindings.get().insert(renamed, def_like);
}

Expand All @@ -5225,7 +5226,7 @@ impl Resolver {

ExprBreak(Some(label)) | ExprAgain(Some(label)) => {
let mut label_ribs = self.label_ribs.borrow_mut();
let renamed = mtwt_resolve(label);
let renamed = mtwt::resolve(label);
match self.search_ribs(label_ribs.get(), renamed, expr.span) {
None =>
self.resolve_error(expr.span,
Expand Down
41 changes: 4 additions & 37 deletions src/libsyntax/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ use parse::token;

use std::fmt;
use std::fmt::Show;
use std::cell::RefCell;
use collections::HashMap;
use std::option::Option;
use std::rc::Rc;
use std::vec_ng::Vec;
Expand All @@ -42,7 +40,10 @@ pub fn P<T: 'static>(value: T) -> P<T> {
// macro expansion per Flatt et al., "Macros
// That Work Together"
#[deriving(Clone, Hash, TotalEq, TotalOrd, Show)]
pub struct Ident { name: Name, ctxt: SyntaxContext }
pub struct Ident {
name: Name,
ctxt: SyntaxContext
}

impl Ident {
/// Construct an identifier with the given name and an empty context:
Expand Down Expand Up @@ -88,43 +89,9 @@ impl Eq for Ident {
// this uint is a reference to a table stored in thread-local
// storage.
pub type SyntaxContext = u32;

// the SCTable contains a table of SyntaxContext_'s. It
// represents a flattened tree structure, to avoid having
// managed pointers everywhere (that caused an ICE).
// the mark_memo and rename_memo fields are side-tables
// that ensure that adding the same mark to the same context
// gives you back the same context as before. This shouldn't
// change the semantics--everything here is immutable--but
// it should cut down on memory use *a lot*; applying a mark
// to a tree containing 50 identifiers would otherwise generate
pub struct SCTable {
table: RefCell<Vec<SyntaxContext_> >,
mark_memo: RefCell<HashMap<(SyntaxContext,Mrk),SyntaxContext>>,
rename_memo: RefCell<HashMap<(SyntaxContext,Ident,Name),SyntaxContext>>,
}

// NB: these must be placed in any SCTable...
pub static EMPTY_CTXT : SyntaxContext = 0;
pub static ILLEGAL_CTXT : SyntaxContext = 1;

#[deriving(Eq, Encodable, Decodable, Hash)]
pub enum SyntaxContext_ {
EmptyCtxt,
Mark (Mrk,SyntaxContext),
// flattening the name and syntaxcontext into the rename...
// HIDDEN INVARIANTS:
// 1) the first name in a Rename node
// can only be a programmer-supplied name.
// 2) Every Rename node with a given Name in the
// "to" slot must have the same name and context
// in the "from" slot. In essence, they're all
// pointers to a single "rename" event node.
Rename (Ident,Name,SyntaxContext),
// actually, IllegalCtxt may not be necessary.
IllegalCtxt
}

/// A name is a part of an identifier, representing a string or gensym. It's
/// the result of interning.
pub type Name = u32;
Expand Down
Loading