From 780b3853d13280ae67d1e196b54e80c47d63e88c Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Wed, 8 Aug 2012 18:50:19 -0700 Subject: [PATCH] rustc: Remove some uses of impl_map --- src/rustc/driver/driver.rs | 1 - src/rustc/middle/resolve3.rs | 79 +------------------------ src/rustc/middle/typeck.rs | 8 +-- src/rustc/middle/typeck/check/method.rs | 34 ----------- 4 files changed, 3 insertions(+), 119 deletions(-) diff --git a/src/rustc/driver/driver.rs b/src/rustc/driver/driver.rs index 779739f8103f..fefbb2bcc5f8 100644 --- a/src/rustc/driver/driver.rs +++ b/src/rustc/driver/driver.rs @@ -195,7 +195,6 @@ fn compile_upto(sess: session, cfg: ast::crate_cfg, let (method_map, vtable_map) = time(time_passes, ~"typechecking", || typeck::check_crate(ty_cx, - impl_map, trait_map, crate)); // These next two const passes can probably be merged diff --git a/src/rustc/middle/resolve3.rs b/src/rustc/middle/resolve3.rs index f30ab29b9b0a..c4c563162d55 100644 --- a/src/rustc/middle/resolve3.rs +++ b/src/rustc/middle/resolve3.rs @@ -1,5 +1,5 @@ import driver::session::session; -import metadata::csearch::{each_path, get_impls_for_mod}; +import metadata::csearch::{each_path}; import metadata::csearch::{get_method_names_if_trait, lookup_defs}; import metadata::cstore::find_use_stmt_cnum; import metadata::decoder::{def_like, dl_def, dl_field, dl_impl}; @@ -1565,83 +1565,6 @@ class Resolver { } } } - - // Create nodes for all the impls. - self.build_reduced_graph_for_impls_in_external_module_subtree(root); - } - - fn build_reduced_graph_for_impls_in_external_module_subtree(module_: - @Module) { - self.build_reduced_graph_for_impls_in_external_module(module_); - - for module_.children.each |_name, child_node| { - match (*child_node).get_module_if_available() { - none => { - // Nothing to do. - } - some(child_module) => { - self. - build_reduced_graph_for_impls_in_external_module_subtree - (child_module); - } - } - } - } - - fn build_reduced_graph_for_impls_in_external_module(module_: @Module) { - // XXX: This is really unfortunate. decoder::each_path can produce - // false positives, since, in the crate metadata, a trait named 'bar' - // in module 'foo' defining a method named 'baz' will result in the - // creation of a (bogus) path entry named 'foo::bar::baz', and we will - // create a module node for "bar". We can identify these fake modules - // by the fact that they have no def ID, which we do here in order to - // skip them. - - debug!{"(building reduced graph for impls in external crate) looking \ - for impls in `%s` (%?)", - self.module_to_str(module_), - copy module_.def_id}; - - match module_.def_id { - none => { - debug!{"(building reduced graph for impls in external \ - module) no def ID for `%s`, skipping", - self.module_to_str(module_)}; - return; - } - some(_) => { - // Continue. - } - } - - let impls_in_module = get_impls_for_mod(self.session.cstore, - get(module_.def_id), - none); - - // Intern def IDs to prevent duplicates. - let def_ids = new_def_hash(); - - for (*impls_in_module).each |implementation| { - if def_ids.contains_key(implementation.did) { - again; - } - def_ids.insert(implementation.did, ()); - - debug!{"(building reduced graph for impls in external module) \ - added impl `%s` (%?) to `%s`", - *implementation.ident, - implementation.did, - self.module_to_str(module_)}; - - let name = (*self.atom_table).intern(implementation.ident); - - let (name_bindings, _) = - // Might want a better span - self.add_child(name, ModuleReducedGraphParent(module_), - ~[ImplNS], dummy_sp()); - - name_bindings.impl_defs += ~[implementation]; - } } /// Creates and adds an import directive to the given module. diff --git a/src/rustc/middle/typeck.rs b/src/rustc/middle/typeck.rs index 690322ec4db3..f19685d8ee9f 100644 --- a/src/rustc/middle/typeck.rs +++ b/src/rustc/middle/typeck.rs @@ -158,9 +158,7 @@ type provided_methods_map = hashmap (method_map, vtable_map) { - let ccx = @crate_ctxt_({impl_map: impl_map, - trait_map: trait_map, + let ccx = @crate_ctxt_({trait_map: trait_map, method_map: std::map::int_hash(), vtable_map: std::map::int_hash(), coherence_info: @coherence::CoherenceInfo(), diff --git a/src/rustc/middle/typeck/check/method.rs b/src/rustc/middle/typeck/check/method.rs index 6ff3c768b1c1..a552b4201e69 100644 --- a/src/rustc/middle/typeck/check/method.rs +++ b/src/rustc/middle/typeck/check/method.rs @@ -138,10 +138,6 @@ class lookup { // it. if self.candidates.len() > 0u { break; } - // now look for impls in scope, but don't look for impls that - // would require doing an implicit borrow of the lhs. - self.add_candidates_from_scope(false); - // Look for inherent methods. self.add_inherent_and_extension_candidates (optional_inherent_methods, false); @@ -149,9 +145,6 @@ class lookup { // if we found anything, stop before trying borrows if self.candidates.len() > 0u { break; } - // now look for impls in scope that might require a borrow - self.add_candidates_from_scope(true); - // Again, look for inherent methods. self.add_inherent_and_extension_candidates (optional_inherent_methods, true); @@ -364,33 +357,6 @@ class lookup { */ } - fn add_candidates_from_scope(use_assignability: bool) { - - // If we're using coherence and this is one of the method invocation - // forms it supports, don't use this method; it'll result in lots of - // multiple-methods-in-scope errors. - if self.fcx.ccx.trait_map.contains_key(self.expr.id) { - return; - } - - let impls_vecs = self.fcx.ccx.impl_map.get(self.expr.id); - let mut added_any = false; - - debug!{"method_from_scope"}; - - for list::each(impls_vecs) |impls| { - for vec::each(*impls) |im| { - if self.add_candidates_from_impl(im, use_assignability) { - added_any = true; - } - } - - // we want to find the innermost scope that has any - // matches and then ignore outer scopes - if added_any {return;} - } - } - // Returns true if any were added and false otherwise. fn add_candidates_from_impl(im: @resolve3::Impl, use_assignability: bool) -> bool {