From fce6a474b1dc1f46b041703f9f66941c0fa4cff2 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Mon, 14 May 2012 17:46:45 -0700 Subject: [PATCH] rustc: Eliminate metadata's dependency on astencode --- src/rustc/metadata.rs | 15 -------------- src/rustc/metadata/csearch.rs | 6 ++++-- src/rustc/metadata/decoder.rs | 18 ++++++++++++----- src/rustc/metadata/encoder.rs | 8 ++++---- src/rustc/middle/astencode.rs | 34 ++++++++++++++++++++++---------- src/rustc/middle/trans/base.rs | 14 +++++++++---- src/rustc/middle/trans/common.rs | 2 +- 7 files changed, 56 insertions(+), 41 deletions(-) diff --git a/src/rustc/metadata.rs b/src/rustc/metadata.rs index 61ba70e73e7..27827ba070c 100644 --- a/src/rustc/metadata.rs +++ b/src/rustc/metadata.rs @@ -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 { diff --git a/src/rustc/metadata/csearch.rs b/src/rustc/metadata/csearch.rs index e691f09221f..333ad2806c4 100644 --- a/src/rustc/metadata/csearch.rs +++ b/src/rustc/metadata/csearch.rs @@ -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] { diff --git a/src/rustc/metadata/decoder.rs b/src/rustc/metadata/decoder.rs index 4ec7a7af340..b91deaddba7 100644 --- a/src/rustc/metadata/decoder.rs +++ b/src/rustc/metadata/decoder.rs @@ -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; + +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 } diff --git a/src/rustc/metadata/encoder.rs b/src/rustc/metadata/encoder.rs index 73c2faa5161..a1ba3ad841d 100644 --- a/src/rustc/metadata/encoder.rs +++ b/src/rustc/metadata/encoder.rs @@ -44,11 +44,11 @@ type encode_parms = { tcx: ty::ctxt, reachable: hashmap, exp_map: resolve::exp_map, + impl_map: resolve::impl_map, item_symbols: hashmap, discrim_symbols: hashmap, 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, exp_map: resolve::exp_map, + impl_map: resolve::impl_map, item_symbols: hashmap, discrim_symbols: hashmap, 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() }); diff --git a/src/rustc/middle/astencode.rs b/src/rustc/middle/astencode.rs index b78c94de663..634a3c8a9cf 100644 --- a/src/rustc/middle/astencode.rs +++ b/src/rustc/middle/astencode.rs @@ -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) {|| diff --git a/src/rustc/middle/trans/base.rs b/src/rustc/middle/trans/base.rs index e88ce94d788..b2ffc09acaa 100644 --- a/src/rustc/middle/trans/base.rs +++ b/src/rustc/middle/trans/base.rs @@ -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); diff --git a/src/rustc/middle/trans/common.rs b/src/rustc/middle/trans/common.rs index ad2b86f395b..ca9213205f8 100644 --- a/src/rustc/middle/trans/common.rs +++ b/src/rustc/middle/trans/common.rs @@ -101,7 +101,7 @@ type crate_ctxt = { type_short_names: hashmap, all_llvm_symbols: set, tcx: ty::ctxt, - maps: metadata::maps, + maps: astencode::maps, stats: stats, upcalls: @upcall::upcalls, tydesc_type: TypeRef,