diff --git a/src/librustc/ty/context.rs b/src/librustc/ty/context.rs index ae6605c30e78c..f471408fe75f3 100644 --- a/src/librustc/ty/context.rs +++ b/src/librustc/ty/context.rs @@ -21,7 +21,8 @@ use hir::map as hir_map; use hir::map::DefPathHash; use lint::{self, Lint}; use ich::{self, StableHashingContext, NodeIdHashingMode}; -use middle::cstore::CrateStore; +use middle::cstore::{CrateStore, LinkMeta, EncodedMetadataHashes}; +use middle::cstore::EncodedMetadata; use middle::free_region::FreeRegionMap; use middle::lang_items; use middle::resolve_lifetime::{self, ObjectLifetimeDefault}; @@ -51,6 +52,7 @@ use rustc_data_structures::stable_hasher::{HashStable, StableHasher, use arena::{TypedArena, DroplessArena}; use rustc_data_structures::indexed_vec::IndexVec; +use std::any::Any; use std::borrow::Borrow; use std::cell::{Cell, RefCell}; use std::cmp::Ordering; @@ -907,10 +909,6 @@ impl<'tcx> GlobalCtxt<'tcx> { } impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { - pub fn cstore_untracked(&self) -> &CrateStore { - &*self.cstore - } - pub fn alloc_generics(self, generics: ty::Generics) -> &'gcx ty::Generics { self.global_arenas.generics.alloc(generics) } @@ -1134,6 +1132,54 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { pub fn crates(self) -> Rc> { self.all_crate_nums(LOCAL_CRATE) } + + pub fn def_key(self, id: DefId) -> hir_map::DefKey { + if id.is_local() { + self.hir.def_key(id) + } else { + self.cstore.def_key(id) + } + } + + /// Convert a `DefId` into its fully expanded `DefPath` (every + /// `DefId` is really just an interned def-path). + /// + /// Note that if `id` is not local to this crate, the result will + /// be a non-local `DefPath`. + pub fn def_path(self, id: DefId) -> hir_map::DefPath { + if id.is_local() { + self.hir.def_path(id) + } else { + self.cstore.def_path(id) + } + } + + #[inline] + pub fn def_path_hash(self, def_id: DefId) -> hir_map::DefPathHash { + if def_id.is_local() { + self.hir.definitions().def_path_hash(def_id.index) + } else { + self.cstore.def_path_hash(def_id) + } + } + + pub fn metadata_encoding_version(self) -> Vec { + self.cstore.metadata_encoding_version().to_vec() + } + + // Note that this is *untracked* and should only be used within the query + // system if the result is otherwise tracked through queries + pub fn crate_data_as_rc_any(self, cnum: CrateNum) -> Rc { + self.cstore.crate_data_as_rc_any(cnum) + } +} + +impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> { + pub fn encode_metadata(self, link_meta: &LinkMeta, reachable: &NodeSet) + -> (EncodedMetadata, EncodedMetadataHashes) + { + self.cstore.encode_metadata(self, link_meta, reachable) + } } impl<'gcx: 'tcx, 'tcx> GlobalCtxt<'gcx> { @@ -2069,4 +2115,16 @@ pub fn provide(providers: &mut ty::maps::Providers) { let id = tcx.hir.definitions().def_index_to_hir_id(id.index); tcx.stability().local_deprecation_entry(id) }; + providers.extern_mod_stmt_cnum = |tcx, id| { + let id = tcx.hir.definitions().find_node_for_hir_id(id); + tcx.cstore.extern_mod_stmt_cnum_untracked(id) + }; + providers.all_crate_nums = |tcx, cnum| { + assert_eq!(cnum, LOCAL_CRATE); + Rc::new(tcx.cstore.crates_untracked()) + }; + providers.postorder_cnums = |tcx, cnum| { + assert_eq!(cnum, LOCAL_CRATE); + Rc::new(tcx.cstore.postorder_cnums_untracked()) + }; } diff --git a/src/librustc/ty/item_path.rs b/src/librustc/ty/item_path.rs index f6d87b0e1dce5..cab5125494862 100644 --- a/src/librustc/ty/item_path.rs +++ b/src/librustc/ty/item_path.rs @@ -151,7 +151,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { } } - cur_path.push(self.cstore_untracked().def_key(cur_def) + cur_path.push(self.def_key(cur_def) .disambiguated_data.data.get_opt_name().unwrap_or_else(|| Symbol::intern("").as_str())); match visible_parent_map.get(&cur_def) { diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs index db7bed87d6a04..761143a50a2c5 100644 --- a/src/librustc/ty/mod.rs +++ b/src/librustc/ty/mod.rs @@ -2180,43 +2180,13 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { } } - pub fn def_key(self, id: DefId) -> hir_map::DefKey { - if id.is_local() { - self.hir.def_key(id) - } else { - self.cstore_untracked().def_key(id) - } - } - - /// Convert a `DefId` into its fully expanded `DefPath` (every - /// `DefId` is really just an interned def-path). - /// - /// Note that if `id` is not local to this crate, the result will - /// be a non-local `DefPath`. - pub fn def_path(self, id: DefId) -> hir_map::DefPath { - if id.is_local() { - self.hir.def_path(id) - } else { - self.cstore_untracked().def_path(id) - } - } - - #[inline] - pub fn def_path_hash(self, def_id: DefId) -> hir_map::DefPathHash { - if def_id.is_local() { - self.hir.definitions().def_path_hash(def_id.index) - } else { - self.cstore_untracked().def_path_hash(def_id) - } - } - pub fn item_name(self, id: DefId) -> InternedString { if let Some(id) = self.hir.as_local_node_id(id) { self.hir.name(id).as_str() } else if id.index == CRATE_DEF_INDEX { self.original_crate_name(id.krate).as_str() } else { - let def_key = self.cstore_untracked().def_key(id); + let def_key = self.def_key(id); // The name of a StructCtor is that of its struct parent. if let hir_map::DefPathData::StructCtor = def_key.disambiguated_data.data { self.item_name(DefId { diff --git a/src/librustc_driver/driver.rs b/src/librustc_driver/driver.rs index 5a35de7b6aa2b..c41d5beec6877 100644 --- a/src/librustc_driver/driver.rs +++ b/src/librustc_driver/driver.rs @@ -274,7 +274,7 @@ pub fn compile_input(sess: &Session, phase5_result); phase5_result?; - phase_6_link_output(sess, cstore, &trans, &outputs); + phase_6_link_output(sess, &trans, &outputs); // Now that we won't touch anything in the incremental compilation directory // any more, we can finalize it (which involves renaming it) @@ -1153,12 +1153,10 @@ pub fn phase_5_run_llvm_passes(sess: &Session, /// This should produce either a finished executable or library. #[cfg(feature="llvm")] pub fn phase_6_link_output(sess: &Session, - cstore: &CrateStore, trans: &trans::CrateTranslation, outputs: &OutputFilenames) { time(sess.time_passes(), "linking", || { ::rustc_trans::back::link::link_binary(sess, - cstore, trans, outputs, &trans.crate_name.as_str()) diff --git a/src/librustc_metadata/cstore_impl.rs b/src/librustc_metadata/cstore_impl.rs index 7579a58ed23fd..74e4ffcdfffdc 100644 --- a/src/librustc_metadata/cstore_impl.rs +++ b/src/librustc_metadata/cstore_impl.rs @@ -60,7 +60,7 @@ macro_rules! provide { $tcx.dep_graph.read(dep_node); - let $cdata = $tcx.cstore_untracked().crate_data_as_rc_any($def_id.krate); + let $cdata = $tcx.crate_data_as_rc_any($def_id.krate); let $cdata = $cdata.downcast_ref::() .expect("CrateStore crated ata is not a CrateMetadata"); $compute @@ -275,15 +275,6 @@ pub fn provide_local<'tcx>(providers: &mut Providers<'tcx>) { assert_eq!(cnum, LOCAL_CRATE); Rc::new(link_args::collect(tcx)) }, - extern_mod_stmt_cnum: |tcx, id| { - let id = tcx.hir.definitions().find_node_for_hir_id(id); - tcx.cstore_untracked().extern_mod_stmt_cnum_untracked(id) - }, - - all_crate_nums: |tcx, cnum| { - assert_eq!(cnum, LOCAL_CRATE); - Rc::new(tcx.cstore_untracked().crates_untracked()) - }, // Returns a map from a sufficiently visible external item (i.e. an // external item that is visible from at least one local module) to a @@ -342,11 +333,6 @@ pub fn provide_local<'tcx>(providers: &mut Providers<'tcx>) { Rc::new(visible_parent_map) }, - postorder_cnums: |tcx, cnum| { - assert_eq!(cnum, LOCAL_CRATE); - Rc::new(tcx.cstore_untracked().postorder_cnums_untracked()) - }, - ..*providers }; } diff --git a/src/librustc_trans/base.rs b/src/librustc_trans/base.rs index c3a4745bc3dcb..4c611cccf581f 100644 --- a/src/librustc_trans/base.rs +++ b/src/librustc_trans/base.rs @@ -775,16 +775,13 @@ fn write_metadata<'a, 'gcx>(tcx: TyCtxt<'a, 'gcx, 'gcx>, EncodedMetadataHashes::new()); } - let cstore = tcx.cstore_untracked(); - let (metadata, hashes) = cstore.encode_metadata(tcx, - &link_meta, - exported_symbols); + let (metadata, hashes) = tcx.encode_metadata(link_meta, exported_symbols); if kind == MetadataKind::Uncompressed { return (metadata_llcx, metadata_llmod, metadata, hashes); } assert!(kind == MetadataKind::Compressed); - let mut compressed = cstore.metadata_encoding_version().to_vec(); + let mut compressed = tcx.metadata_encoding_version(); DeflateEncoder::new(&mut compressed, Compression::Fast) .write_all(&metadata.raw_data).unwrap(); diff --git a/src/librustdoc/build.rs b/src/librustdoc/build.rs index 130c6fd01a8d8..386550f511a52 100644 --- a/src/librustdoc/build.rs +++ b/src/librustdoc/build.rs @@ -25,6 +25,7 @@ fn main() { .file("../rt/hoedown/src/stack.c") .file("../rt/hoedown/src/version.c") .include(src_dir) + .warnings(false) .compile("libhoedown.a"); } diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index 81396d41606a8..d7ce5e262ce38 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -215,7 +215,7 @@ pub fn run_core(search_paths: SearchPaths, debug!("crate: {:?}", tcx.hir.krate()); let krate = { - let mut v = RustdocVisitor::new(&ctxt); + let mut v = RustdocVisitor::new(&*cstore, &ctxt); v.visit(tcx.hir.krate()); v.clean(&ctxt) }; diff --git a/src/librustdoc/visit_ast.rs b/src/librustdoc/visit_ast.rs index d354d726ff703..4fed218ba0871 100644 --- a/src/librustdoc/visit_ast.rs +++ b/src/librustdoc/visit_ast.rs @@ -21,7 +21,7 @@ use syntax_pos::Span; use rustc::hir::map as hir_map; use rustc::hir::def::Def; use rustc::hir::def_id::{DefId, LOCAL_CRATE}; -use rustc::middle::cstore::LoadedMacro; +use rustc::middle::cstore::{LoadedMacro, CrateStore}; use rustc::middle::privacy::AccessLevel; use rustc::util::nodemap::FxHashSet; @@ -40,6 +40,7 @@ use doctree::*; // framework from syntax? pub struct RustdocVisitor<'a, 'tcx: 'a> { + cstore: &'tcx CrateStore, pub module: Module, pub attrs: hir::HirVec, pub cx: &'a core::DocContext<'a, 'tcx>, @@ -51,7 +52,8 @@ pub struct RustdocVisitor<'a, 'tcx: 'a> { } impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> { - pub fn new(cx: &'a core::DocContext<'a, 'tcx>) -> RustdocVisitor<'a, 'tcx> { + pub fn new(cstore: &'tcx CrateStore, + cx: &'a core::DocContext<'a, 'tcx>) -> RustdocVisitor<'a, 'tcx> { // If the root is reexported, terminate all recursion. let mut stack = FxHashSet(); stack.insert(ast::CRATE_NODE_ID); @@ -63,6 +65,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> { inlining: false, inside_public_path: true, reexported_macros: FxHashSet(), + cstore, } } @@ -208,8 +211,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> { } let imported_from = self.cx.tcx.original_crate_name(def_id.krate); - let cstore = &self.cx.sess().cstore; - let def = match cstore.load_macro_untracked(def_id, self.cx.sess()) { + let def = match self.cstore.load_macro_untracked(def_id, self.cx.sess()) { LoadedMacro::MacroDef(macro_def) => macro_def, // FIXME(jseyfried): document proc macro reexports LoadedMacro::ProcMacro(..) => continue,