]> git.lizzy.rs Git - rust.git/commitdiff
rustc: Make `CrateStore` private to `TyCtxt`
authorAlex Crichton <alex@alexcrichton.com>
Thu, 7 Sep 2017 20:21:46 +0000 (13:21 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Wed, 13 Sep 2017 04:14:06 +0000 (21:14 -0700)
This commit removes the `cstore_untracked` method, making the `CrateStore` trait
object entirely private to the `ty/context.rs` module.

src/Cargo.lock
src/librustc/ty/context.rs
src/librustc/ty/item_path.rs
src/librustc/ty/mod.rs
src/librustc_driver/driver.rs
src/librustc_metadata/cstore_impl.rs
src/librustc_trans/base.rs
src/librustdoc/build.rs
src/librustdoc/core.rs
src/librustdoc/visit_ast.rs
src/tools/rls

index 47ef0a7d8ca13a98f4aef9a61a1463d78d0546d5..1bbe8ca7575f11b6b9110ec415b1dd504296cfda 100644 (file)
@@ -1336,7 +1336,7 @@ dependencies = [
  "racer 2.0.10 (registry+https://github.com/rust-lang/crates.io-index)",
  "rls-analysis 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)",
  "rls-data 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)",
- "rls-rustc 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "rls-rustc 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
  "rls-span 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "rls-vfs 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)",
  "rustfmt-nightly 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -1371,7 +1371,7 @@ dependencies = [
 
 [[package]]
 name = "rls-rustc"
-version = "0.1.0"
+version = "0.1.1"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 
 [[package]]
@@ -2544,7 +2544,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
 "checksum regex-syntax 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ad890a5eef7953f55427c50575c680c42841653abd2b028b68cd223d157f62db"
 "checksum rls-analysis 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)" = "d2cb40c0371765897ae428b5706bb17135705ad4f6d1b8b6afbaabcf8c9b5cff"
 "checksum rls-data 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "11d339f1888e33e74d8032de0f83c40b2bdaaaf04a8cfc03b32186c3481fb534"
-"checksum rls-rustc 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5fa757c9d547d460427ceff01875f9cac5f5acd8fc6543946e9b0335ba29d537"
+"checksum rls-rustc 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b21ea952e9bf1569929abf1bb920262cde04b7b1b26d8e0260286302807299d2"
 "checksum rls-span 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5d7c7046dc6a92f2ae02ed302746db4382e75131b9ce20ce967259f6b5867a6a"
 "checksum rls-vfs 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "ffd34691a510938bb67fe0444fb363103c73ffb31c121d1e16bc92d8945ea8ff"
 "checksum rustc-demangle 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "aee45432acc62f7b9a108cc054142dac51f979e69e71ddce7d6fc7adf29e817e"
index 88fcbc1707ed92897f726a5eecfb0630b79282e3..fb0cdab0b6a0fa6f3e47e4200412418ce638af8d 100644 (file)
 use hir::map::DefPathHash;
 use lint::{self, Lint};
 use ich::{self, StableHashingContext, NodeIdHashingMode};
-<<<<<<< 817e1b81e230d599585f860cdcad96c5ed83b93e
 use middle::const_val::ConstVal;
-=======
-use middle::cstore::CrateStore;
->>>>>>> Remove the `cstore` reference from Session in order to prepare encapsulating CrateStore access in tcx.
+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};
@@ -56,6 +54,7 @@
 use arena::{TypedArena, DroplessArena};
 use rustc_const_math::{ConstInt, ConstUsize};
 use rustc_data_structures::indexed_vec::IndexVec;
+use std::any::Any;
 use std::borrow::Borrow;
 use std::cell::{Cell, RefCell};
 use std::cmp::Ordering;
@@ -915,10 +914,6 @@ pub fn global_tcx<'a>(&'a self) -> TyCtxt<'a, 'tcx, '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)
     }
