diff options
| author | John Clements <clements@racket-lang.org> | 2013-06-26 15:56:13 -0700 |
|---|---|---|
| committer | John Clements <clements@racket-lang.org> | 2013-09-06 13:35:07 -0700 |
| commit | 39ca2dbbc5072713b91a4f444bb1fdcd0d69e19c (patch) | |
| tree | 85b5b71a917f10aa2c1f48842aed5c92fb548bd2 /src | |
| parent | 71e72ee86260880c281d8f8ec6d4d3a1eb55e461 (diff) | |
| download | rust-39ca2dbbc5072713b91a4f444bb1fdcd0d69e19c.tar.gz rust-39ca2dbbc5072713b91a4f444bb1fdcd0d69e19c.zip | |
update librustc to use name comparison in most cases, and mtwt_resolve comparison in others
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustc/middle/resolve.rs | 163 | ||||
| -rw-r--r-- | src/librustc/middle/trans/_match.rs | 4 | ||||
| -rw-r--r-- | src/librustc/middle/trans/consts.rs | 4 | ||||
| -rw-r--r-- | src/librustc/middle/trans/expr.rs | 5 | ||||
| -rw-r--r-- | src/librustc/middle/trans/meth.rs | 3 | ||||
| -rw-r--r-- | src/librustc/middle/ty.rs | 10 | ||||
| -rw-r--r-- | src/librustc/middle/typeck/check/method.rs | 11 | ||||
| -rw-r--r-- | src/librustc/middle/typeck/check/mod.rs | 32 | ||||
| -rw-r--r-- | src/librustc/middle/typeck/coherence.rs | 4 | ||||
| -rw-r--r-- | src/librustc/middle/typeck/collect.rs | 2 |
10 files changed, 124 insertions, 114 deletions
diff --git a/src/librustc/middle/resolve.rs b/src/librustc/middle/resolve.rs index 563b36202b3..8c8dedeef32 100644 --- a/src/librustc/middle/resolve.rs +++ b/src/librustc/middle/resolve.rs @@ -23,7 +23,7 @@ use middle::pat_util::pat_bindings; 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::{Privacy, Public, Private}; 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. -pub type BindingMap = HashMap<Ident,binding_info>; +pub type BindingMap = HashMap<Name,binding_info>; // Trait method resolution pub type TraitMap = HashMap<NodeId,@mut ~[DefId]>; @@ -445,12 +445,12 @@ pub struct Module { def_id: Option<DefId>, kind: ModuleKind, - children: @mut HashMap<Ident, @mut NameBindings>, + children: @mut HashMap<Name, @mut NameBindings>, imports: @mut ~[@ImportDirective], // The external module children of this node that were declared with // `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- // modules that are implicitly created around items contained within @@ -469,7 +469,7 @@ pub struct Module { anonymous_children: @mut HashMap<NodeId,@mut 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. glob_count: uint, @@ -759,15 +759,14 @@ pub fn NameBindings() -> NameBindings { /// Interns the names of the primitive types. pub struct PrimitiveTypeTable { - primitive_types: HashMap<Ident,prim_ty>, + primitive_types: HashMap<Name,prim_ty>, } impl PrimitiveTypeTable { pub fn intern(&mut self, string: &str, primitive_type: prim_ty) { - let ident = token::str_to_ident(string); - self.primitive_types.insert(ident, primitive_type); + self.primitive_types.insert(token::intern(string), primitive_type); } } @@ -873,7 +872,7 @@ pub struct Resolver { graph_root: @mut NameBindings, - method_map: @mut HashMap<Ident, HashSet<DefId>>, + method_map: @mut HashMap<Name, HashSet<DefId>>, structs: HashSet<DefId>, // The number of imports that are currently unresolved. @@ -1036,10 +1035,10 @@ impl Resolver { // Add or reuse the child. let new_parent = ModuleReducedGraphParent(module_); - match module_.children.find(&name) { + match module_.children.find(&name.name) { None => { let child = @mut NameBindings(); - module_.children.insert(name, child); + module_.children.insert(name.name, child); return (child, new_parent); } Some(&child) => { @@ -1307,7 +1306,7 @@ impl Resolver { } if path.segments.len() == 1 => { 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 Some(&child) if child.get_module_if_available() .is_some() && @@ -1426,7 +1425,7 @@ impl Resolver { match ty_m.explicit_self.node { sty_static => {} _ => { - method_names.insert(ident, ()); + method_names.insert(ident.name, ()); } } } @@ -1582,7 +1581,7 @@ impl Resolver { false); parent.external_module_children.insert( - name, + name.name, external_module); self.build_reduced_graph_for_external_crate( @@ -1727,7 +1726,7 @@ impl Resolver { // Add it to the trait info if not 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() { @@ -1981,7 +1980,7 @@ impl Resolver { self.idents_to_str(directive.module_path), self.session.str_of(target)); - match module_.import_resolutions.find(&target) { + match module_.import_resolutions.find(&target.name) { Some(&resolution) => { debug!("(building import directive) bumping \ reference"); @@ -1996,7 +1995,7 @@ impl Resolver { debug!("(building import directive) creating new"); let resolution = @mut ImportResolution::new(privacy, id); 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. self.populate_module_if_necessary(containing_module); - match containing_module.children.find(&source) { + match containing_module.children.find(&source.name) { None => { // Continue. } @@ -2315,7 +2314,7 @@ impl Resolver { // Now search the exported imports within the containing // module. - match containing_module.import_resolutions.find(&source) { + match containing_module.import_resolutions.find(&source.name) { None => { // The containing module definitely doesn't have an // exported import with the name in question. We can @@ -2386,7 +2385,7 @@ impl Resolver { BoundResult(*) => {} _ => { match containing_module.external_module_children - .find(&source) { + .find(&source.name) { None => {} // Continue. Some(module) => { let name_bindings = @@ -2400,8 +2399,8 @@ impl Resolver { } // We've successfully resolved the import. Write the results in. - assert!(module_.import_resolutions.contains_key(&target)); - let import_resolution = module_.import_resolutions.get(&target); + assert!(module_.import_resolutions.contains_key(&target.name)); + let import_resolution = module_.import_resolutions.get(&target.name); match value_result { 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| { let dest_import_resolution; - match module_.import_resolutions.find(&ident) { + match module_.import_resolutions.find(&name) { None => { // Create a new import resolution from this child. dest_import_resolution = @mut ImportResolution::new(privacy, id); module_.import_resolutions.insert - (ident, dest_import_resolution); + (name, dest_import_resolution); } Some(&existing_import_resolution) => { dest_import_resolution = existing_import_resolution; @@ -2580,7 +2579,7 @@ impl Resolver { debug!("(resolving glob import) writing resolution `%s` in `%s` \ to `%s`, privacy=%?", - self.session.str_of(ident), + interner_get(name), self.module_to_str(containing_module), self.module_to_str(module_), dest_import_resolution.privacy); @@ -2602,15 +2601,15 @@ impl Resolver { // Add all children from the containing module. self.populate_module_if_necessary(containing_module); - for (&ident, name_bindings) in containing_module.children.iter() { - merge_import_resolution(ident, *name_bindings); + for (&name, name_bindings) in containing_module.children.iter() { + merge_import_resolution(name, *name_bindings); } // 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 = @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"); @@ -2836,7 +2835,7 @@ impl Resolver { // The current module node is handled specially. First, check for // its immediate children. self.populate_module_if_necessary(module_); - match module_.children.find(&name) { + match module_.children.find(&name.name) { Some(name_bindings) if name_bindings.defined_in_namespace(namespace) => { 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 // adjacent import statements are processed as though they mutated the // current scope. - match module_.import_resolutions.find(&name) { + match module_.import_resolutions.find(&name.name) { None => { // Not found; continue. } @@ -2872,7 +2871,7 @@ impl Resolver { // Search for external modules. if namespace == TypeNS { - match module_.external_module_children.find(&name) { + match module_.external_module_children.find(&name.name) { None => {} Some(module) => { 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::`. + /// grammar: (SELF MOD_SEP ) ? (SUPER MOD_SEP) * pub fn resolve_module_prefix(@mut self, module_: @mut Module, module_path: &[Ident]) @@ -3091,7 +3091,7 @@ impl Resolver { // First, check the direct children of the module. self.populate_module_if_necessary(module_); - match module_.children.find(&name) { + match module_.children.find(&name.name) { Some(name_bindings) if name_bindings.defined_in_namespace(namespace) => { debug!("(resolving name in module) found node as child"); @@ -3112,7 +3112,7 @@ impl Resolver { } // Check the list of resolved imports. - match module_.import_resolutions.find(&name) { + match module_.import_resolutions.find(&name.name) { Some(import_resolution) => { if import_resolution.privacy == Public && import_resolution.outstanding_references != 0 { @@ -3147,7 +3147,7 @@ impl Resolver { // Finally, search through external children. if namespace == TypeNS { - match module_.external_module_children.find(&name) { + match module_.external_module_children.find(&name.name) { None => {} Some(module) => { let name_bindings = @@ -3273,7 +3273,7 @@ impl Resolver { pub fn add_exports_of_namebindings(@mut self, exports2: &mut ~[Export2], - ident: Ident, + name: Name, namebindings: @mut NameBindings, ns: Namespace, reexport: bool) { @@ -3282,11 +3282,11 @@ impl Resolver { (Some(d), Some(Public)) => { debug!("(computing exports) YES: %s '%s' => %?", if reexport { ~"reexport" } else { ~"export"}, - self.session.str_of(ident), + interner_get(name), def_id_of_def(d)); exports2.push(Export2 { reexport: reexport, - name: self.session.str_of(ident), + name: interner_get(name), def_id: def_id_of_def(d) }); } @@ -3302,10 +3302,10 @@ impl Resolver { pub fn add_exports_for_module(@mut self, exports2: &mut ~[Export2], module_: @mut Module) { - for (ident, importresolution) in module_.import_resolutions.iter() { + for (name, importresolution) in module_.import_resolutions.iter() { if importresolution.privacy != Public { debug!("(computing exports) not reexporting private `%s`", - self.session.str_of(*ident)); + interner_get(*name)); loop; } let xs = [TypeNS, ValueNS]; @@ -3313,9 +3313,9 @@ impl Resolver { match importresolution.target_for_namespace(*ns) { Some(target) => { debug!("(computing exports) maybe reexport '%s'", - self.session.str_of(*ident)); + interner_get(*name)); self.add_exports_of_namebindings(&mut *exports2, - *ident, + *name, target.bindings, *ns, true) @@ -3354,7 +3354,7 @@ impl Resolver { } Some(name) => { self.populate_module_if_necessary(orig_module); - match orig_module.children.find(&name) { + match orig_module.children.find(&name.name) { None => { debug!("!!! (with scope) didn't find `%s` in `%s`", self.session.str_of(name), @@ -3498,7 +3498,7 @@ impl Resolver { pub fn search_ribs(@mut self, ribs: &mut ~[@Rib], - name: Ident, + name: Name, span: Span, allow_capturing_self: AllowCapturingSelfFlag) -> Option<DefLike> { @@ -3508,7 +3508,7 @@ impl Resolver { let mut i = ribs.len(); while i != 0 { i -= 1; - match ribs[i].bindings.find(&name.name) { + match ribs[i].bindings.find(&name) { Some(&def_like) => { return self.upvarify(ribs, i, def_like, span, allow_capturing_self); @@ -3591,7 +3591,9 @@ impl Resolver { // Create a new rib for the self type. let self_type_rib = @Rib::new(NormalRibKind); 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))); // Create a new rib for the trait-wide type parameters. @@ -3733,6 +3735,7 @@ impl Resolver { // the item that bound it self.record_def(type_parameter.id, DefTyParamBinder(node_id)); + // plain insert (no renaming) 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 { let mut result = HashMap::new(); do pat_bindings(self.def_map, pat) |binding_mode, _id, sp, path| { - let ident = path_to_ident(path); - result.insert(ident, + let name = path_to_ident(path).name; // mtwt_resolve(path_to_ident(path)); + result.insert(name, binding_info {span: sp, binding_mode: binding_mode}); } @@ -4088,7 +4091,7 @@ impl Resolver { p.span, fmt!("variable `%s` from pattern #1 is \ not bound in pattern #%u", - self.session.str_of(key), i + 1)); + interner_get(key), i + 1)); } Some(binding_i) => { if binding_0.binding_mode != binding_i.binding_mode { @@ -4096,7 +4099,7 @@ impl Resolver { binding_i.span, fmt!("variable `%s` is bound with different \ 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, fmt!("variable `%s` from pattern #%u is \ 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. if path.segments.len() == 1 { - let name = path.segments.last().identifier; + let id = path.segments.last().identifier; match self.primitive_type_table .primitive_types - .find(&name) { + .find(&id.name) { Some(&primitive_type) => { result_def = @@ -4272,7 +4275,7 @@ impl Resolver { mutability: Mutability, // Maps idents to the node ID for the (outermost) // pattern that binds them - bindings_list: Option<@mut HashMap<Ident,NodeId>>, + bindings_list: Option<@mut HashMap<Name,NodeId>>, visitor: &mut ResolveVisitor) { let pat_id = pattern.id; do walk_pat(pattern) |pattern| { @@ -4290,13 +4293,14 @@ impl Resolver { // what you want). let ident = path.segments[0].identifier; + let renamed = ident.name; // mtwt_resolve(ident); match self.resolve_bare_identifier_pattern(ident) { FoundStructOrEnumVariant(def) if mode == RefutableMode => { debug!("(resolving pattern) resolving `%s` to \ struct or enum variant", - self.session.str_of(ident)); + interner_get(renamed)); self.enforce_default_binding_mode( pattern, @@ -4310,13 +4314,12 @@ impl Resolver { shadows an enum \ variant or unit-like \ struct in scope", - self.session - .str_of(ident))); + interner_get(renamed))); } FoundConst(def) if mode == RefutableMode => { debug!("(resolving pattern) resolving `%s` to \ constant", - self.session.str_of(ident)); + interner_get(renamed)); self.enforce_default_binding_mode( pattern, @@ -4331,7 +4334,7 @@ impl Resolver { } BareIdentifierPatternUnresolved => { debug!("(resolving pattern) binding `%s`", - self.session.str_of(ident)); + interner_get(renamed)); let is_mutable = mutability == Mutable; @@ -4366,16 +4369,16 @@ impl Resolver { match bindings_list { Some(bindings_list) - if !bindings_list.contains_key(&ident) => { + if !bindings_list.contains_key(&renamed) => { let this = &mut *self; let last_rib = this.value_ribs[ this.value_ribs.len() - 1]; - last_rib.bindings.insert(ident.name, + last_rib.bindings.insert(renamed, DlDef(def)); - bindings_list.insert(ident, pat_id); + bindings_list.insert(renamed, pat_id); } Some(b) => { - if b.find(&ident) == Some(&pat_id) { + if b.find(&renamed) == Some(&pat_id) { // Then this is a duplicate variable // in the same disjunct, which is an // error @@ -4391,7 +4394,7 @@ impl Resolver { let this = &mut *self; let last_rib = this.value_ribs[ this.value_ribs.len() - 1]; - last_rib.bindings.insert(ident.name, + last_rib.bindings.insert(renamed, DlDef(def)); } } @@ -4640,7 +4643,7 @@ impl Resolver { -> NameDefinition { // First, search children. self.populate_module_if_necessary(containing_module); - match containing_module.children.find(&name) { + match containing_module.children.find(&name.name) { Some(child_name_bindings) => { match (child_name_bindings.def_for_namespace(namespace), child_name_bindings.privacy_for_namespace(namespace)) { @@ -4663,7 +4666,7 @@ impl Resolver { } // 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 || xray == Xray => { match (*import_resolution).target_for_namespace(namespace) { @@ -4691,7 +4694,7 @@ impl Resolver { // Finally, search through external children. if namespace == TypeNS { - match containing_module.external_module_children.find(&name) { + match containing_module.external_module_children.find(&name.name) { None => {} Some(module) => { 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, - name, + ident, namespace, xray) { NoNameDefinition => { @@ -4753,7 +4756,7 @@ impl Resolver { }; match containing_module.kind { TraitModuleKind | ImplModuleKind => { - match self.method_map.find(&name) { + match self.method_map.find(&ident.name) { Some(s) => { match containing_module.def_id { Some(def_id) if s.contains(&def_id) => { @@ -4830,12 +4833,14 @@ impl Resolver { let search_result; match namespace { 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, DontAllowCapturingSelf); } 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); } } @@ -5135,6 +5140,7 @@ impl Resolver { let this = &mut *self; let def_like = DlDef(DefLabel(expr.id)); let rib = this.label_ribs[this.label_ribs.len() - 1]; + // plain insert (no renaming) rib.bindings.insert(label.name, def_like); } @@ -5145,7 +5151,8 @@ impl Resolver { ExprForLoop(*) => fail!("non-desugared expr_for_loop"), 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) { None => self.resolve_error(expr.span, @@ -5273,7 +5280,7 @@ impl Resolver { let mut found_traits = ~[]; let mut search_module = self.current_module; - match self.method_map.find(&name) { + match self.method_map.find(&name.name) { Some(candidate_traits) => loop { // Look for the current trait. match self.current_trait_refs { @@ -5495,7 +5502,7 @@ impl Resolver { debug!("Children:"); self.populate_module_if_necessary(module_); for (&name, _) in module_.children.iter() { - debug!("* %s", self.session.str_of(name)); + debug!("* %s", interner_get(name)); } 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); } } diff --git a/src/librustc/middle/trans/_match.rs b/src/librustc/middle/trans/_match.rs index 39e3e97b489..5efd81ebc47 100644 --- a/src/librustc/middle/trans/_match.rs +++ b/src/librustc/middle/trans/_match.rs @@ -1482,7 +1482,7 @@ fn compile_submatch_continue(mut bcx: @mut Block, let pat_repr = adt::represent_type(bcx.ccx(), pat_ty); do expr::with_field_tys(tcx, pat_ty, None) |discr, field_tys| { 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) }); compile_submatch( @@ -2159,7 +2159,7 @@ fn bind_irrefutable_pat(bcx: @mut Block, let pat_repr = adt::represent_type(bcx.ccx(), pat_ty); do expr::with_field_tys(tcx, pat_ty, None) |discr, field_tys| { 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, discr, ix); bcx = bind_irrefutable_pat(bcx, f.pat, fldptr, binding_mode); diff --git a/src/librustc/middle/trans/consts.rs b/src/librustc/middle/trans/consts.rs index 096e37136ac..94f0b373570 100644 --- a/src/librustc/middle/trans/consts.rs +++ b/src/librustc/middle/trans/consts.rs @@ -374,7 +374,7 @@ fn const_expr_unadjusted(cx: @mut CrateContext, e: &ast::Expr) -> ValueRef { let brepr = adt::represent_type(cx, bt); let bv = const_expr(cx, base); 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) } } @@ -502,7 +502,7 @@ fn const_expr_unadjusted(cx: @mut CrateContext, e: &ast::Expr) -> ValueRef { |discr, field_tys| { let cs: ~[ValueRef] = field_tys.iter().enumerate() .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), None => { match base_val { diff --git a/src/librustc/middle/trans/expr.rs b/src/librustc/middle/trans/expr.rs index ce6fb6d3e77..3ecb319e468 100644 --- a/src/librustc/middle/trans/expr.rs +++ b/src/librustc/middle/trans/expr.rs @@ -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 repr = adt::represent_type(bcx.ccx(), base_datum.ty); 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 { datum: do base_datum.get_element(bcx, 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 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 { Some(i) => { need_base[i] = false; diff --git a/src/librustc/middle/trans/meth.rs b/src/librustc/middle/trans/meth.rs index 76b23d9d536..3dfdb551634 100644 --- a/src/librustc/middle/trans/meth.rs +++ b/src/librustc/middle/trans/meth.rs @@ -295,6 +295,7 @@ pub fn trans_static_method_callee(bcx: @mut Block, pub fn method_with_name(ccx: &mut CrateContext, impl_id: 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)); match meth_id_opt { Some(m) => return m, @@ -303,7 +304,7 @@ pub fn method_with_name(ccx: &mut CrateContext, let imp = ccx.tcx.impls.find(&impl_id) .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"); ccx.impl_method_cache.insert((impl_id, name), meth.def_id); diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index 0958eeb7097..4a42efc3393 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -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; - 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; } -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 { 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!( "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)))); } diff --git a/src/librustc/middle/typeck/check/method.rs b/src/librustc/middle/typeck/check/method.rs index 3588fb3f51e..48d630b4aa9 100644 --- a/src/librustc/middle/typeck/check/method.rs +++ b/src/librustc/middle/typeck/check/method.rs @@ -105,6 +105,7 @@ use syntax::ast::{sty_uniq, sty_static, NodeId}; use syntax::ast::{MutMutable, MutImmutable}; use syntax::ast; use syntax::ast_map; +use syntax::parse::token; #[deriving(Eq)] pub enum CheckTraitsFlag { @@ -126,7 +127,7 @@ pub fn lookup( self_expr: @ast::Expr, // The expression `a`. callee_id: NodeId, /* Where to store `a.b`'s type, * 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`. supplied_tps: &[ty::t], // The list of types X, Y, ... . deref_args: check::DerefArgs, // Whether we autopointer first. @@ -173,7 +174,7 @@ pub struct LookupContext<'self> { expr: @ast::Expr, self_expr: @ast::Expr, callee_id: NodeId, - m_name: ast::Ident, + m_name: ast::Name, supplied_tps: &'self [ty::t], impl_dups: @mut HashSet<DefId>, inherent_candidates: @mut ~[Candidate], @@ -515,7 +516,7 @@ impl<'self> LookupContext<'self> { let trait_methods = ty::trait_methods(tcx, bound_trait_ref.def_id); match trait_methods.iter().position(|m| { m.explicit_self != ast::sty_static && - m.ident == self.m_name }) + m.ident.name == self.m_name }) { Some(pos) => { let method = trait_methods[pos]; @@ -558,12 +559,12 @@ impl<'self> LookupContext<'self> { return; // already visited } 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.methods.map(|m| m.ident).repr(self.tcx())); 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, None => { return; } // No method with the right name. } diff --git a/src/librustc/middle/typeck/check/mod.rs b/src/librustc/middle/typeck/check/mod.rs index 0e335cf3f14..50c93468bb1 100644 --- a/src/librustc/middle/typeck/check/mod.rs +++ b/src/librustc/middle/typeck/check/mod.rs @@ -1117,10 +1117,10 @@ pub fn impl_self_ty(vcx: &VtableContext, pub fn lookup_field_ty(tcx: ty::ctxt, class_id: ast::DefId, items: &[ty::field_ty], - fieldname: ast::Ident, + fieldname: ast::Name, 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| { ty::lookup_field_type(tcx, class_id, f.id, substs) } @@ -1553,7 +1553,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt, expr, rcvr, callee_id, - method_name, + method_name.name, expr_t, tps, DontDerefArgs, @@ -1637,7 +1637,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt, op_ex: @ast::Expr, self_ex: @ast::Expr, self_t: ty::t, - opname: ast::Ident, + opname: ast::Name, args: ~[@ast::Expr], deref_args: DerefArgs, autoderef_receiver: AutoderefReceiverFlag, @@ -1777,7 +1777,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt, lhs_resolved_t, None) }; 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, expected_result); } @@ -1811,7 +1811,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt, -> ty::t { lookup_op_method( fcx, callee_id, ex, rhs_expr, rhs_t, - fcx.tcx().sess.ident_of(mname), ~[], + token::intern(mname), ~[], DoDerefArgs, DontAutoderefReceiver, || { 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, expr: @ast::Expr, base: @ast::Expr, - field: ast::Ident, + field: ast::Name, tys: &[ast::Ty]) { let tcx = fcx.ccx.tcx; let bot = check_expr(fcx, base); @@ -1985,7 +1985,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt, |actual| { fmt!("attempted to take value of method `%s` on type `%s` \ (try writing an anonymous function)", - tcx.sess.str_of(field), actual) + token::interner_get(field), actual) }, expr_t, None); } @@ -1996,7 +1996,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt, |actual| { fmt!("attempted access of field `%s` on type `%s`, \ but no field with that name was found", - tcx.sess.str_of(field), actual) + token::interner_get(field), actual) }, 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 fields_found = 0; 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; @@ -2027,7 +2027,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt, for field in ast_fields.iter() { 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 { None => { tcx.sess.span_err( @@ -2048,7 +2048,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt, ty::lookup_field_type( tcx, class_id, field_id, &substitutions); class_field_map.insert( - field.ident, (field_id, true)); + field.ident.name, (field_id, true)); fields_found += 1; } } @@ -2070,11 +2070,11 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt, if fields_found < field_types.len() { let mut missing_fields = ~[]; 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); if !seen { 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) => { - check_field(fcx, expr, base, field, *tys); + check_field(fcx, expr, base, field.name, *tys); } ast::ExprIndex(callee_id, base, idx) => { check_expr(fcx, base); @@ -2886,7 +2886,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt, expr, base, resolved, - index_ident, + index_ident.name, ~[idx], DoDerefArgs, AutoderefReceiver, diff --git a/src/librustc/middle/typeck/coherence.rs b/src/librustc/middle/typeck/coherence.rs index 738ed9656e3..700b60f1159 100644 --- a/src/librustc/middle/typeck/coherence.rs +++ b/src/librustc/middle/typeck/coherence.rs @@ -553,13 +553,13 @@ impl CoherenceChecker { let mut provided_names = HashSet::new(); // Implemented methods 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); for method in r.iter() { 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, fmt!("missing method `%s`", diff --git a/src/librustc/middle/typeck/collect.rs b/src/librustc/middle/typeck/collect.rs index 8056831537f..3f5e1ef5210 100644 --- a/src/librustc/middle/typeck/collect.rs +++ b/src/librustc/middle/typeck/collect.rs @@ -698,7 +698,7 @@ pub fn check_methods_against_trait(ccx: &CrateCtxt, // we'll catch it in coherence let trait_ms = ty::trait_methods(tcx, trait_ref.def_id); 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) => { let num_impl_tps = generics.ty_params.len(); compare_impl_method( |
