rustc: Break another dependency between metadata and resolve

This commit is contained in:
Brian Anderson 2012-05-16 22:28:01 -07:00
parent 6a41eb0192
commit 322b20d14d
2 changed files with 43 additions and 35 deletions

View File

@ -2,7 +2,7 @@
import util::ppaux::ty_to_str; import util::ppaux::ty_to_str;
import std::{ebml, map, list}; import std::{ebml, map};
import std::map::hashmap; import std::map::hashmap;
import io::writer_util; import io::writer_util;
import ebml::writer; import ebml::writer;
@ -17,7 +17,6 @@ import middle::ast_map;
import syntax::attr; import syntax::attr;
import std::serialization::serializer; import std::serialization::serializer;
import std::ebml::serializer; import std::ebml::serializer;
import middle::resolve;
import syntax::ast; import syntax::ast;
import syntax::diagnostic::span_handler; import syntax::diagnostic::span_handler;
@ -49,7 +48,7 @@ type encode_parms = {
tcx: ty::ctxt, tcx: ty::ctxt,
reachable: hashmap<ast::node_id, ()>, reachable: hashmap<ast::node_id, ()>,
reexports: [(str, def_id)], reexports: [(str, def_id)],
impl_map: resolve::impl_map, impl_map: fn@(ast::node_id) -> [(ident, def_id)],
item_symbols: hashmap<ast::node_id, str>, item_symbols: hashmap<ast::node_id, str>,
discrim_symbols: hashmap<ast::node_id, str>, discrim_symbols: hashmap<ast::node_id, str>,
link_meta: link_meta, link_meta: link_meta,
@ -62,7 +61,7 @@ enum encode_ctxt = {
tcx: ty::ctxt, tcx: ty::ctxt,
reachable: hashmap<ast::node_id, ()>, reachable: hashmap<ast::node_id, ()>,
reexports: [(str, def_id)], reexports: [(str, def_id)],
impl_map: resolve::impl_map, impl_map: fn@(ast::node_id) -> [(ident, def_id)],
item_symbols: hashmap<ast::node_id, str>, item_symbols: hashmap<ast::node_id, str>,
discrim_symbols: hashmap<ast::node_id, str>, discrim_symbols: hashmap<ast::node_id, str>,
link_meta: link_meta, link_meta: link_meta,
@ -405,36 +404,31 @@ fn encode_info_for_mod(ecx: @encode_ctxt, ebml_w: ebml::writer, md: _mod,
encode_def_id(ebml_w, local_def(id)); encode_def_id(ebml_w, local_def(id));
encode_family(ebml_w, 'm'); encode_family(ebml_w, 'm');
encode_name(ebml_w, name); encode_name(ebml_w, name);
alt ecx.impl_map.get(id) { let impls = ecx.impl_map(id);
list::cons(impls, @list::nil) { for impls.each {|i|
for vec::each(*impls) {|i| let (ident, did) = i;
if ast_util::is_exported(i.ident, md) { if ast_util::is_exported(ident, md) {
ebml_w.start_tag(tag_mod_impl); ebml_w.start_tag(tag_mod_impl);
/* If did stands for an iface /* If did stands for an iface
ref, we need to map it to its parent class */ ref, we need to map it to its parent class */
alt ecx.tcx.items.get(i.did.node) { alt ecx.tcx.items.get(did.node) {
ast_map::node_item(it@@{node: cl@item_class(*),_},_) { ast_map::node_item(it@@{node: cl@item_class(*),_},_) {
ebml_w.wr_str(def_to_str(local_def(it.id))); ebml_w.wr_str(def_to_str(local_def(it.id)));
some(ty::lookup_item_type(ecx.tcx, i.did).ty) some(ty::lookup_item_type(ecx.tcx, did).ty)
} }
ast_map::node_item(@{node: item_impl(_,_, ast_map::node_item(@{node: item_impl(_,_,
some(ifce),_,_),_},_) { some(ifce),_,_),_},_) {
ebml_w.wr_str(def_to_str(i.did)); ebml_w.wr_str(def_to_str(did));
some(ty::node_id_to_type(ecx.tcx, ifce.id)) some(ty::node_id_to_type(ecx.tcx, ifce.id))
} }
_ { _ {
ebml_w.wr_str(def_to_str(i.did)); none ebml_w.wr_str(def_to_str(did)); none
} }
}; };
ebml_w.end_tag(); ebml_w.end_tag();
} // if } // if
} // for } // for
} // list::cons alt
_ {
ecx.diag.handler().bug(#fmt("encode_info_for_mod: empty impl_map \
entry for %?", path));
}
}
encode_path(ebml_w, path, ast_map::path_mod(name)); encode_path(ebml_w, path, ast_map::path_mod(name));
ebml_w.end_tag(); ebml_w.end_tag();
} }

View File

@ -14,7 +14,7 @@
// int) and rec(x=int, y=int, z=int) will have the same TypeRef. // int) and rec(x=int, y=int, z=int) will have the same TypeRef.
import libc::c_uint; import libc::c_uint;
import std::{map, time}; import std::{map, time, list};
import std::map::hashmap; import std::map::hashmap;
import std::map::{int_hash, str_hash}; import std::map::{int_hash, str_hash};
import driver::session; import driver::session;
@ -5202,7 +5202,7 @@ fn crate_ctxt_to_encode_parms(cx: @crate_ctxt)
tcx: cx.tcx, tcx: cx.tcx,
reachable: cx.reachable, reachable: cx.reachable,
reexports: reexports(cx), reexports: reexports(cx),
impl_map: cx.maps.impl_map, impl_map: impl_map(cx, _),
item_symbols: cx.item_symbols, item_symbols: cx.item_symbols,
discrim_symbols: cx.discrim_symbols, discrim_symbols: cx.discrim_symbols,
link_meta: cx.link_meta, link_meta: cx.link_meta,
@ -5226,6 +5226,20 @@ fn crate_ctxt_to_encode_parms(cx: @crate_ctxt)
ret reexports; ret reexports;
} }
fn impl_map(cx: @crate_ctxt,
id: ast::node_id) -> [(ast::ident, ast::def_id)] {
alt cx.maps.impl_map.get(id) {
list::cons(impls, @list::nil) {
(*impls).map {|i|
(i.ident, i.did)
}
}
_ {
cx.sess.bug(#fmt("encode_info_for_mod: empty impl_map \
entry for %?", id));
}
}
}
} }
fn write_metadata(cx: @crate_ctxt, crate: @ast::crate) { fn write_metadata(cx: @crate_ctxt, crate: @ast::crate) {