move `export_map` into the tcx

This commit is contained in:
Niko Matsakis 2017-03-23 14:18:25 -04:00
parent d5580374d7
commit a3a5ff98eb
11 changed files with 26 additions and 46 deletions

View File

@ -255,8 +255,8 @@ pub trait CrateStore {
fn used_crates(&self, prefer: LinkagePreference) -> Vec<(CrateNum, LibSource)>;
fn used_crate_source(&self, cnum: CrateNum) -> CrateSource;
fn extern_mod_stmt_cnum(&self, emod_id: ast::NodeId) -> Option<CrateNum>;
fn encode_metadata<'a, 'tcx>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>,
reexports: &def::ExportMap,
fn encode_metadata<'a, 'tcx>(&self,
tcx: TyCtxt<'a, 'tcx, 'tcx>,
link_meta: &LinkMeta,
reachable: &NodeSet) -> Vec<u8>;
fn metadata_encoding_version(&self) -> &[u8];
@ -412,10 +412,10 @@ impl CrateStore for DummyCrateStore {
{ vec![] }
fn used_crate_source(&self, cnum: CrateNum) -> CrateSource { bug!("used_crate_source") }
fn extern_mod_stmt_cnum(&self, emod_id: ast::NodeId) -> Option<CrateNum> { None }
fn encode_metadata<'a, 'tcx>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>,
reexports: &def::ExportMap,
link_meta: &LinkMeta,
reachable: &NodeSet) -> Vec<u8> { vec![] }
fn encode_metadata<'a, 'tcx>(&self,
tcx: TyCtxt<'a, 'tcx, 'tcx>,
link_meta: &LinkMeta,
reachable: &NodeSet) -> Vec<u8> { vec![] }
fn metadata_encoding_version(&self) -> &[u8] { bug!("metadata_encoding_version") }
}

View File

@ -15,7 +15,7 @@ use session::Session;
use lint;
use middle;
use hir::TraitMap;
use hir::def::Def;
use hir::def::{Def, ExportMap};
use hir::def_id::{CrateNum, DefId, LOCAL_CRATE};
use hir::map as hir_map;
use hir::map::DisambiguatedDefPathData;
@ -416,6 +416,9 @@ pub struct GlobalCtxt<'tcx> {
/// is relevant; generated by resolve.
pub trait_map: TraitMap,
/// Export map produced by name resolution.
pub export_map: ExportMap,
pub named_region_map: resolve_lifetime::NamedRegionMap,
pub region_maps: RegionMaps,
@ -698,6 +701,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
region_maps: region_maps,
variance_computed: Cell::new(false),
trait_map: resolutions.trait_map,
export_map: resolutions.export_map,
fulfilled_predicates: RefCell::new(fulfilled_predicates),
hir: hir,
maps: maps::Maps::new(dep_graph, providers),

View File

