rustc: Remove some uses of impl_map
This commit is contained in:
@@ -195,7 +195,6 @@ fn compile_upto(sess: session, cfg: ast::crate_cfg,
|
|||||||
|
|
||||||
let (method_map, vtable_map) = time(time_passes, ~"typechecking", ||
|
let (method_map, vtable_map) = time(time_passes, ~"typechecking", ||
|
||||||
typeck::check_crate(ty_cx,
|
typeck::check_crate(ty_cx,
|
||||||
impl_map,
|
|
||||||
trait_map,
|
trait_map,
|
||||||
crate));
|
crate));
|
||||||
// These next two const passes can probably be merged
|
// These next two const passes can probably be merged
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import driver::session::session;
|
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::csearch::{get_method_names_if_trait, lookup_defs};
|
||||||
import metadata::cstore::find_use_stmt_cnum;
|
import metadata::cstore::find_use_stmt_cnum;
|
||||||
import metadata::decoder::{def_like, dl_def, dl_field, dl_impl};
|
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.
|
/// Creates and adds an import directive to the given module.
|
||||||
|
|||||||
@@ -158,9 +158,7 @@ type provided_methods_map = hashmap<ast::node_id,
|
|||||||
|
|
||||||
type ty_param_substs_and_ty = {substs: ty::substs, ty: ty::t};
|
type ty_param_substs_and_ty = {substs: ty::substs, ty: ty::t};
|
||||||
|
|
||||||
type crate_ctxt_ = {impl_map: resolve3::ImplMap,
|
type crate_ctxt_ = {// A mapping from method call sites to traits that have
|
||||||
|
|
||||||
// A mapping from method call sites to traits that have
|
|
||||||
// that method.
|
// that method.
|
||||||
trait_map: resolve3::TraitMap,
|
trait_map: resolve3::TraitMap,
|
||||||
method_map: method_map,
|
method_map: method_map,
|
||||||
@@ -299,13 +297,11 @@ fn check_for_main_fn(ccx: @crate_ctxt) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn check_crate(tcx: ty::ctxt,
|
fn check_crate(tcx: ty::ctxt,
|
||||||
impl_map: resolve3::ImplMap,
|
|
||||||
trait_map: resolve3::TraitMap,
|
trait_map: resolve3::TraitMap,
|
||||||
crate: @ast::crate)
|
crate: @ast::crate)
|
||||||
-> (method_map, vtable_map) {
|
-> (method_map, vtable_map) {
|
||||||
|
|
||||||
let ccx = @crate_ctxt_({impl_map: impl_map,
|
let ccx = @crate_ctxt_({trait_map: trait_map,
|
||||||
trait_map: trait_map,
|
|
||||||
method_map: std::map::int_hash(),
|
method_map: std::map::int_hash(),
|
||||||
vtable_map: std::map::int_hash(),
|
vtable_map: std::map::int_hash(),
|
||||||
coherence_info: @coherence::CoherenceInfo(),
|
coherence_info: @coherence::CoherenceInfo(),
|
||||||
|
|||||||
@@ -138,10 +138,6 @@ class lookup {
|
|||||||
// it.
|
// it.
|
||||||
if self.candidates.len() > 0u { break; }
|
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.
|
// Look for inherent methods.
|
||||||
self.add_inherent_and_extension_candidates
|
self.add_inherent_and_extension_candidates
|
||||||
(optional_inherent_methods, false);
|
(optional_inherent_methods, false);
|
||||||
@@ -149,9 +145,6 @@ class lookup {
|
|||||||
// if we found anything, stop before trying borrows
|
// if we found anything, stop before trying borrows
|
||||||
if self.candidates.len() > 0u { break; }
|
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.
|
// Again, look for inherent methods.
|
||||||
self.add_inherent_and_extension_candidates
|
self.add_inherent_and_extension_candidates
|
||||||
(optional_inherent_methods, true);
|
(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.
|
// Returns true if any were added and false otherwise.
|
||||||
fn add_candidates_from_impl(im: @resolve3::Impl,
|
fn add_candidates_from_impl(im: @resolve3::Impl,
|
||||||
use_assignability: bool) -> bool {
|
use_assignability: bool) -> bool {
|
||||||
|
|||||||
Reference in New Issue
Block a user