diff --git a/src/rustc/metadata/encoder.rs b/src/rustc/metadata/encoder.rs index 4135d738b2f..e36b982ff12 100644 --- a/src/rustc/metadata/encoder.rs +++ b/src/rustc/metadata/encoder.rs @@ -29,8 +29,7 @@ export encode_def_id; type abbrev_map = map::hashmap; type encode_ctxt = {ccx: @crate_ctxt, - type_abbrevs: abbrev_map, - reachable: reachable::map}; + type_abbrevs: abbrev_map}; // Path table encoding fn encode_name(ebml_w: ebml::writer, name: str) { @@ -97,7 +96,7 @@ fn encode_module_item_paths(ebml_w: ebml::writer, ecx: @encode_ctxt, module: _mod, path: [str], &index: [entry]) { // FIXME factor out add_to_index/start/encode_name/encode_def_id/end ops for it: @item in module.items { - if !ecx.reachable.contains_key(it.id) || + if !ecx.ccx.reachable.contains_key(it.id) || !ast_util::is_exported(it.ident, module) { cont; } alt it.node { item_const(_, _) { @@ -430,7 +429,7 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item, let tcx = ecx.ccx.tcx; let must_write = alt item.node { item_enum(_, _) { true } _ { false } }; - if !must_write && !ecx.reachable.contains_key(item.id) { ret; } + if !must_write && !ecx.ccx.reachable.contains_key(item.id) { ret; } *index += [{val: item.id, pos: ebml_w.writer.tell()}]; alt item.node { @@ -598,7 +597,7 @@ fn encode_info_for_native_item(ecx: @encode_ctxt, ebml_w: ebml::writer, nitem: @native_item, index: @mutable [entry], path: ast_map::path, abi: native_abi) { - if !ecx.reachable.contains_key(nitem.id) { ret; } + if !ecx.ccx.reachable.contains_key(nitem.id) { ret; } *index += [{val: nitem.id, pos: ebml_w.writer.tell()}]; ebml_w.start_tag(tag_items_data_item); @@ -861,12 +860,7 @@ fn encode_hash(ebml_w: ebml::writer, hash: str) { } fn encode_metadata(cx: @crate_ctxt, crate: @crate) -> [u8] { - - let reachable = reachable::find_reachable(cx, crate.node.module); - let abbrevs = ty::new_ty_hash(); - let ecx = @{ccx: cx, - type_abbrevs: abbrevs, - reachable: reachable}; + let ecx = @{ccx: cx, type_abbrevs: ty::new_ty_hash()}; let buf = io::mem_buffer(); let buf_w = io::mem_buffer_writer(buf); diff --git a/src/rustc/middle/trans/base.rs b/src/rustc/middle/trans/base.rs index 93c291fa48b..6a64f2ddc2f 100644 --- a/src/rustc/middle/trans/base.rs +++ b/src/rustc/middle/trans/base.rs @@ -4604,6 +4604,8 @@ fn trans_crate(sess: session::session, crate: @ast::crate, tcx: ty::ctxt, -> (ModuleRef, link::link_meta) { let sha = std::sha1::sha1(); let link_meta = link::build_link_meta(sess, *crate, output, sha); + let reachable = reachable::find_reachable(crate.node.module, emap, tcx, + maps.method_map); // Append ".rc" to crate name as LLVM module identifier. // @@ -4658,6 +4660,7 @@ fn trans_crate(sess: session::session, crate: @ast::crate, tcx: ty::ctxt, intrinsics: intrinsics, item_vals: int_hash::(), exp_map: emap, + reachable: reachable, item_symbols: int_hash::(), mutable main_fn: none::, link_meta: link_meta, diff --git a/src/rustc/middle/trans/common.rs b/src/rustc/middle/trans/common.rs index 07a9e22952b..940a1848821 100644 --- a/src/rustc/middle/trans/common.rs +++ b/src/rustc/middle/trans/common.rs @@ -79,6 +79,7 @@ type crate_ctxt = { intrinsics: hashmap, item_vals: hashmap, exp_map: resolve::exp_map, + reachable: reachable::map, item_symbols: hashmap, mutable main_fn: option, link_meta: link::link_meta, diff --git a/src/rustc/metadata/reachable.rs b/src/rustc/middle/trans/reachable.rs similarity index 88% rename from src/rustc/metadata/reachable.rs rename to src/rustc/middle/trans/reachable.rs index 1ee2d8eab95..696932dd901 100644 --- a/src/rustc/metadata/reachable.rs +++ b/src/rustc/middle/trans/reachable.rs @@ -5,7 +5,6 @@ // makes all other generics or inline functions that it references // reachable as well. -import middle::{resolve, ast_map, typeck}; import syntax::ast::*; import syntax::{visit, ast_util}; import syntax::ast_util::def_id_of_def; @@ -16,13 +15,15 @@ export map, find_reachable; type map = std::map::hashmap; -type ctx = {ccx: @middle::trans::common::crate_ctxt, +type ctx = {exp_map: resolve::exp_map, + tcx: ty::ctxt, + method_map: typeck::method_map, rmap: map}; -fn find_reachable(ccx: @middle::trans::common::crate_ctxt, crate_mod: _mod) - -> map { +fn find_reachable(crate_mod: _mod, exp_map: resolve::exp_map, + tcx: ty::ctxt, method_map: typeck::method_map) -> map { let rmap = std::map::int_hash(); - let cx = {ccx: ccx, rmap: rmap}; + let cx = {exp_map: exp_map, tcx: tcx, method_map: method_map, rmap: rmap}; traverse_public_mod(cx, crate_mod); traverse_all_resources(cx, crate_mod); rmap @@ -50,14 +51,14 @@ fn traverse_exports(cx: ctx, vis: [@view_item]) -> bool { } fn traverse_export(cx: ctx, exp_id: node_id) { - option::may(cx.ccx.exp_map.find(exp_id)) {|defs| + option::may(cx.exp_map.find(exp_id)) {|defs| for def in defs { traverse_def_id(cx, def.id); } } } fn traverse_def_id(cx: ctx, did: def_id) { if did.crate != local_crate { ret; } - alt cx.ccx.tcx.items.get(did.node) { + alt cx.tcx.items.get(did.node) { ast_map::node_item(item, _) { traverse_public_item(cx, item); } ast_map::node_method(_, impl_id, _) { traverse_def_id(cx, impl_id); } ast_map::node_native_item(item, _, _) { cx.rmap.insert(item.id, ()); } @@ -106,10 +107,10 @@ fn traverse_inline_body(cx: ctx, body: blk) { fn traverse_expr(e: @expr, cx: ctx, v: visit::vt) { alt e.node { expr_path(_) { - traverse_def_id(cx, def_id_of_def(cx.ccx.tcx.def_map.get(e.id))); + traverse_def_id(cx, def_id_of_def(cx.tcx.def_map.get(e.id))); } expr_field(_, _, _) { - alt cx.ccx.maps.method_map.find(e.id) { + alt cx.method_map.find(e.id) { some(typeck::method_static(did)) { traverse_def_id(cx, did); } _ {} } diff --git a/src/rustc/rustc.rc b/src/rustc/rustc.rc index 05e073155e7..2560d02ebc4 100644 --- a/src/rustc/rustc.rc +++ b/src/rustc/rustc.rc @@ -28,6 +28,7 @@ mod middle { mod shape; mod debuginfo; mod type_use; + mod reachable; } mod ty; mod ast_map; @@ -131,7 +132,6 @@ mod metadata { mod creader; mod cstore; mod csearch; - mod reachable; } mod driver {