@ -110,7 +110,6 @@ mod sty;
/// produced by the driver and fed to trans and later passes.
#[derive(Clone)]
pub struct CrateAnalysis {
pub export_map: ExportMap,
pub access_levels: middle::privacy::AccessLevels,
pub reachable: NodeSet,
pub name: String,
@ -122,6 +121,7 @@ pub struct Resolutions {
pub freevars: FreevarMap,
pub trait_map: TraitMap,
pub maybe_unused_trait_imports: NodeSet,
pub export_map: ExportMap,
}
#[derive(Clone, Copy, PartialEq, Eq, Debug)]

View File

@ -807,7 +807,6 @@ pub fn phase_2_configure_and_expand<F>(sess: &Session,
expanded_crate: krate,
defs: resolver.definitions,
analysis: ty::CrateAnalysis {
export_map: resolver.export_map,
access_levels: AccessLevels::default(),
reachable: NodeSet(),
name: crate_name.to_string(),
@ -815,10 +814,11 @@ pub fn phase_2_configure_and_expand<F>(sess: &Session,
},
resolutions: Resolutions {
freevars: resolver.freevars,
export_map: resolver.export_map,
trait_map: resolver.trait_map,
maybe_unused_trait_imports: resolver.maybe_unused_trait_imports,
},
hir_forest: hir_forest
hir_forest: hir_forest,
})
}
@ -932,7 +932,7 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(sess: &'tcx Session,
analysis.access_levels =
time(time_passes, "privacy checking", || {
rustc_privacy::check_crate(tcx, &analysis.export_map)
rustc_privacy::check_crate(tcx)
});
time(time_passes,

View File

@ -496,12 +496,12 @@ impl CrateStore for cstore::CStore {
self.do_extern_mod_stmt_cnum(emod_id)
}
fn encode_metadata<'a, 'tcx>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>,
reexports: &def::ExportMap,
fn encode_metadata<'a, 'tcx>(&self,
tcx: TyCtxt<'a, 'tcx, 'tcx>,
link_meta: &LinkMeta,
reachable: &NodeSet) -> Vec<u8>
{
encoder::encode_metadata(tcx, self, reexports, link_meta, reachable)
encoder::encode_metadata(tcx, self, link_meta, reachable)
}
fn metadata_encoding_version(&self) -> &[u8]

View File

@ -13,7 +13,6 @@ use index::Index;
use schema::*;
use rustc::middle::cstore::{LinkMeta, LinkagePreference, NativeLibrary};
use rustc::hir::def;
use rustc::hir::def_id::{CrateNum, CRATE_DEF_INDEX, DefIndex, DefId};
use rustc::hir::map::definitions::DefPathTable;
use rustc::middle::dependency_format::Linkage;
@ -48,7 +47,6 @@ use super::index_builder::{FromId, IndexBuilder, Untracked};
pub struct EncodeContext<'a, 'tcx: 'a> {
opaque: opaque::Encoder<'a>,
pub tcx: TyCtxt<'a, 'tcx, 'tcx>,
reexports: &'a def::ExportMap,
link_meta: &'a LinkMeta,
cstore: &'a cstore::CStore,
exported_symbols: &'a NodeSet,
@ -306,7 +304,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
let def_id = tcx.hir.local_def_id(id);
let data = ModData {
reexports: match self.reexports.get(&id) {
reexports: match tcx.export_map.get(&id) {
Some(exports) if *vis == hir::Public => self.lazy_seq_ref(exports),
_ => LazySeq::empty(),
},
@ -1423,7 +1421,6 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
pub fn encode_metadata<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
cstore: &cstore::CStore,
reexports: &def::ExportMap,
link_meta: &LinkMeta,
exported_symbols: &NodeSet)
-> Vec<u8> {
@ -1437,7 +1434,6 @@ pub fn encode_metadata<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
let mut ecx = EncodeContext {
opaque: opaque::Encoder::new(&mut cursor),
tcx: tcx,
reexports: reexports,
link_meta: link_meta,
cstore: cstore,
exported_symbols: exported_symbols,

View File

@ -27,7 +27,7 @@ extern crate syntax_pos;
use rustc::dep_graph::DepNode;
use rustc::hir::{self, PatKind};
use rustc::hir::def::{self, Def};
use rustc::hir::def::Def;
use rustc::hir::def_id::{CRATE_DEF_INDEX, DefId};
use rustc::hir::intravisit::{self, Visitor, NestedVisitorMap};
use rustc::hir::itemlikevisit::DeepVisitor;
@ -71,7 +71,6 @@ impl<'a, 'tcx> Visitor<'tcx> for PubRestrictedVisitor<'a, 'tcx> {
struct EmbargoVisitor<'a, 'tcx: 'a> {
tcx: TyCtxt<'a, 'tcx, 'tcx>,
export_map: &'a def::ExportMap,
// Accessibility levels for reachable nodes
access_levels: AccessLevels,
@ -324,7 +323,7 @@ impl<'a, 'tcx> Visitor<'tcx> for EmbargoVisitor<'a, 'tcx> {
// This code is here instead of in visit_item so that the
// crate module gets processed as well.
if self.prev_level.is_some() {
if let Some(exports) = self.export_map.get(&id) {
if let Some(exports) = self.tcx.export_map.get(&id) {
for export in exports {
if let Some(node_id) = self.tcx.hir.as_local_node_id(export.def.def_id()) {
self.update(node_id, Some(AccessLevel::Exported));
@ -1204,9 +1203,7 @@ impl<'a, 'tcx> Visitor<'tcx> for PrivateItemsInPublicInterfacesVisitor<'a, 'tcx>
fn visit_pat(&mut self, _: &'tcx hir::Pat) {}
}
pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
export_map: &def::ExportMap)
-> AccessLevels {
pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) -> AccessLevels {
let _task = tcx.dep_graph.in_task(DepNode::Privacy);
let krate = tcx.hir.krate();
@ -1226,7 +1223,6 @@ pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
// items which are reachable from external crates based on visibility.
let mut visitor = EmbargoVisitor {
tcx: tcx,
export_map: export_map,
access_levels: Default::default(),
prev_level: Some(AccessLevel::Public),
changed: false,

View File

@ -755,7 +755,6 @@ fn write_metadata(cx: &SharedCrateContext,
let cstore = &cx.tcx().sess.cstore;
let metadata = cstore.encode_metadata(cx.tcx(),
cx.export_map(),
cx.link_meta(),
exported_symbols);
if kind == MetadataKind::Uncompressed {
@ -1056,7 +1055,7 @@ pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
// particular items that will be processed.
let krate = tcx.hir.krate();
let ty::CrateAnalysis { export_map, reachable, name, .. } = analysis;
let ty::CrateAnalysis { reachable, name, .. } = analysis;
let exported_symbols = find_exported_symbols(tcx, reachable);
let check_overflow = tcx.sess.overflow_checks();
@ -1064,7 +1063,6 @@ pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
let link_meta = link::build_link_meta(incremental_hashes_map, &name);
let shared_ccx = SharedCrateContext::new(tcx,
export_map,
link_meta.clone(),
exported_symbols,
check_overflow);

View File

@ -14,7 +14,6 @@ use rustc::dep_graph::{DepGraph, DepGraphSafe, DepNode, DepTrackingMap,
DepTrackingMapConfig, WorkProduct};
use middle::cstore::LinkMeta;
use rustc::hir;
use rustc::hir::def::ExportMap;
use rustc::hir::def_id::DefId;
use rustc::traits;
use debuginfo;
@ -68,7 +67,6 @@ pub struct SharedCrateContext<'a, 'tcx: 'a> {
metadata_llmod: ModuleRef,
metadata_llcx: ContextRef,
export_map: ExportMap,
exported_symbols: NodeSet,
link_meta: LinkMeta,
tcx: TyCtxt<'a, 'tcx, 'tcx>,
@ -402,7 +400,6 @@ unsafe fn create_context_and_module(sess: &Session, mod_name: &str) -> (ContextR
impl<'b, 'tcx> SharedCrateContext<'b, 'tcx> {
pub fn new(tcx: TyCtxt<'b, 'tcx, 'tcx>,
export_map: ExportMap,
link_meta: LinkMeta,
exported_symbols: NodeSet,
check_overflow: bool)
@ -459,7 +456,6 @@ impl<'b, 'tcx> SharedCrateContext<'b, 'tcx> {
SharedCrateContext {
metadata_llmod: metadata_llmod,
metadata_llcx: metadata_llcx,
export_map: export_map,
exported_symbols: exported_symbols,
link_meta: link_meta,
empty_param_env: tcx.empty_parameter_environment(),
@ -499,10 +495,6 @@ impl<'b, 'tcx> SharedCrateContext<'b, 'tcx> {
self.metadata_llcx
}
pub fn export_map<'a>(&'a self) -> &'a ExportMap {
&self.export_map
}
pub fn exported_symbols<'a>(&'a self) -> &'a NodeSet {
&self.exported_symbols
}
@ -702,10 +694,6 @@ impl<'b, 'tcx> CrateContext<'b, 'tcx> {
unsafe { llvm::LLVMRustGetModuleDataLayout(self.llmod()) }
}
pub fn export_map<'a>(&'a self) -> &'a ExportMap {
&self.shared.export_map
}
pub fn exported_symbols<'a>(&'a self) -> &'a NodeSet {
&self.shared.exported_symbols
}

View File

@ -13,7 +13,7 @@ use rustc_driver::{driver, target_features, abort_on_err};
use rustc::dep_graph::DepGraph;
use rustc::session::{self, config};
use rustc::hir::def_id::DefId;
use rustc::hir::def::{Def, ExportMap};
use rustc::hir::def::Def;
use rustc::middle::privacy::AccessLevels;
use rustc::ty::{self, TyCtxt, GlobalArenas};
use rustc::hir::map as hir_map;
@ -64,7 +64,6 @@ pub struct DocContext<'a, 'tcx: 'a> {
pub ty_substs: RefCell<FxHashMap<Def, clean::Type>>,
/// Table node id of lifetime parameter definition -> substituted lifetime
pub lt_substs: RefCell<FxHashMap<ast::NodeId, clean::Lifetime>>,
pub export_map: ExportMap,
}
impl<'a, 'tcx> DocContext<'a, 'tcx> {
@ -180,7 +179,7 @@ pub fn run_core(search_paths: SearchPaths,
sess.fatal("Compilation failed, aborting rustdoc");
}
let ty::CrateAnalysis { access_levels, export_map, .. } = analysis;
let ty::CrateAnalysis { access_levels, .. } = analysis;
// Convert from a NodeId set to a DefId set since we don't always have easy access
// to the map from defid -> nodeid
@ -198,7 +197,6 @@ pub fn run_core(search_paths: SearchPaths,
renderinfo: Default::default(),
ty_substs: Default::default(),
lt_substs: Default::default(),
export_map: export_map,
};
debug!("crate: {:?}", tcx.hir.krate());

View File

@ -198,7 +198,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
self.visit_item(item, None, &mut om);
}
self.inside_public_path = orig_inside_public_path;
if let Some(exports) = self.cx.export_map.get(&id) {
if let Some(exports) = self.cx.tcx.export_map.get(&id) {
for export in exports {
if let Def::Macro(def_id, ..) = export.def {
if def_id.krate == LOCAL_CRATE {