rustc: Eliminate metadata's dependency on astencode

This commit is contained in:
Brian Anderson 2012-05-14 17:46:45 -07:00
parent 5c864e9de0
commit fce6a474b1
7 changed files with 56 additions and 41 deletions

View File

@ -1,16 +1,3 @@
export maps;
// Auxiliary maps of things to be encoded
type maps = {
mutbl_map: middle::borrowck::mutbl_map,
copy_map: middle::alias::copy_map,
last_uses: middle::last_use::last_uses,
impl_map: middle::resolve::impl_map,
method_map: middle::typeck::method_map,
vtable_map: middle::typeck::vtable_map,
spill_map: middle::last_use::spill_map
};
// Define the rustc API's that the metadata module has access to
// Over time we will reduce these dependencies and, once metadata has
// no dependencies on rustc it can move into its own crate.
@ -32,8 +19,6 @@ mod middle {
export borrowck;
import alias = middle_::alias;
export alias;
import astencode = middle_::astencode;
export astencode;
}
mod front {

View File

@ -98,11 +98,13 @@ enum found_ast {
// Finds the AST for this item in the crate metadata, if any. If the item was
// not marked for inlining, then the AST will not be present and hence none
// will be returned.
fn maybe_get_item_ast(tcx: ty::ctxt, maps: maps, def: ast::def_id)
fn maybe_get_item_ast(tcx: ty::ctxt, def: ast::def_id,
decode_inlined_item: decoder::decode_inlined_item)
-> found_ast {
let cstore = tcx.sess.cstore;
let cdata = cstore::get_crate_data(cstore, def.crate);
decoder::maybe_get_item_ast(cdata, tcx, maps, def.node)
decoder::maybe_get_item_ast(cdata, tcx, def.node,
decode_inlined_item)
}
fn get_enum_variants(tcx: ty::ctxt, def: ast::def_id) -> [ty::variant_info] {

View File

@ -15,7 +15,6 @@ import syntax::print::pprust;
import cmd=cstore::crate_metadata;
import util::ppaux::ty_to_str;
import ebml::deserializer;
import middle::astencode;
export get_class_fields;
export get_symbol;
@ -41,6 +40,7 @@ export get_item_path;
export maybe_find_item; // sketchy
export item_type; // sketchy
export maybe_get_item_ast;
export decode_inlined_item;
// Used internally by astencode:
export translate_def_id;
@ -339,19 +339,27 @@ fn get_item_path(cdata: cmd, id: ast::node_id) -> ast_map::path {
item_path(lookup_item(id, cdata.data))
}
fn maybe_get_item_ast(cdata: cmd, tcx: ty::ctxt, maps: maps,
id: ast::node_id) -> csearch::found_ast {
type decode_inlined_item = fn(
cdata: cstore::crate_metadata,
tcx: ty::ctxt,
path: ast_map::path,
par_doc: ebml::doc) -> option<ast::inlined_item>;
fn maybe_get_item_ast(cdata: cmd, tcx: ty::ctxt,
id: ast::node_id,
decode_inlined_item: decode_inlined_item
) -> csearch::found_ast {
#debug("Looking up item: %d", id);
let item_doc = lookup_item(id, cdata.data);
let path = vec::init(item_path(item_doc));
alt astencode::decode_inlined_item(cdata, tcx, maps, path, item_doc) {
alt decode_inlined_item(cdata, tcx, path, item_doc) {
some(ii) { csearch::found(ii) }
none {
alt item_parent_item(item_doc) {
some(did) {
let did = translate_def_id(cdata, did);
let parent_item = lookup_item(did.node, cdata.data);
alt astencode::decode_inlined_item(cdata, tcx, maps, path,
alt decode_inlined_item(cdata, tcx, path,
parent_item) {
some(ii) { csearch::found_parent(did, ii) }
none { csearch::not_found }

View File

@ -44,11 +44,11 @@ type encode_parms = {
tcx: ty::ctxt,
reachable: hashmap<ast::node_id, ()>,
exp_map: resolve::exp_map,
impl_map: resolve::impl_map,
item_symbols: hashmap<ast::node_id, str>,
discrim_symbols: hashmap<ast::node_id, str>,
link_meta: back::link::link_meta,
cstore: cstore::cstore,
maps: maps,
encode_inlined_item: encode_inlined_item
};
@ -56,11 +56,11 @@ enum encode_ctxt = {
tcx: ty::ctxt,
reachable: hashmap<ast::node_id, ()>,
exp_map: resolve::exp_map,
impl_map: resolve::impl_map,
item_symbols: hashmap<ast::node_id, str>,
discrim_symbols: hashmap<ast::node_id, str>,
link_meta: back::link::link_meta,
cstore: cstore::cstore,
maps: maps,
encode_inlined_item: encode_inlined_item,
type_abbrevs: abbrev_map
};
@ -396,7 +396,7 @@ fn encode_info_for_mod(ecx: @encode_ctxt, ebml_w: ebml::writer, md: _mod,
encode_def_id(ebml_w, local_def(id));
encode_family(ebml_w, 'm');
encode_name(ebml_w, name);
alt ecx.maps.impl_map.get(id) {
alt ecx.impl_map.get(id) {
list::cons(impls, @list::nil) {
for vec::each(*impls) {|i|
if ast_util::is_exported(i.ident, md) {
@ -1056,11 +1056,11 @@ fn encode_metadata(parms: encode_parms, crate: @crate) -> [u8] {
tcx: parms.tcx,
reachable: parms.reachable,
exp_map: parms.exp_map,
impl_map: parms.impl_map,
item_symbols: parms.item_symbols,
discrim_symbols: parms.discrim_symbols,
link_meta: parms.link_meta,
cstore: parms.cstore,
maps: parms.maps,
encode_inlined_item: parms.encode_inlined_item,
type_abbrevs: ty::new_ty_hash()
});

View File

@ -30,7 +30,6 @@ import middle::freevars::{freevar_entry,
import c = metadata::common;
import e = metadata::encoder;
import cstore = metadata::cstore;
import metadata::maps;
import metadata::encoder;
import metadata::decoder;
import metadata::tyencode;
@ -43,9 +42,21 @@ import syntax::codemap;
import syntax::parse;
import syntax::print::pprust;
export maps;
export encode_inlined_item;
export decode_inlined_item;
// Auxiliary maps of things to be encoded
type maps = {
mutbl_map: middle::borrowck::mutbl_map,
copy_map: middle::alias::copy_map,
last_uses: middle::last_use::last_uses,
impl_map: middle::resolve::impl_map,
method_map: middle::typeck::method_map,
vtable_map: middle::typeck::vtable_map,
spill_map: middle::last_use::spill_map
};
type decode_ctxt = @{
cdata: cstore::crate_metadata,
tcx: ty::ctxt,
@ -68,7 +79,8 @@ iface tr {
fn encode_inlined_item(ecx: @e::encode_ctxt,
ebml_w: ebml::writer,
path: ast_map::path,
ii: ast::inlined_item) {
ii: ast::inlined_item,
maps: maps) {
#debug["> Encoding inlined item: %s::%s (%u)",
ast_map::path_to_str(path), ii.ident(),
ebml_w.writer.tell()];
@ -77,7 +89,7 @@ fn encode_inlined_item(ecx: @e::encode_ctxt,
ebml_w.wr_tag(c::tag_ast as uint) {||
encode_id_range(ebml_w, id_range);
encode_ast(ebml_w, simplify_ast(ii));
encode_side_tables_for_ii(ecx, ebml_w, ii);
encode_side_tables_for_ii(ecx, maps, ebml_w, ii);
}
#debug["< Encoded inlined fn: %s::%s (%u)",
@ -719,6 +731,7 @@ impl writer for ebml::writer {
}
fn encode_side_tables_for_ii(ecx: @e::encode_ctxt,
maps: maps,
ebml_w: ebml::writer,
ii: ast::inlined_item) {
ebml_w.wr_tag(c::tag_table as uint) {||
@ -726,12 +739,13 @@ fn encode_side_tables_for_ii(ecx: @e::encode_ctxt,
// Note: this will cause a copy of ebml_w, which is bad as
// it has mut fields. But I believe it's harmless since
// we generate balanced EBML.
encode_side_tables_for_id(ecx, ebml_w, id)
encode_side_tables_for_id(ecx, maps, ebml_w, id)
});
}
}
fn encode_side_tables_for_id(ecx: @e::encode_ctxt,
maps: maps,
ebml_w: ebml::writer,
id: ast::node_id) {
let tcx = ecx.tcx;
@ -808,25 +822,25 @@ fn encode_side_tables_for_id(ecx: @e::encode_ctxt,
// }
//}
option::iter(ecx.maps.mutbl_map.find(id)) {|_m|
option::iter(maps.mutbl_map.find(id)) {|_m|
ebml_w.tag(c::tag_table_mutbl) {||
ebml_w.id(id);
}
}
option::iter(ecx.maps.copy_map.find(id)) {|_m|
option::iter(maps.copy_map.find(id)) {|_m|
ebml_w.tag(c::tag_table_copy) {||
ebml_w.id(id);
}
}
option::iter(ecx.maps.spill_map.find(id)) {|_m|
option::iter(maps.spill_map.find(id)) {|_m|
ebml_w.tag(c::tag_table_spill) {||
ebml_w.id(id);
}
}
option::iter(ecx.maps.last_uses.find(id)) {|m|
option::iter(maps.last_uses.find(id)) {|m|
ebml_w.tag(c::tag_table_last_use) {||
ebml_w.id(id);
ebml_w.tag(c::tag_table_val) {||
@ -838,7 +852,7 @@ 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.
option::iter(ecx.maps.method_map.find(id)) {|mo|
option::iter(maps.method_map.find(id)) {|mo|
ebml_w.tag(c::tag_table_method_map) {||
ebml_w.id(id);
ebml_w.tag(c::tag_table_val) {||
@ -847,7 +861,7 @@ fn encode_side_tables_for_id(ecx: @e::encode_ctxt,
}
}
option::iter(ecx.maps.vtable_map.find(id)) {|dr|
option::iter(maps.vtable_map.find(id)) {|dr|
ebml_w.tag(c::tag_table_vtable_map) {||
ebml_w.id(id);
ebml_w.tag(c::tag_table_val) {||

View File

@ -2066,7 +2066,10 @@ fn maybe_instantiate_inline(ccx: @crate_ctxt, fn_id: ast::def_id)
}
some(none) { fn_id } // Not inlinable
none { // Not seen yet
alt check csearch::maybe_get_item_ast(ccx.tcx, ccx.maps, fn_id) {
alt check csearch::maybe_get_item_ast(
ccx.tcx, fn_id,
bind astencode::decode_inlined_item(_, _, ccx.maps, _, _)) {
csearch::not_found {
ccx.external.insert(fn_id, none);
fn_id
@ -4991,16 +4994,19 @@ fn fill_crate_map(ccx: @crate_ctxt, map: ValueRef) {
fn crate_ctxt_to_encode_parms(cx: @crate_ctxt)
-> encoder::encode_parms {
let encode_inlined_item =
bind astencode::encode_inlined_item(_, _, _, _, cx.maps);
{
tcx: cx.tcx,
reachable: cx.reachable,
exp_map: cx.exp_map,
impl_map: cx.maps.impl_map,
item_symbols: cx.item_symbols,
discrim_symbols: cx.discrim_symbols,
link_meta: cx.link_meta,
cstore: cx.sess.cstore,
maps: cx.maps,
encode_inlined_item: middle::astencode::encode_inlined_item
encode_inlined_item: encode_inlined_item
}
}
@ -5036,7 +5042,7 @@ fn write_abi_version(ccx: @crate_ctxt) {
fn trans_crate(sess: session::session, crate: @ast::crate, tcx: ty::ctxt,
output: str, emap: resolve::exp_map,
maps: metadata::maps)
maps: astencode::maps)
-> (ModuleRef, link::link_meta) {
let sha = std::sha1::sha1();
let link_meta = link::build_link_meta(sess, *crate, output, sha);

View File

@ -101,7 +101,7 @@ type crate_ctxt = {
type_short_names: hashmap<ty::t, str>,
all_llvm_symbols: set<str>,
tcx: ty::ctxt,
maps: metadata::maps,
maps: astencode::maps,
stats: stats,
upcalls: @upcall::upcalls,
tydesc_type: TypeRef,