@@ -1183,6 +1178,54 @@ pub fn stability(self) -> Rc<stability::Index<'tcx>> {
     pub fn crates(self) -> Rc<Vec<CrateNum>> {
         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<u8> {
+        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<Any> {
+        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> {
@@ -2163,4 +2206,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.as_local_node_id(id).unwrap();
+        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())
+    };
 }
index 64b231b11fc852a263243a6772529684cd5a55a3..a8ccb3e269ffcc00ef8bf2f493add0bb188b0b13 100644 (file)
@@ -151,7 +151,7 @@ pub fn try_push_visible_item_path<T>(self, buffer: &mut T, external_def_id: DefI
                 }
             }
 
-            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("<unnamed>").as_str()));
             match visible_parent_map.get(&cur_def) {
index 59c42c701295478a619afd083ddc33a9591dce4a..2d5b0ce0954fcba6fd4892cc0f1ff51ace3d4a26 100644 (file)
@@ -2170,43 +2170,13 @@ pub fn expect_variant_def(self, def: Def) -> &'tcx VariantDef {
         }
     }
 
-    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 {
index 5a35de7b6aa2b6009fcaebe50189661cabed491e..c41d5beec6877ab61570ae2f6fcfa17601e1b080 100644 (file)
@@ -274,7 +274,7 @@ macro_rules! controller_entry_point {
                                 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())
index 3a47ee1a36b8f5819d4617f639d04abbacf9afca..74e4ffcdfffdc2a1adf023b014e7b9b1adc84edc 100644 (file)
@@ -60,7 +60,7 @@ pub fn provide<$lt>(providers: &mut Providers<$lt>) {
 
                 $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::<cstore::CrateMetadata>()
                     .expect("CrateStore crated ata is not a CrateMetadata");
                 $compute
@@ -275,15 +275,6 @@ fn is_const_fn<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> bool {
             assert_eq!(cnum, LOCAL_CRATE);
             Rc::new(link_args::collect(tcx))
         },
-        extern_mod_stmt_cnum: |tcx, id| {
-            let id = tcx.hir.as_local_node_id(id).unwrap();
-            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 @@ fn is_const_fn<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> bool {
             Rc::new(visible_parent_map)
         },
 
-        postorder_cnums: |tcx, cnum| {
-            assert_eq!(cnum, LOCAL_CRATE);
-            Rc::new(tcx.cstore_untracked().postorder_cnums_untracked())
-        },
-
         ..*providers
     };
 }
index ade05003ef84c9495c18a01aa6d1830cd1a227f5..026417682cc74221809d7c1bda153a60ae346c10 100644 (file)
@@ -777,16 +777,13 @@ enum MetadataKind {
                 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();
 
index 507393bed8a1ab9c8fbfcd391c97284930ec324e..830492dec9482f0c7857529d5583f727231116a0 100644 (file)
@@ -26,6 +26,7 @@ fn main() {
        .file("../rt/hoedown/src/version.c")
        .warnings(false)
        .include(src_dir)
+       .warnings(false)
        .compile("libhoedown.a");
 }
 
index 81396d41606a8e11450b7461d504e57cbdbe5191..d7ce5e262ce381b07cd0f412da0dff4b4ad80704 100644 (file)
@@ -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)
         };
index b74bac7a85b0b058db6649ff0089712822dff069..327a330c2a2e5dba7a181a28a556a459f94828aa 100644 (file)
@@ -21,7 +21,7 @@
 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 @@
 // framework from syntax?
 
 pub struct RustdocVisitor<'a, 'tcx: 'a> {
+    cstore: &'tcx CrateStore,
     pub module: Module,
     pub attrs: hir::HirVec<ast::Attribute>,
     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 @@ pub fn new(cx: &'a core::DocContext<'a, 'tcx>) -> RustdocVisitor<'a, 'tcx> {
             inlining: false,
             inside_public_path: true,
             reexported_macros: FxHashSet(),
+            cstore,
         }
     }
 
@@ -208,8 +211,7 @@ pub fn visit_mod_contents(&mut self, span: Span, attrs: hir::HirVec<ast::Attribu
                     }
 
                     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,
index 303671ea8103cbc39575a1f47a204159546a04d0..8dd70945fb049df3f9dc7685cdc58d94e05e8ffc 160000 (submodule)
@@ -1 +1 @@
-Subproject commit 303671ea8103cbc39575a1f47a204159546a04d0
+Subproject commit 8dd70945fb049df3f9dc7685cdc58d94e05e8ffc