From 6a41eb0192cfe1489c4f5720082f09ed4fbe9eda Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Wed, 16 May 2012 21:50:17 -0700 Subject: [PATCH] rustc: Break a dependency between metadata and resolve --- src/rustc/metadata/encoder.rs | 26 ++++++++++---------------- src/rustc/middle/trans/base.rs | 20 ++++++++++++++++++-- 2 files changed, 28 insertions(+), 18 deletions(-) diff --git a/src/rustc/metadata/encoder.rs b/src/rustc/metadata/encoder.rs index 4638d8ea4e5..c897767d2b7 100644 --- a/src/rustc/metadata/encoder.rs +++ b/src/rustc/metadata/encoder.rs @@ -48,7 +48,7 @@ type encode_parms = { diag: span_handler, tcx: ty::ctxt, reachable: hashmap, - exp_map: resolve::exp_map, + reexports: [(str, def_id)], impl_map: resolve::impl_map, item_symbols: hashmap, discrim_symbols: hashmap, @@ -61,7 +61,7 @@ enum encode_ctxt = { diag: span_handler, tcx: ty::ctxt, reachable: hashmap, - exp_map: resolve::exp_map, + reexports: [(str, def_id)], impl_map: resolve::impl_map, item_symbols: hashmap, discrim_symbols: hashmap, @@ -260,19 +260,13 @@ fn encode_item_paths(ebml_w: ebml::writer, ecx: @encode_ctxt, crate: @crate) fn encode_reexport_paths(ebml_w: ebml::writer, ecx: @encode_ctxt, &index: [entry]) { - let tcx = ecx.tcx; - for ecx.exp_map.each {|exp_id, defs| - for defs.each {|def| - if !def.reexp { cont; } - let path = alt check tcx.items.get(exp_id) { - ast_map::node_export(_, path) { ast_map::path_to_str(*path) } - }; - index += [{val: path, pos: ebml_w.writer.tell()}]; - ebml_w.start_tag(tag_paths_data_item); - encode_name(ebml_w, path); - encode_def_id(ebml_w, def.id); - ebml_w.end_tag(); - } + for ecx.reexports.each {|reexport| + let (path, def_id) = reexport; + index += [{val: path, pos: ebml_w.writer.tell()}]; + ebml_w.start_tag(tag_paths_data_item); + encode_name(ebml_w, path); + encode_def_id(ebml_w, def_id); + ebml_w.end_tag(); } } @@ -1071,7 +1065,7 @@ fn encode_metadata(parms: encode_parms, crate: @crate) -> [u8] { diag: parms.diag, tcx: parms.tcx, reachable: parms.reachable, - exp_map: parms.exp_map, + reexports: parms.reexports, impl_map: parms.impl_map, item_symbols: parms.item_symbols, discrim_symbols: parms.discrim_symbols, diff --git a/src/rustc/middle/trans/base.rs b/src/rustc/middle/trans/base.rs index 16e5e07b0cf..41c065bb025 100644 --- a/src/rustc/middle/trans/base.rs +++ b/src/rustc/middle/trans/base.rs @@ -5197,17 +5197,33 @@ fn crate_ctxt_to_encode_parms(cx: @crate_ctxt) let encode_inlined_item = bind astencode::encode_inlined_item(_, _, _, _, cx.maps); - { + ret { diag: cx.sess.diagnostic(), tcx: cx.tcx, reachable: cx.reachable, - exp_map: cx.exp_map, + reexports: reexports(cx), 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, encode_inlined_item: encode_inlined_item + }; + + fn reexports(cx: @crate_ctxt) -> [(str, ast::def_id)] { + let mut reexports = []; + for cx.exp_map.each {|exp_id, defs| + for defs.each {|def| + if !def.reexp { cont; } + let path = alt check cx.tcx.items.get(exp_id) { + ast_map::node_export(_, path) { + ast_map::path_to_str(*path) + } + }; + reexports += [(path, def.id)]; + } + } + ret reexports; } }