1
Fork 0

update librustc to use name comparison in most cases, and mtwt_resolve comparison in others

This commit is contained in:
John Clements 2013-06-26 15:56:13 -07:00
parent 71e72ee862
commit 39ca2dbbc5
10 changed files with 124 additions and 114 deletions

View file

@ -23,7 +23,7 @@ use middle::pat_util::pat_bindings;
use syntax::ast::*; use syntax::ast::*;
use syntax::ast; use syntax::ast;
use syntax::ast_util::{def_id_of_def, local_def}; use syntax::ast_util::{def_id_of_def, local_def}; // mtwt_resolve
use syntax::ast_util::{path_to_ident, walk_pat, trait_method_to_ty_method}; use syntax::ast_util::{path_to_ident, walk_pat, trait_method_to_ty_method};
use syntax::ast_util::{Privacy, Public, Private}; use syntax::ast_util::{Privacy, Public, Private};
use syntax::ast_util::{variant_visibility_to_privacy, visibility_to_privacy}; use syntax::ast_util::{variant_visibility_to_privacy, visibility_to_privacy};
@ -51,7 +51,7 @@ pub struct binding_info {
} }
// Map from the name in a pattern to its binding mode. // Map from the name in a pattern to its binding mode.
pub type BindingMap = HashMap<Ident,binding_info>; pub type BindingMap = HashMap<Name,binding_info>;
// Trait method resolution // Trait method resolution
pub type TraitMap = HashMap<NodeId,@mut ~[DefId]>; pub type TraitMap = HashMap<NodeId,@mut ~[DefId]>;
@ -445,12 +445,12 @@ pub struct Module {
def_id: Option<DefId>, def_id: Option<DefId>,
kind: ModuleKind, kind: ModuleKind,
children: @mut HashMap<Ident, @mut NameBindings>, children: @mut HashMap<Name, @mut NameBindings>,
imports: @mut ~[@ImportDirective], imports: @mut ~[@ImportDirective],
// The external module children of this node that were declared with // The external module children of this node that were declared with
// `extern mod`. // `extern mod`.
external_module_children: @mut HashMap<Ident, @mut Module>, external_module_children: @mut HashMap<Name, @mut Module>,
// The anonymous children of this node. Anonymous children are pseudo- // The anonymous children of this node. Anonymous children are pseudo-
// modules that are implicitly created around items contained within // modules that are implicitly created around items contained within
@ -469,7 +469,7 @@ pub struct Module {
anonymous_children: @mut HashMap<NodeId,@mut Module>, anonymous_children: @mut HashMap<NodeId,@mut Module>,
// The status of resolving each import in this module. // The status of resolving each import in this module.
import_resolutions: @mut HashMap<Ident, @mut ImportResolution>, import_resolutions: @mut HashMap<Name, @mut ImportResolution>,
// The number of unresolved globs that this module exports. // The number of unresolved globs that this module exports.
glob_count: uint, glob_count: uint,
@ -759,15 +759,14 @@ pub fn NameBindings() -> NameBindings {
/// Interns the names of the primitive types. /// Interns the names of the primitive types.
pub struct PrimitiveTypeTable { pub struct PrimitiveTypeTable {
primitive_types: HashMap<Ident,prim_ty>, primitive_types: HashMap<Name,prim_ty>,
} }
impl PrimitiveTypeTable { impl PrimitiveTypeTable {
pub fn intern(&mut self, pub fn intern(&mut self,
string: &str, string: &str,
primitive_type: prim_ty) { primitive_type: prim_ty) {
let ident = token::str_to_ident(string); self.primitive_types.insert(token::intern(string), primitive_type);
self.primitive_types.insert(ident, primitive_type);
} }
} }
@ -873,7 +872,7 @@ pub struct Resolver {
graph_root: @mut NameBindings, graph_root: @mut NameBindings,
method_map: @mut HashMap<Ident, HashSet<DefId>>, method_map: @mut HashMap<Name, HashSet<DefId>>,
structs: HashSet<DefId>, structs: HashSet<DefId>,
// The number of imports that are currently unresolved. // The number of imports that are currently unresolved.
@ -1036,10 +1035,10 @@ impl Resolver {
// Add or reuse the child. // Add or reuse the child.
let new_parent = ModuleReducedGraphParent(module_); let new_parent = ModuleReducedGraphParent(module_);
match module_.children.find(&name) { match module_.children.find(&name.name) {
None => { None => {
let child = @mut NameBindings(); let child = @mut NameBindings();
module_.children.insert(name, child); module_.children.insert(name.name, child);
return (child, new_parent); return (child, new_parent);
} }
Some(&child) => { Some(&child) => {
@ -1307,7 +1306,7 @@ impl Resolver {
} if path.segments.len() == 1 => { } if path.segments.len() == 1 => {
let name = path_to_ident(path); let name = path_to_ident(path);
let new_parent = match parent.children.find(&name) { let new_parent = match parent.children.find(&name.name) {
// It already exists // It already exists
Some(&child) if child.get_module_if_available() Some(&child) if child.get_module_if_available()
.is_some() && .is_some() &&
@ -1426,7 +1425,7 @@ impl Resolver {
match ty_m.explicit_self.node { match ty_m.explicit_self.node {
sty_static => {} sty_static => {}
_ => { _ => {
method_names.insert(ident, ()); method_names.insert(ident.name, ());
} }
} }
} }
@ -1582,7 +1581,7 @@ impl Resolver {
false); false);
parent.external_module_children.insert( parent.external_module_children.insert(
name, name.name,
external_module); external_module);
self.build_reduced_graph_for_external_crate( self.build_reduced_graph_for_external_crate(
@ -1727,7 +1726,7 @@ impl Resolver {
// Add it to the trait info if not static. // Add it to the trait info if not static.
if explicit_self != sty_static { if explicit_self != sty_static {
interned_method_names.insert(method_name); interned_method_names.insert(method_name.name);
} }
} }
for name in interned_method_names.iter() { for name in interned_method_names.iter() {
@ -1981,7 +1980,7 @@ impl Resolver {
self.idents_to_str(directive.module_path), self.idents_to_str(directive.module_path),
self.session.str_of(target)); self.session.str_of(target));
match module_.import_resolutions.find(&target) { match module_.import_resolutions.find(&target.name) {
Some(&resolution) => { Some(&resolution) => {
debug!("(building import directive) bumping \ debug!("(building import directive) bumping \
reference"); reference");
@ -1996,7 +1995,7 @@ impl Resolver {
debug!("(building import directive) creating new"); debug!("(building import directive) creating new");
let resolution = @mut ImportResolution::new(privacy, id); let resolution = @mut ImportResolution::new(privacy, id);
resolution.outstanding_references = 1; resolution.outstanding_references = 1;
module_.import_resolutions.insert(target, resolution); module_.import_resolutions.insert(target.name, resolution);
} }
} }
} }
@ -2281,7 +2280,7 @@ impl Resolver {
// Search for direct children of the containing module. // Search for direct children of the containing module.
self.populate_module_if_necessary(containing_module); self.populate_module_if_necessary(containing_module);
match containing_module.children.find(&source) { match containing_module.children.find(&source.name) {
None => { None => {
// Continue. // Continue.
} }
@ -2315,7 +2314,7 @@ impl Resolver {
// Now search the exported imports within the containing // Now search the exported imports within the containing
// module. // module.
match containing_module.import_resolutions.find(&source) { match containing_module.import_resolutions.find(&source.name) {
None => { None => {
// The containing module definitely doesn't have an // The containing module definitely doesn't have an
// exported import with the name in question. We can // exported import with the name in question. We can
@ -2386,7 +2385,7 @@ impl Resolver {
BoundResult(*) => {} BoundResult(*) => {}
_ => { _ => {
match containing_module.external_module_children match containing_module.external_module_children
.find(&source) { .find(&source.name) {
None => {} // Continue. None => {} // Continue.
Some(module) => { Some(module) => {
let name_bindings = let name_bindings =
@ -2400,8 +2399,8 @@ impl Resolver {
} }
// We've successfully resolved the import. Write the results in. // We've successfully resolved the import. Write the results in.
assert!(module_.import_resolutions.contains_key(&target)); assert!(module_.import_resolutions.contains_key(&target.name));
let import_resolution = module_.import_resolutions.get(&target); let import_resolution = module_.import_resolutions.get(&target.name);
match value_result { match value_result {
BoundResult(target_module, name_bindings) => { BoundResult(target_module, name_bindings) => {
@ -2563,15 +2562,15 @@ impl Resolver {
} }
} }
let merge_import_resolution = |ident, let merge_import_resolution = |name,
name_bindings: @mut NameBindings| { name_bindings: @mut NameBindings| {
let dest_import_resolution; let dest_import_resolution;
match module_.import_resolutions.find(&ident) { match module_.import_resolutions.find(&name) {
None => { None => {
// Create a new import resolution from this child. // Create a new import resolution from this child.
dest_import_resolution = @mut ImportResolution::new(privacy, id); dest_import_resolution = @mut ImportResolution::new(privacy, id);
module_.import_resolutions.insert module_.import_resolutions.insert
(ident, dest_import_resolution); (name, dest_import_resolution);
} }
Some(&existing_import_resolution) => { Some(&existing_import_resolution) => {
dest_import_resolution = existing_import_resolution; dest_import_resolution = existing_import_resolution;
@ -2580,7 +2579,7 @@ impl Resolver {
debug!("(resolving glob import) writing resolution `%s` in `%s` \ debug!("(resolving glob import) writing resolution `%s` in `%s` \
to `%s`, privacy=%?", to `%s`, privacy=%?",
self.session.str_of(ident), interner_get(name),
self.module_to_str(containing_module), self.module_to_str(containing_module),
self.module_to_str(module_), self.module_to_str(module_),
dest_import_resolution.privacy); dest_import_resolution.privacy);
@ -2602,15 +2601,15 @@ impl Resolver {
// Add all children from the containing module. // Add all children from the containing module.
self.populate_module_if_necessary(containing_module); self.populate_module_if_necessary(containing_module);
for (&ident, name_bindings) in containing_module.children.iter() { for (&name, name_bindings) in containing_module.children.iter() {
merge_import_resolution(ident, *name_bindings); merge_import_resolution(name, *name_bindings);
} }
// Add external module children from the containing module. // Add external module children from the containing module.
for (&ident, module) in containing_module.external_module_children.iter() { for (&name, module) in containing_module.external_module_children.iter() {
let name_bindings = let name_bindings =
@mut Resolver::create_name_bindings_from_module(*module); @mut Resolver::create_name_bindings_from_module(*module);
merge_import_resolution(ident, name_bindings); merge_import_resolution(name, name_bindings);
} }
debug!("(resolving glob import) successfully resolved import"); debug!("(resolving glob import) successfully resolved import");
@ -2836,7 +2835,7 @@ impl Resolver {
// The current module node is handled specially. First, check for // The current module node is handled specially. First, check for
// its immediate children. // its immediate children.
self.populate_module_if_necessary(module_); self.populate_module_if_necessary(module_);
match module_.children.find(&name) { match module_.children.find(&name.name) {
Some(name_bindings) Some(name_bindings)
if name_bindings.defined_in_namespace(namespace) => { if name_bindings.defined_in_namespace(namespace) => {
return Success(Target::new(module_, *name_bindings)); return Success(Target::new(module_, *name_bindings));
@ -2848,7 +2847,7 @@ impl Resolver {
// all its imports in the usual way; this is because chains of // all its imports in the usual way; this is because chains of
// adjacent import statements are processed as though they mutated the // adjacent import statements are processed as though they mutated the
// current scope. // current scope.
match module_.import_resolutions.find(&name) { match module_.import_resolutions.find(&name.name) {
None => { None => {
// Not found; continue. // Not found; continue.
} }
@ -2872,7 +2871,7 @@ impl Resolver {
// Search for external modules. // Search for external modules.
if namespace == TypeNS { if namespace == TypeNS {
match module_.external_module_children.find(&name) { match module_.external_module_children.find(&name.name) {
None => {} None => {}
Some(module) => { Some(module) => {
let name_bindings = let name_bindings =
@ -3034,8 +3033,9 @@ impl Resolver {
} }
} }
/// Resolves a "module prefix". A module prefix is one of (a) `self::`; /// Resolves a "module prefix". A module prefix is one or both of (a) `self::`;
/// (b) some chain of `super::`. /// (b) some chain of `super::`.
/// grammar: (SELF MOD_SEP ) ? (SUPER MOD_SEP) *
pub fn resolve_module_prefix(@mut self, pub fn resolve_module_prefix(@mut self,
module_: @mut Module, module_: @mut Module,
module_path: &[Ident]) module_path: &[Ident])
@ -3091,7 +3091,7 @@ impl Resolver {
// First, check the direct children of the module. // First, check the direct children of the module.
self.populate_module_if_necessary(module_); self.populate_module_if_necessary(module_);
match module_.children.find(&name) { match module_.children.find(&name.name) {
Some(name_bindings) Some(name_bindings)
if name_bindings.defined_in_namespace(namespace) => { if name_bindings.defined_in_namespace(namespace) => {
debug!("(resolving name in module) found node as child"); debug!("(resolving name in module) found node as child");
@ -3112,7 +3112,7 @@ impl Resolver {
} }
// Check the list of resolved imports. // Check the list of resolved imports.
match module_.import_resolutions.find(&name) { match module_.import_resolutions.find(&name.name) {
Some(import_resolution) => { Some(import_resolution) => {
if import_resolution.privacy == Public && if import_resolution.privacy == Public &&
import_resolution.outstanding_references != 0 { import_resolution.outstanding_references != 0 {
@ -3147,7 +3147,7 @@ impl Resolver {
// Finally, search through external children. // Finally, search through external children.
if namespace == TypeNS { if namespace == TypeNS {
match module_.external_module_children.find(&name) { match module_.external_module_children.find(&name.name) {
None => {} None => {}
Some(module) => { Some(module) => {
let name_bindings = let name_bindings =
@ -3273,7 +3273,7 @@ impl Resolver {
pub fn add_exports_of_namebindings(@mut self, pub fn add_exports_of_namebindings(@mut self,
exports2: &mut ~[Export2], exports2: &mut ~[Export2],
ident: Ident, name: Name,
namebindings: @mut NameBindings, namebindings: @mut NameBindings,
ns: Namespace, ns: Namespace,
reexport: bool) { reexport: bool) {
@ -3282,11 +3282,11 @@ impl Resolver {
(Some(d), Some(Public)) => { (Some(d), Some(Public)) => {
debug!("(computing exports) YES: %s '%s' => %?", debug!("(computing exports) YES: %s '%s' => %?",
if reexport { ~"reexport" } else { ~"export"}, if reexport { ~"reexport" } else { ~"export"},
self.session.str_of(ident), interner_get(name),
def_id_of_def(d)); def_id_of_def(d));
exports2.push(Export2 { exports2.push(Export2 {
reexport: reexport, reexport: reexport,
name: self.session.str_of(ident), name: interner_get(name),
def_id: def_id_of_def(d) def_id: def_id_of_def(d)
}); });
} }
@ -3302,10 +3302,10 @@ impl Resolver {
pub fn add_exports_for_module(@mut self, pub fn add_exports_for_module(@mut self,
exports2: &mut ~[Export2], exports2: &mut ~[Export2],
module_: @mut Module) { module_: @mut Module) {
for (ident, importresolution) in module_.import_resolutions.iter() { for (name, importresolution) in module_.import_resolutions.iter() {
if importresolution.privacy != Public { if importresolution.privacy != Public {
debug!("(computing exports) not reexporting private `%s`", debug!("(computing exports) not reexporting private `%s`",
self.session.str_of(*ident)); interner_get(*name));
loop; loop;
} }
let xs = [TypeNS, ValueNS]; let xs = [TypeNS, ValueNS];
@ -3313,9 +3313,9 @@ impl Resolver {
match importresolution.target_for_namespace(*ns) { match importresolution.target_for_namespace(*ns) {
Some(target) => { Some(target) => {
debug!("(computing exports) maybe reexport '%s'", debug!("(computing exports) maybe reexport '%s'",
self.session.str_of(*ident)); interner_get(*name));
self.add_exports_of_namebindings(&mut *exports2, self.add_exports_of_namebindings(&mut *exports2,
*ident, *name,
target.bindings, target.bindings,
*ns, *ns,
true) true)
@ -3354,7 +3354,7 @@ impl Resolver {
} }
Some(name) => { Some(name) => {
self.populate_module_if_necessary(orig_module); self.populate_module_if_necessary(orig_module);
match orig_module.children.find(&name) { match orig_module.children.find(&name.name) {
None => { None => {
debug!("!!! (with scope) didn't find `%s` in `%s`", debug!("!!! (with scope) didn't find `%s` in `%s`",
self.session.str_of(name), self.session.str_of(name),
@ -3498,7 +3498,7 @@ impl Resolver {
pub fn search_ribs(@mut self, pub fn search_ribs(@mut self,
ribs: &mut ~[@Rib], ribs: &mut ~[@Rib],
name: Ident, name: Name,
span: Span, span: Span,
allow_capturing_self: AllowCapturingSelfFlag) allow_capturing_self: AllowCapturingSelfFlag)
-> Option<DefLike> { -> Option<DefLike> {
@ -3508,7 +3508,7 @@ impl Resolver {
let mut i = ribs.len(); let mut i = ribs.len();
while i != 0 { while i != 0 {
i -= 1; i -= 1;
match ribs[i].bindings.find(&name.name) { match ribs[i].bindings.find(&name) {
Some(&def_like) => { Some(&def_like) => {
return self.upvarify(ribs, i, def_like, span, return self.upvarify(ribs, i, def_like, span,
allow_capturing_self); allow_capturing_self);
@ -3591,7 +3591,9 @@ impl Resolver {
// Create a new rib for the self type. // Create a new rib for the self type.
let self_type_rib = @Rib::new(NormalRibKind); let self_type_rib = @Rib::new(NormalRibKind);
self.type_ribs.push(self_type_rib); self.type_ribs.push(self_type_rib);
self_type_rib.bindings.insert(self.type_self_ident.name, // plain insert (no renaming)
let name = self.type_self_ident.name;
self_type_rib.bindings.insert(name,
DlDef(DefSelfTy(item.id))); DlDef(DefSelfTy(item.id)));
// Create a new rib for the trait-wide type parameters. // Create a new rib for the trait-wide type parameters.
@ -3733,6 +3735,7 @@ impl Resolver {
// the item that bound it // the item that bound it
self.record_def(type_parameter.id, self.record_def(type_parameter.id,
DefTyParamBinder(node_id)); DefTyParamBinder(node_id));
// plain insert (no renaming)
function_type_rib.bindings.insert(ident.name, def_like); function_type_rib.bindings.insert(ident.name, def_like);
} }
} }
@ -4067,8 +4070,8 @@ impl Resolver {
pub fn binding_mode_map(@mut self, pat: @Pat) -> BindingMap { pub fn binding_mode_map(@mut self, pat: @Pat) -> BindingMap {
let mut result = HashMap::new(); let mut result = HashMap::new();
do pat_bindings(self.def_map, pat) |binding_mode, _id, sp, path| { do pat_bindings(self.def_map, pat) |binding_mode, _id, sp, path| {
let ident = path_to_ident(path); let name = path_to_ident(path).name; // mtwt_resolve(path_to_ident(path));
result.insert(ident, result.insert(name,
binding_info {span: sp, binding_info {span: sp,
binding_mode: binding_mode}); binding_mode: binding_mode});
} }
@ -4088,7 +4091,7 @@ impl Resolver {
p.span, p.span,
fmt!("variable `%s` from pattern #1 is \ fmt!("variable `%s` from pattern #1 is \
not bound in pattern #%u", not bound in pattern #%u",
self.session.str_of(key), i + 1)); interner_get(key), i + 1));
} }
Some(binding_i) => { Some(binding_i) => {
if binding_0.binding_mode != binding_i.binding_mode { if binding_0.binding_mode != binding_i.binding_mode {
@ -4096,7 +4099,7 @@ impl Resolver {
binding_i.span, binding_i.span,
fmt!("variable `%s` is bound with different \ fmt!("variable `%s` is bound with different \
mode in pattern #%u than in pattern #1", mode in pattern #%u than in pattern #1",
self.session.str_of(key), i + 1)); interner_get(key), i + 1));
} }
} }
} }
@ -4108,7 +4111,7 @@ impl Resolver {
binding.span, binding.span,
fmt!("variable `%s` from pattern #%u is \ fmt!("variable `%s` from pattern #%u is \
not bound in pattern #1", not bound in pattern #1",
self.session.str_of(key), i + 1)); interner_get(key), i + 1));
} }
} }
} }
@ -4170,11 +4173,11 @@ impl Resolver {
// First, check to see whether the name is a primitive type. // First, check to see whether the name is a primitive type.
if path.segments.len() == 1 { if path.segments.len() == 1 {
let name = path.segments.last().identifier; let id = path.segments.last().identifier;
match self.primitive_type_table match self.primitive_type_table
.primitive_types .primitive_types
.find(&name) { .find(&id.name) {
Some(&primitive_type) => { Some(&primitive_type) => {
result_def = result_def =
@ -4272,7 +4275,7 @@ impl Resolver {
mutability: Mutability, mutability: Mutability,
// Maps idents to the node ID for the (outermost) // Maps idents to the node ID for the (outermost)
// pattern that binds them // pattern that binds them
bindings_list: Option<@mut HashMap<Ident,NodeId>>, bindings_list: Option<@mut HashMap<Name,NodeId>>,
visitor: &mut ResolveVisitor) { visitor: &mut ResolveVisitor) {
let pat_id = pattern.id; let pat_id = pattern.id;
do walk_pat(pattern) |pattern| { do walk_pat(pattern) |pattern| {
@ -4290,13 +4293,14 @@ impl Resolver {
// what you want). // what you want).
let ident = path.segments[0].identifier; let ident = path.segments[0].identifier;
let renamed = ident.name; // mtwt_resolve(ident);
match self.resolve_bare_identifier_pattern(ident) { match self.resolve_bare_identifier_pattern(ident) {
FoundStructOrEnumVariant(def) FoundStructOrEnumVariant(def)
if mode == RefutableMode => { if mode == RefutableMode => {
debug!("(resolving pattern) resolving `%s` to \ debug!("(resolving pattern) resolving `%s` to \
struct or enum variant", struct or enum variant",
self.session.str_of(ident)); interner_get(renamed));
self.enforce_default_binding_mode( self.enforce_default_binding_mode(
pattern, pattern,
@ -4310,13 +4314,12 @@ impl Resolver {
shadows an enum \ shadows an enum \
variant or unit-like \ variant or unit-like \
struct in scope", struct in scope",
self.session interner_get(renamed)));
.str_of(ident)));
} }
FoundConst(def) if mode == RefutableMode => { FoundConst(def) if mode == RefutableMode => {
debug!("(resolving pattern) resolving `%s` to \ debug!("(resolving pattern) resolving `%s` to \
constant", constant",
self.session.str_of(ident)); interner_get(renamed));
self.enforce_default_binding_mode( self.enforce_default_binding_mode(
pattern, pattern,
@ -4331,7 +4334,7 @@ impl Resolver {
} }
BareIdentifierPatternUnresolved => { BareIdentifierPatternUnresolved => {
debug!("(resolving pattern) binding `%s`", debug!("(resolving pattern) binding `%s`",
self.session.str_of(ident)); interner_get(renamed));
let is_mutable = mutability == Mutable; let is_mutable = mutability == Mutable;
@ -4366,16 +4369,16 @@ impl Resolver {
match bindings_list { match bindings_list {
Some(bindings_list) Some(bindings_list)
if !bindings_list.contains_key(&ident) => { if !bindings_list.contains_key(&renamed) => {
let this = &mut *self; let this = &mut *self;
let last_rib = this.value_ribs[ let last_rib = this.value_ribs[
this.value_ribs.len() - 1]; this.value_ribs.len() - 1];
last_rib.bindings.insert(ident.name, last_rib.bindings.insert(renamed,
DlDef(def)); DlDef(def));
bindings_list.insert(ident, pat_id); bindings_list.insert(renamed, pat_id);
} }
Some(b) => { Some(b) => {
if b.find(&ident) == Some(&pat_id) { if b.find(&renamed) == Some(&pat_id) {
// Then this is a duplicate variable // Then this is a duplicate variable
// in the same disjunct, which is an // in the same disjunct, which is an
// error // error
@ -4391,7 +4394,7 @@ impl Resolver {
let this = &mut *self; let this = &mut *self;
let last_rib = this.value_ribs[ let last_rib = this.value_ribs[
this.value_ribs.len() - 1]; this.value_ribs.len() - 1];
last_rib.bindings.insert(ident.name, last_rib.bindings.insert(renamed,
DlDef(def)); DlDef(def));
} }
} }
@ -4640,7 +4643,7 @@ impl Resolver {
-> NameDefinition { -> NameDefinition {
// First, search children. // First, search children.
self.populate_module_if_necessary(containing_module); self.populate_module_if_necessary(containing_module);
match containing_module.children.find(&name) { match containing_module.children.find(&name.name) {
Some(child_name_bindings) => { Some(child_name_bindings) => {
match (child_name_bindings.def_for_namespace(namespace), match (child_name_bindings.def_for_namespace(namespace),
child_name_bindings.privacy_for_namespace(namespace)) { child_name_bindings.privacy_for_namespace(namespace)) {
@ -4663,7 +4666,7 @@ impl Resolver {
} }
// Next, search import resolutions. // Next, search import resolutions.
match containing_module.import_resolutions.find(&name) { match containing_module.import_resolutions.find(&name.name) {
Some(import_resolution) if import_resolution.privacy == Public || Some(import_resolution) if import_resolution.privacy == Public ||
xray == Xray => { xray == Xray => {
match (*import_resolution).target_for_namespace(namespace) { match (*import_resolution).target_for_namespace(namespace) {
@ -4691,7 +4694,7 @@ impl Resolver {
// Finally, search through external children. // Finally, search through external children.
if namespace == TypeNS { if namespace == TypeNS {
match containing_module.external_module_children.find(&name) { match containing_module.external_module_children.find(&name.name) {
None => {} None => {}
Some(module) => { Some(module) => {
match module.def_id { match module.def_id {
@ -4738,9 +4741,9 @@ impl Resolver {
} }
} }
let name = path.segments.last().identifier; let ident = path.segments.last().identifier;
let def = match self.resolve_definition_of_name_in_module(containing_module, let def = match self.resolve_definition_of_name_in_module(containing_module,
name, ident,
namespace, namespace,
xray) { xray) {
NoNameDefinition => { NoNameDefinition => {
@ -4753,7 +4756,7 @@ impl Resolver {
}; };
match containing_module.kind { match containing_module.kind {
TraitModuleKind | ImplModuleKind => { TraitModuleKind | ImplModuleKind => {
match self.method_map.find(&name) { match self.method_map.find(&ident.name) {
Some(s) => { Some(s) => {
match containing_module.def_id { match containing_module.def_id {
Some(def_id) if s.contains(&def_id) => { Some(def_id) if s.contains(&def_id) => {
@ -4830,12 +4833,14 @@ impl Resolver {
let search_result; let search_result;
match namespace { match namespace {
ValueNS => { ValueNS => {
search_result = self.search_ribs(self.value_ribs, ident, let renamed = ident.name; // mtwt_resolve(ident);
search_result = self.search_ribs(self.value_ribs, renamed,
span, span,
DontAllowCapturingSelf); DontAllowCapturingSelf);
} }
TypeNS => { TypeNS => {
search_result = self.search_ribs(self.type_ribs, ident, let name = ident.name;
search_result = self.search_ribs(self.type_ribs, name,
span, AllowCapturingSelf); span, AllowCapturingSelf);
} }
} }
@ -5135,6 +5140,7 @@ impl Resolver {
let this = &mut *self; let this = &mut *self;
let def_like = DlDef(DefLabel(expr.id)); let def_like = DlDef(DefLabel(expr.id));
let rib = this.label_ribs[this.label_ribs.len() - 1]; let rib = this.label_ribs[this.label_ribs.len() - 1];
// plain insert (no renaming)
rib.bindings.insert(label.name, def_like); rib.bindings.insert(label.name, def_like);
} }
@ -5145,7 +5151,8 @@ impl Resolver {
ExprForLoop(*) => fail!("non-desugared expr_for_loop"), ExprForLoop(*) => fail!("non-desugared expr_for_loop"),
ExprBreak(Some(label)) | ExprAgain(Some(label)) => { ExprBreak(Some(label)) | ExprAgain(Some(label)) => {
match self.search_ribs(self.label_ribs, label, expr.span, let name = label.name;
match self.search_ribs(self.label_ribs, name, expr.span,
DontAllowCapturingSelf) { DontAllowCapturingSelf) {
None => None =>
self.resolve_error(expr.span, self.resolve_error(expr.span,
@ -5273,7 +5280,7 @@ impl Resolver {
let mut found_traits = ~[]; let mut found_traits = ~[];
let mut search_module = self.current_module; let mut search_module = self.current_module;
match self.method_map.find(&name) { match self.method_map.find(&name.name) {
Some(candidate_traits) => loop { Some(candidate_traits) => loop {
// Look for the current trait. // Look for the current trait.
match self.current_trait_refs { match self.current_trait_refs {
@ -5495,7 +5502,7 @@ impl Resolver {
debug!("Children:"); debug!("Children:");
self.populate_module_if_necessary(module_); self.populate_module_if_necessary(module_);
for (&name, _) in module_.children.iter() { for (&name, _) in module_.children.iter() {
debug!("* %s", self.session.str_of(name)); debug!("* %s", interner_get(name));
} }
debug!("Import resolutions:"); debug!("Import resolutions:");
@ -5518,7 +5525,7 @@ impl Resolver {
} }
} }
debug!("* %s:%s%s", self.session.str_of(*name), debug!("* %s:%s%s", interner_get(*name),
value_repr, type_repr); value_repr, type_repr);
} }
} }

View file

@ -1482,7 +1482,7 @@ fn compile_submatch_continue(mut bcx: @mut Block,
let pat_repr = adt::represent_type(bcx.ccx(), pat_ty); let pat_repr = adt::represent_type(bcx.ccx(), pat_ty);
do expr::with_field_tys(tcx, pat_ty, None) |discr, field_tys| { do expr::with_field_tys(tcx, pat_ty, None) |discr, field_tys| {
let rec_vals = rec_fields.map(|field_name| { let rec_vals = rec_fields.map(|field_name| {
let ix = ty::field_idx_strict(tcx, *field_name, field_tys); let ix = ty::field_idx_strict(tcx, field_name.name, field_tys);
adt::trans_field_ptr(bcx, pat_repr, val, discr, ix) adt::trans_field_ptr(bcx, pat_repr, val, discr, ix)
}); });
compile_submatch( compile_submatch(
@ -2159,7 +2159,7 @@ fn bind_irrefutable_pat(bcx: @mut Block,
let pat_repr = adt::represent_type(bcx.ccx(), pat_ty); let pat_repr = adt::represent_type(bcx.ccx(), pat_ty);
do expr::with_field_tys(tcx, pat_ty, None) |discr, field_tys| { do expr::with_field_tys(tcx, pat_ty, None) |discr, field_tys| {
for f in fields.iter() { for f in fields.iter() {
let ix = ty::field_idx_strict(tcx, f.ident, field_tys); let ix = ty::field_idx_strict(tcx, f.ident.name, field_tys);
let fldptr = adt::trans_field_ptr(bcx, pat_repr, val, let fldptr = adt::trans_field_ptr(bcx, pat_repr, val,
discr, ix); discr, ix);
bcx = bind_irrefutable_pat(bcx, f.pat, fldptr, binding_mode); bcx = bind_irrefutable_pat(bcx, f.pat, fldptr, binding_mode);

View file

@ -374,7 +374,7 @@ fn const_expr_unadjusted(cx: @mut CrateContext, e: &ast::Expr) -> ValueRef {
let brepr = adt::represent_type(cx, bt); let brepr = adt::represent_type(cx, bt);
let bv = const_expr(cx, base); let bv = const_expr(cx, base);
do expr::with_field_tys(cx.tcx, bt, None) |discr, field_tys| { do expr::with_field_tys(cx.tcx, bt, None) |discr, field_tys| {
let ix = ty::field_idx_strict(cx.tcx, field, field_tys); let ix = ty::field_idx_strict(cx.tcx, field.name, field_tys);
adt::const_get_field(cx, brepr, bv, discr, ix) adt::const_get_field(cx, brepr, bv, discr, ix)
} }
} }
@ -502,7 +502,7 @@ fn const_expr_unadjusted(cx: @mut CrateContext, e: &ast::Expr) -> ValueRef {
|discr, field_tys| { |discr, field_tys| {
let cs: ~[ValueRef] = field_tys.iter().enumerate() let cs: ~[ValueRef] = field_tys.iter().enumerate()
.map(|(ix, &field_ty)| { .map(|(ix, &field_ty)| {
match fs.iter().find(|f| field_ty.ident == f.ident) { match fs.iter().find(|f| field_ty.ident.name == f.ident.name) {
Some(f) => const_expr(cx, (*f).expr), Some(f) => const_expr(cx, (*f).expr),
None => { None => {
match base_val { match base_val {

View file

@ -903,7 +903,7 @@ fn trans_lvalue_unadjusted(bcx: @mut Block, expr: @ast::Expr) -> DatumBlock {
let base_datum = unpack_datum!(bcx, trans_to_datum(bcx, base)); let base_datum = unpack_datum!(bcx, trans_to_datum(bcx, base));
let repr = adt::represent_type(bcx.ccx(), base_datum.ty); let repr = adt::represent_type(bcx.ccx(), base_datum.ty);
do with_field_tys(bcx.tcx(), base_datum.ty, None) |discr, field_tys| { do with_field_tys(bcx.tcx(), base_datum.ty, None) |discr, field_tys| {
let ix = ty::field_idx_strict(bcx.tcx(), field, field_tys); let ix = ty::field_idx_strict(bcx.tcx(), field.name, field_tys);
DatumBlock { DatumBlock {
datum: do base_datum.get_element(bcx, datum: do base_datum.get_element(bcx,
field_tys[ix].mt.ty, field_tys[ix].mt.ty,
@ -1176,7 +1176,8 @@ fn trans_rec_or_struct(bcx: @mut Block,
let mut need_base = vec::from_elem(field_tys.len(), true); let mut need_base = vec::from_elem(field_tys.len(), true);
let numbered_fields = do fields.map |field| { let numbered_fields = do fields.map |field| {
let opt_pos = field_tys.iter().position(|field_ty| field_ty.ident == field.ident); let opt_pos = field_tys.iter().position(|field_ty|
field_ty.ident.name == field.ident.name);
match opt_pos { match opt_pos {
Some(i) => { Some(i) => {
need_base[i] = false; need_base[i] = false;

View file

@ -295,6 +295,7 @@ pub fn trans_static_method_callee(bcx: @mut Block,
pub fn method_with_name(ccx: &mut CrateContext, pub fn method_with_name(ccx: &mut CrateContext,
impl_id: ast::DefId, impl_id: ast::DefId,
name: ast::Ident) -> ast::DefId { name: ast::Ident) -> ast::DefId {
// NOTE : SHOULD USE NAME (chonged later)
let meth_id_opt = ccx.impl_method_cache.find_copy(&(impl_id, name)); let meth_id_opt = ccx.impl_method_cache.find_copy(&(impl_id, name));
match meth_id_opt { match meth_id_opt {
Some(m) => return m, Some(m) => return m,
@ -303,7 +304,7 @@ pub fn method_with_name(ccx: &mut CrateContext,
let imp = ccx.tcx.impls.find(&impl_id) let imp = ccx.tcx.impls.find(&impl_id)
.expect("could not find impl while translating"); .expect("could not find impl while translating");
let meth = imp.methods.iter().find(|m| m.ident == name) let meth = imp.methods.iter().find(|m| m.ident.name == name.name)
.expect("could not find method while translating"); .expect("could not find method while translating");
ccx.impl_method_cache.insert((impl_id, name), meth.def_id); ccx.impl_method_cache.insert((impl_id, name), meth.def_id);

View file

@ -3360,19 +3360,19 @@ pub fn stmt_node_id(s: &ast::Stmt) -> ast::NodeId {
} }
} }
pub fn field_idx(id: ast::Ident, fields: &[field]) -> Option<uint> { pub fn field_idx(name: ast::Name, fields: &[field]) -> Option<uint> {
let mut i = 0u; let mut i = 0u;
for f in fields.iter() { if f.ident == id { return Some(i); } i += 1u; } for f in fields.iter() { if f.ident.name == name { return Some(i); } i += 1u; }
return None; return None;
} }
pub fn field_idx_strict(tcx: ty::ctxt, id: ast::Ident, fields: &[field]) pub fn field_idx_strict(tcx: ty::ctxt, name: ast::Name, fields: &[field])
-> uint { -> uint {
let mut i = 0u; let mut i = 0u;
for f in fields.iter() { if f.ident == id { return i; } i += 1u; } for f in fields.iter() { if f.ident.name == name { return i; } i += 1u; }
tcx.sess.bug(fmt!( tcx.sess.bug(fmt!(
"No field named `%s` found in the list of fields `%?`", "No field named `%s` found in the list of fields `%?`",
tcx.sess.str_of(id), token::interner_get(name),
fields.map(|f| tcx.sess.str_of(f.ident)))); fields.map(|f| tcx.sess.str_of(f.ident))));
} }

View file

@ -105,6 +105,7 @@ use syntax::ast::{sty_uniq, sty_static, NodeId};
use syntax::ast::{MutMutable, MutImmutable}; use syntax::ast::{MutMutable, MutImmutable};
use syntax::ast; use syntax::ast;
use syntax::ast_map; use syntax::ast_map;
use syntax::parse::token;
#[deriving(Eq)] #[deriving(Eq)]
pub enum CheckTraitsFlag { pub enum CheckTraitsFlag {
@ -126,7 +127,7 @@ pub fn lookup(
self_expr: @ast::Expr, // The expression `a`. self_expr: @ast::Expr, // The expression `a`.
callee_id: NodeId, /* Where to store `a.b`'s type, callee_id: NodeId, /* Where to store `a.b`'s type,
* also the scope of the call */ * also the scope of the call */
m_name: ast::Ident, // The ident `b`. m_name: ast::Name, // The name `b`.
self_ty: ty::t, // The type of `a`. self_ty: ty::t, // The type of `a`.
supplied_tps: &[ty::t], // The list of types X, Y, ... . supplied_tps: &[ty::t], // The list of types X, Y, ... .
deref_args: check::DerefArgs, // Whether we autopointer first. deref_args: check::DerefArgs, // Whether we autopointer first.
@ -173,7 +174,7 @@ pub struct LookupContext<'self> {
expr: @ast::Expr, expr: @ast::Expr,
self_expr: @ast::Expr, self_expr: @ast::Expr,
callee_id: NodeId, callee_id: NodeId,
m_name: ast::Ident, m_name: ast::Name,
supplied_tps: &'self [ty::t], supplied_tps: &'self [ty::t],
impl_dups: @mut HashSet<DefId>, impl_dups: @mut HashSet<DefId>,
inherent_candidates: @mut ~[Candidate], inherent_candidates: @mut ~[Candidate],
@ -515,7 +516,7 @@ impl<'self> LookupContext<'self> {
let trait_methods = ty::trait_methods(tcx, bound_trait_ref.def_id); let trait_methods = ty::trait_methods(tcx, bound_trait_ref.def_id);
match trait_methods.iter().position(|m| { match trait_methods.iter().position(|m| {
m.explicit_self != ast::sty_static && m.explicit_self != ast::sty_static &&
m.ident == self.m_name }) m.ident.name == self.m_name })
{ {
Some(pos) => { Some(pos) => {
let method = trait_methods[pos]; let method = trait_methods[pos];
@ -558,12 +559,12 @@ impl<'self> LookupContext<'self> {
return; // already visited return; // already visited
} }
debug!("push_candidates_from_impl: %s %s %s", debug!("push_candidates_from_impl: %s %s %s",
self.m_name.repr(self.tcx()), token::interner_get(self.m_name),
impl_info.ident.repr(self.tcx()), impl_info.ident.repr(self.tcx()),
impl_info.methods.map(|m| m.ident).repr(self.tcx())); impl_info.methods.map(|m| m.ident).repr(self.tcx()));
let idx = { let idx = {
match impl_info.methods.iter().position(|m| m.ident == self.m_name) { match impl_info.methods.iter().position(|m| m.ident.name == self.m_name) {
Some(idx) => idx, Some(idx) => idx,
None => { return; } // No method with the right name. None => { return; } // No method with the right name.
} }

View file

@ -1117,10 +1117,10 @@ pub fn impl_self_ty(vcx: &VtableContext,
pub fn lookup_field_ty(tcx: ty::ctxt, pub fn lookup_field_ty(tcx: ty::ctxt,
class_id: ast::DefId, class_id: ast::DefId,
items: &[ty::field_ty], items: &[ty::field_ty],
fieldname: ast::Ident, fieldname: ast::Name,
substs: &ty::substs) -> Option<ty::t> { substs: &ty::substs) -> Option<ty::t> {
let o_field = items.iter().find(|f| f.ident == fieldname); let o_field = items.iter().find(|f| f.ident.name == fieldname);
do o_field.map() |f| { do o_field.map() |f| {
ty::lookup_field_type(tcx, class_id, f.id, substs) ty::lookup_field_type(tcx, class_id, f.id, substs)
} }
@ -1553,7 +1553,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
expr, expr,
rcvr, rcvr,
callee_id, callee_id,
method_name, method_name.name,
expr_t, expr_t,
tps, tps,
DontDerefArgs, DontDerefArgs,
@ -1637,7 +1637,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
op_ex: @ast::Expr, op_ex: @ast::Expr,
self_ex: @ast::Expr, self_ex: @ast::Expr,
self_t: ty::t, self_t: ty::t,
opname: ast::Ident, opname: ast::Name,
args: ~[@ast::Expr], args: ~[@ast::Expr],
deref_args: DerefArgs, deref_args: DerefArgs,
autoderef_receiver: AutoderefReceiverFlag, autoderef_receiver: AutoderefReceiverFlag,
@ -1777,7 +1777,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
lhs_resolved_t, None) lhs_resolved_t, None)
}; };
return lookup_op_method(fcx, callee_id, ex, lhs_expr, lhs_resolved_t, return lookup_op_method(fcx, callee_id, ex, lhs_expr, lhs_resolved_t,
fcx.tcx().sess.ident_of(*name), token::intern(*name),
~[rhs], DoDerefArgs, DontAutoderefReceiver, if_op_unbound, ~[rhs], DoDerefArgs, DontAutoderefReceiver, if_op_unbound,
expected_result); expected_result);
} }
@ -1811,7 +1811,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
-> ty::t { -> ty::t {
lookup_op_method( lookup_op_method(
fcx, callee_id, ex, rhs_expr, rhs_t, fcx, callee_id, ex, rhs_expr, rhs_t,
fcx.tcx().sess.ident_of(mname), ~[], token::intern(mname), ~[],
DoDerefArgs, DontAutoderefReceiver, DoDerefArgs, DontAutoderefReceiver,
|| { || {
fcx.type_error_message(ex.span, |actual| { fcx.type_error_message(ex.span, |actual| {
@ -1937,7 +1937,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
fn check_field(fcx: @mut FnCtxt, fn check_field(fcx: @mut FnCtxt,
expr: @ast::Expr, expr: @ast::Expr,
base: @ast::Expr, base: @ast::Expr,
field: ast::Ident, field: ast::Name,
tys: &[ast::Ty]) { tys: &[ast::Ty]) {
let tcx = fcx.ccx.tcx; let tcx = fcx.ccx.tcx;
let bot = check_expr(fcx, base); let bot = check_expr(fcx, base);
@ -1985,7 +1985,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
|actual| { |actual| {
fmt!("attempted to take value of method `%s` on type `%s` \ fmt!("attempted to take value of method `%s` on type `%s` \
(try writing an anonymous function)", (try writing an anonymous function)",
tcx.sess.str_of(field), actual) token::interner_get(field), actual)
}, },
expr_t, None); expr_t, None);
} }
@ -1996,7 +1996,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
|actual| { |actual| {
fmt!("attempted access of field `%s` on type `%s`, \ fmt!("attempted access of field `%s` on type `%s`, \
but no field with that name was found", but no field with that name was found",
tcx.sess.str_of(field), actual) token::interner_get(field), actual)
}, },
expr_t, None); expr_t, None);
} }
@ -2018,7 +2018,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
let mut class_field_map = HashMap::new(); let mut class_field_map = HashMap::new();
let mut fields_found = 0; let mut fields_found = 0;
for field in field_types.iter() { for field in field_types.iter() {
class_field_map.insert(field.ident, (field.id, false)); class_field_map.insert(field.ident.name, (field.id, false));
} }
let mut error_happened = false; let mut error_happened = false;
@ -2027,7 +2027,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
for field in ast_fields.iter() { for field in ast_fields.iter() {
let mut expected_field_type = ty::mk_err(); let mut expected_field_type = ty::mk_err();
let pair = class_field_map.find(&field.ident).map_move(|x| *x); let pair = class_field_map.find(&field.ident.name).map_move(|x| *x);
match pair { match pair {
None => { None => {
tcx.sess.span_err( tcx.sess.span_err(
@ -2048,7 +2048,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
ty::lookup_field_type( ty::lookup_field_type(
tcx, class_id, field_id, &substitutions); tcx, class_id, field_id, &substitutions);
class_field_map.insert( class_field_map.insert(
field.ident, (field_id, true)); field.ident.name, (field_id, true));
fields_found += 1; fields_found += 1;
} }
} }
@ -2070,11 +2070,11 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
if fields_found < field_types.len() { if fields_found < field_types.len() {
let mut missing_fields = ~[]; let mut missing_fields = ~[];
for class_field in field_types.iter() { for class_field in field_types.iter() {
let name = class_field.ident; let name = class_field.ident.name;
let (_, seen) = *class_field_map.get(&name); let (_, seen) = *class_field_map.get(&name);
if !seen { if !seen {
missing_fields.push( missing_fields.push(
~"`" + tcx.sess.str_of(name) + "`"); ~"`" + token::interner_get(name) + "`");
} }
} }
@ -2846,7 +2846,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
} }
} }
ast::ExprField(base, field, ref tys) => { ast::ExprField(base, field, ref tys) => {
check_field(fcx, expr, base, field, *tys); check_field(fcx, expr, base, field.name, *tys);
} }
ast::ExprIndex(callee_id, base, idx) => { ast::ExprIndex(callee_id, base, idx) => {
check_expr(fcx, base); check_expr(fcx, base);
@ -2886,7 +2886,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
expr, expr,
base, base,
resolved, resolved,
index_ident, index_ident.name,
~[idx], ~[idx],
DoDerefArgs, DoDerefArgs,
AutoderefReceiver, AutoderefReceiver,

View file

@ -553,13 +553,13 @@ impl CoherenceChecker {
let mut provided_names = HashSet::new(); let mut provided_names = HashSet::new();
// Implemented methods // Implemented methods
for elt in all_methods.iter() { for elt in all_methods.iter() {
provided_names.insert(elt.ident); provided_names.insert(elt.ident.name);
} }
let r = ty::trait_methods(tcx, trait_did); let r = ty::trait_methods(tcx, trait_did);
for method in r.iter() { for method in r.iter() {
debug!("checking for %s", method.ident.repr(tcx)); debug!("checking for %s", method.ident.repr(tcx));
if provided_names.contains(&method.ident) { loop; } if provided_names.contains(&method.ident.name) { loop; }
tcx.sess.span_err(trait_ref_span, tcx.sess.span_err(trait_ref_span,
fmt!("missing method `%s`", fmt!("missing method `%s`",

View file

@ -698,7 +698,7 @@ pub fn check_methods_against_trait(ccx: &CrateCtxt,
// we'll catch it in coherence // we'll catch it in coherence
let trait_ms = ty::trait_methods(tcx, trait_ref.def_id); let trait_ms = ty::trait_methods(tcx, trait_ref.def_id);
for impl_m in impl_ms.iter() { for impl_m in impl_ms.iter() {
match trait_ms.iter().find(|trait_m| trait_m.ident == impl_m.mty.ident) { match trait_ms.iter().find(|trait_m| trait_m.ident.name == impl_m.mty.ident.name) {
Some(trait_m) => { Some(trait_m) => {
let num_impl_tps = generics.ty_params.len(); let num_impl_tps = generics.ty_params.len();
compare_impl_method( compare_impl_method(