mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-26 00:34:06 +00:00
Move external-reachability checker to trans
Preparation for a fix for issue #2020
This commit is contained in:
parent
ccaace6587
commit
ade1207ba3
@ -29,8 +29,7 @@ export encode_def_id;
|
||||
type abbrev_map = map::hashmap<ty::t, tyencode::ty_abbrev>;
|
||||
|
||||
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<str>]) {
|
||||
// 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<int>],
|
||||
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);
|
||||
|
@ -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::<ValueRef>(),
|
||||
exp_map: emap,
|
||||
reachable: reachable,
|
||||
item_symbols: int_hash::<str>(),
|
||||
mutable main_fn: none::<ValueRef>,
|
||||
link_meta: link_meta,
|
||||
|
@ -79,6 +79,7 @@ type crate_ctxt = {
|
||||
intrinsics: hashmap<str, ValueRef>,
|
||||
item_vals: hashmap<ast::node_id, ValueRef>,
|
||||
exp_map: resolve::exp_map,
|
||||
reachable: reachable::map,
|
||||
item_symbols: hashmap<ast::node_id, str>,
|
||||
mutable main_fn: option<ValueRef>,
|
||||
link_meta: link::link_meta,
|
||||
|
@ -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<node_id, ()>;
|
||||
|
||||
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<ctx>) {
|
||||
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); }
|
||||
_ {}
|
||||
}
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user