rustc: Remove the impl map
This commit is contained in:
parent
10c997a746
commit
26aaf08ff4
5 changed files with 5 additions and 186 deletions
|
@ -177,7 +177,6 @@ fn compile_upto(sess: session, cfg: ast::crate_cfg,
|
|||
let { def_map: def_map,
|
||||
exp_map: exp_map,
|
||||
exp_map2: exp_map2,
|
||||
impl_map: impl_map,
|
||||
trait_map: trait_map } =
|
||||
time(time_passes, ~"resolution", ||
|
||||
middle::resolve3::resolve_crate(sess, lang_items, crate));
|
||||
|
@ -232,9 +231,10 @@ fn compile_upto(sess: session, cfg: ast::crate_cfg,
|
|||
if upto == cu_no_trans { return {crate: crate, tcx: some(ty_cx)}; }
|
||||
let outputs = option::get(outputs);
|
||||
|
||||
let maps = {mutbl_map: mutbl_map, root_map: root_map,
|
||||
let maps = {mutbl_map: mutbl_map,
|
||||
root_map: root_map,
|
||||
last_use_map: last_use_map,
|
||||
impl_map: impl_map, method_map: method_map,
|
||||
method_map: method_map,
|
||||
vtable_map: vtable_map};
|
||||
|
||||
let (llmod, link_meta) = time(time_passes, ~"translation", ||
|
||||
|
|
|
@ -46,7 +46,6 @@ type encode_parms = {
|
|||
reachable: hashmap<ast::node_id, ()>,
|
||||
reexports: ~[(~str, def_id)],
|
||||
reexports2: middle::resolve3::ExportMap2,
|
||||
impl_map: fn@(ast::node_id) -> ~[(ident, def_id)],
|
||||
item_symbols: hashmap<ast::node_id, ~str>,
|
||||
discrim_symbols: hashmap<ast::node_id, ~str>,
|
||||
link_meta: link_meta,
|
||||
|
@ -60,7 +59,6 @@ enum encode_ctxt = {
|
|||
reachable: hashmap<ast::node_id, ()>,
|
||||
reexports: ~[(~str, def_id)],
|
||||
reexports2: middle::resolve3::ExportMap2,
|
||||
impl_map: fn@(ast::node_id) -> ~[(ident, def_id)],
|
||||
item_symbols: hashmap<ast::node_id, ~str>,
|
||||
discrim_symbols: hashmap<ast::node_id, ~str>,
|
||||
link_meta: link_meta,
|
||||
|
@ -1049,7 +1047,6 @@ fn encode_metadata(parms: encode_parms, crate: @crate) -> ~[u8] {
|
|||
reachable: parms.reachable,
|
||||
reexports: parms.reexports,
|
||||
reexports2: parms.reexports2,
|
||||
impl_map: parms.impl_map,
|
||||
item_symbols: parms.item_symbols,
|
||||
discrim_symbols: parms.discrim_symbols,
|
||||
link_meta: parms.link_meta,
|
||||
|
|
|
@ -50,7 +50,6 @@ type maps = {
|
|||
mutbl_map: middle::borrowck::mutbl_map,
|
||||
root_map: middle::borrowck::root_map,
|
||||
last_use_map: middle::liveness::last_use_map,
|
||||
impl_map: middle::resolve3::ImplMap,
|
||||
method_map: middle::typeck::method_map,
|
||||
vtable_map: middle::typeck::vtable_map,
|
||||
};
|
||||
|
@ -727,9 +726,6 @@ fn encode_side_tables_for_id(ecx: @e::encode_ctxt,
|
|||
}
|
||||
}
|
||||
|
||||
// impl_map is not used except when emitting metadata,
|
||||
// don't need to keep it.
|
||||
|
||||
do option::iter(maps.method_map.find(id)) |mme| {
|
||||
do ebml_w.tag(c::tag_table_method_map) {
|
||||
ebml_w.id(id);
|
||||
|
|
|
@ -84,9 +84,6 @@ type MethodInfo = {
|
|||
};
|
||||
|
||||
type Impl = { did: def_id, ident: ident, methods: ~[@MethodInfo] };
|
||||
type ImplScope = @~[@Impl];
|
||||
type ImplScopes = @list<ImplScope>;
|
||||
type ImplMap = hashmap<node_id,ImplScopes>;
|
||||
|
||||
// Trait method resolution
|
||||
type TraitMap = @hashmap<node_id,@DVec<def_id>>;
|
||||
|
@ -452,9 +449,6 @@ struct Module {
|
|||
// The index of the import we're resolving.
|
||||
let mut resolved_import_count: uint;
|
||||
|
||||
// The list of implementation scopes, rooted from this module.
|
||||
let mut impl_scopes: ImplScopes;
|
||||
|
||||
new(parent_link: ParentLink, def_id: option<def_id>) {
|
||||
self.parent_link = parent_link;
|
||||
self.def_id = def_id;
|
||||
|
@ -469,8 +463,6 @@ struct Module {
|
|||
self.import_resolutions = atom_hashmap();
|
||||
self.glob_count = 0u;
|
||||
self.resolved_import_count = 0u;
|
||||
|
||||
self.impl_scopes = @nil;
|
||||
}
|
||||
|
||||
fn all_imports_resolved() -> bool {
|
||||
|
@ -708,7 +700,6 @@ struct Resolver {
|
|||
let namespaces: ~[Namespace];
|
||||
|
||||
let def_map: DefMap;
|
||||
let impl_map: ImplMap;
|
||||
let export_map: ExportMap;
|
||||
let export_map2: ExportMap2;
|
||||
let trait_map: TraitMap;
|
||||
|
@ -749,7 +740,6 @@ struct Resolver {
|
|||
self.namespaces = ~[ ModuleNS, TypeNS, ValueNS, ImplNS ];
|
||||
|
||||
self.def_map = int_hash();
|
||||
self.impl_map = int_hash();
|
||||
self.export_map = int_hash();
|
||||
self.export_map2 = int_hash();
|
||||
self.trait_map = @int_hash();
|
||||
|
@ -766,9 +756,6 @@ struct Resolver {
|
|||
self.record_exports();
|
||||
self.session.abort_if_errors();
|
||||
|
||||
self.build_impl_scopes();
|
||||
self.session.abort_if_errors();
|
||||
|
||||
self.resolve_crate();
|
||||
self.session.abort_if_errors();
|
||||
|
||||
|
@ -2809,106 +2796,6 @@ struct Resolver {
|
|||
}
|
||||
}
|
||||
|
||||
// Implementation scope creation
|
||||
//
|
||||
// This is a fairly simple pass that simply gathers up all the typeclass
|
||||
// implementations in scope and threads a series of singly-linked series
|
||||
// of impls through the tree.
|
||||
|
||||
fn build_impl_scopes() {
|
||||
let root_module = (*self.graph_root).get_module();
|
||||
self.build_impl_scopes_for_module_subtree(root_module);
|
||||
}
|
||||
|
||||
fn build_impl_scopes_for_module_subtree(module_: @Module) {
|
||||
// If this isn't a local crate, then bail out. We don't need to
|
||||
// resolve implementations for external crates.
|
||||
|
||||
match module_.def_id {
|
||||
some(def_id) if def_id.crate == local_crate => {
|
||||
// OK. Continue.
|
||||
}
|
||||
none => {
|
||||
// Resolve implementation scopes for the root module.
|
||||
}
|
||||
some(_) => {
|
||||
// Bail out.
|
||||
debug!{"(building impl scopes for module subtree) not \
|
||||
resolving implementations for `%s`",
|
||||
self.module_to_str(module_)};
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
self.build_impl_scope_for_module(module_);
|
||||
|
||||
for module_.children.each |_atom, child_name_bindings| {
|
||||
match (*child_name_bindings).get_module_if_available() {
|
||||
none => {
|
||||
// Nothing to do.
|
||||
}
|
||||
some(child_module) => {
|
||||
self.build_impl_scopes_for_module_subtree(child_module);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for module_.anonymous_children.each |_node_id, child_module| {
|
||||
self.build_impl_scopes_for_module_subtree(child_module);
|
||||
}
|
||||
}
|
||||
|
||||
fn build_impl_scope_for_module(module_: @Module) {
|
||||
let mut impl_scope = ~[];
|
||||
|
||||
debug!{"(building impl scope for module) processing module %s (%?)",
|
||||
self.module_to_str(module_),
|
||||
copy module_.def_id};
|
||||
|
||||
// Gather up all direct children implementations in the module.
|
||||
for module_.children.each |_impl_name, child_name_bindings| {
|
||||
if child_name_bindings.impl_defs.len() >= 1u {
|
||||
impl_scope += child_name_bindings.impl_defs;
|
||||
}
|
||||
}
|
||||
|
||||
debug!{"(building impl scope for module) found %u impl(s) as direct \
|
||||
children",
|
||||
impl_scope.len()};
|
||||
|
||||
// Gather up all imports.
|
||||
for module_.import_resolutions.each |_impl_name, import_resolution| {
|
||||
for (*import_resolution.impl_target).each |impl_target| {
|
||||
debug!{"(building impl scope for module) found impl def"};
|
||||
impl_scope += impl_target.bindings.impl_defs;
|
||||
}
|
||||
}
|
||||
|
||||
debug!{"(building impl scope for module) found %u impl(s) in total",
|
||||
impl_scope.len()};
|
||||
|
||||
// Determine the parent's implementation scope.
|
||||
let mut parent_impl_scopes;
|
||||
match module_.parent_link {
|
||||
NoParentLink => {
|
||||
parent_impl_scopes = @nil;
|
||||
}
|
||||
ModuleParentLink(parent_module_node, _) |
|
||||
BlockParentLink(parent_module_node, _) => {
|
||||
parent_impl_scopes = parent_module_node.impl_scopes;
|
||||
}
|
||||
}
|
||||
|
||||
// Create the new implementation scope, if it was nonempty, and chain
|
||||
// it up to the parent.
|
||||
|
||||
if impl_scope.len() >= 1u {
|
||||
module_.impl_scopes = @cons(@impl_scope, parent_impl_scopes);
|
||||
} else {
|
||||
module_.impl_scopes = parent_impl_scopes;
|
||||
}
|
||||
}
|
||||
|
||||
// AST resolution
|
||||
//
|
||||
// We maintain a list of value ribs and type ribs.
|
||||
|
@ -3095,11 +2982,6 @@ struct Resolver {
|
|||
fn resolve_crate() unsafe {
|
||||
debug!{"(resolving crate) starting"};
|
||||
|
||||
// To avoid a failure in metadata encoding later, we have to add the
|
||||
// crate-level implementation scopes
|
||||
|
||||
self.impl_map.insert(0, (*self.graph_root).get_module().impl_scopes);
|
||||
|
||||
// XXX: This is awful!
|
||||
let this = ptr::addr_of(self);
|
||||
visit_crate(*self.crate, (), mk_vt(@{
|
||||
|
@ -3669,8 +3551,6 @@ struct Resolver {
|
|||
|
||||
// Write the implementations in scope into the module metadata.
|
||||
debug!{"(resolving module) resolving module ID %d", id};
|
||||
self.impl_map.insert(id, self.current_module.impl_scopes);
|
||||
|
||||
visit_mod(module_, span, id, (), visitor);
|
||||
}
|
||||
|
||||
|
@ -4385,13 +4265,8 @@ struct Resolver {
|
|||
}
|
||||
|
||||
fn resolve_expr(expr: @expr, visitor: ResolveVisitor) {
|
||||
// First, write the implementations in scope into a table if the
|
||||
// expression might need them.
|
||||
|
||||
self.record_impls_for_expr_if_necessary(expr);
|
||||
|
||||
// Then record candidate traits for this expression if it could result
|
||||
// in the invocation of a method call.
|
||||
// First, record candidate traits for this expression if it could
|
||||
// result in the invocation of a method call.
|
||||
|
||||
self.record_candidate_traits_for_expr_if_necessary(expr);
|
||||
|
||||
|
@ -4506,19 +4381,6 @@ struct Resolver {
|
|||
}
|
||||
}
|
||||
|
||||
fn record_impls_for_expr_if_necessary(expr: @expr) {
|
||||
match expr.node {
|
||||
expr_field(*) | expr_path(*) | expr_cast(*) | expr_binary(*) |
|
||||
expr_unary(*) | expr_assign_op(*) | expr_index(*) => {
|
||||
self.impl_map.insert(expr.id,
|
||||
self.current_module.impl_scopes);
|
||||
}
|
||||
_ => {
|
||||
// Nothing to do.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn record_candidate_traits_for_expr_if_necessary(expr: @expr) {
|
||||
match expr.node {
|
||||
expr_field(_, ident, _) => {
|
||||
|
@ -4855,30 +4717,6 @@ struct Resolver {
|
|||
module_repr, value_repr, type_repr, impl_repr};
|
||||
}
|
||||
}
|
||||
|
||||
fn dump_impl_scopes(impl_scopes: ImplScopes) {
|
||||
debug!{"Dump of impl scopes:"};
|
||||
|
||||
let mut i = 0u;
|
||||
let mut impl_scopes = impl_scopes;
|
||||
loop {
|
||||
match *impl_scopes {
|
||||
cons(impl_scope, rest_impl_scopes) => {
|
||||
debug!{"Impl scope %u:", i};
|
||||
|
||||
for (*impl_scope).each |implementation| {
|
||||
debug!{"Impl: %s", *implementation.ident};
|
||||
}
|
||||
|
||||
i += 1u;
|
||||
impl_scopes = rest_impl_scopes;
|
||||
}
|
||||
nil => {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Entry point to crate resolution.
|
||||
|
@ -4886,7 +4724,6 @@ fn resolve_crate(session: session, lang_items: LanguageItems, crate: @crate)
|
|||
-> { def_map: DefMap,
|
||||
exp_map: ExportMap,
|
||||
exp_map2: ExportMap2,
|
||||
impl_map: ImplMap,
|
||||
trait_map: TraitMap } {
|
||||
|
||||
let resolver = @Resolver(session, lang_items, crate);
|
||||
|
@ -4895,7 +4732,6 @@ fn resolve_crate(session: session, lang_items: LanguageItems, crate: @crate)
|
|||
def_map: resolver.def_map,
|
||||
exp_map: resolver.export_map,
|
||||
exp_map2: resolver.export_map2,
|
||||
impl_map: resolver.impl_map,
|
||||
trait_map: resolver.trait_map
|
||||
};
|
||||
}
|
||||
|
|
|
@ -5645,7 +5645,6 @@ fn crate_ctxt_to_encode_parms(cx: @crate_ctxt)
|
|||
reachable: cx.reachable,
|
||||
reexports: reexports(cx),
|
||||
reexports2: cx.exp_map2,
|
||||
impl_map: |a| impl_map(cx, a),
|
||||
item_symbols: cx.item_symbols,
|
||||
discrim_symbols: cx.discrim_symbols,
|
||||
link_meta: cx.link_meta,
|
||||
|
@ -5669,15 +5668,6 @@ fn crate_ctxt_to_encode_parms(cx: @crate_ctxt)
|
|||
}
|
||||
return reexports;
|
||||
}
|
||||
|
||||
fn impl_map(cx: @crate_ctxt,
|
||||
id: ast::node_id) -> ~[(ast::ident, ast::def_id)] {
|
||||
let mut result = ~[];
|
||||
for list::each(cx.maps.impl_map.get(id)) |impls| {
|
||||
vec::push_all(result, (*impls).map(|i| (i.ident, i.did)));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
fn write_metadata(cx: @crate_ctxt, crate: @ast::crate) {
|
||||
|
|
Loading…
Reference in a new issue