Skip to content

Commit 921750b

Browse files
committed
rustc: Make CrateStore private to TyCtxt
This commit removes the `cstore_untracked` method, making the `CrateStore` trait object entirely private to the `ty/context.rs` module.
1 parent 54fa047 commit 921750b

File tree

11 files changed

+81
-72
lines changed

11 files changed

+81
-72
lines changed

src/Cargo.lock

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/librustc/ty/context.rs

+63-8
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,9 @@ use hir::map as hir_map;
2121
use hir::map::DefPathHash;
2222
use lint::{self, Lint};
2323
use ich::{self, StableHashingContext, NodeIdHashingMode};
24-
<<<<<<< 817e1b81e230d599585f860cdcad96c5ed83b93e
2524
use middle::const_val::ConstVal;
26-
=======
27-
use middle::cstore::CrateStore;
28-
>>>>>>> Remove the `cstore` reference from Session in order to prepare encapsulating CrateStore access in tcx.
25+
use middle::cstore::{CrateStore, LinkMeta, EncodedMetadataHashes};
26+
use middle::cstore::EncodedMetadata;
2927
use middle::free_region::FreeRegionMap;
3028
use middle::lang_items;
3129
use middle::resolve_lifetime::{self, ObjectLifetimeDefault};
@@ -56,6 +54,7 @@ use rustc_data_structures::stable_hasher::{HashStable, StableHasher,
5654
use arena::{TypedArena, DroplessArena};
5755
use rustc_const_math::{ConstInt, ConstUsize};
5856
use rustc_data_structures::indexed_vec::IndexVec;
57+
use std::any::Any;
5958
use std::borrow::Borrow;
6059
use std::cell::{Cell, RefCell};
6160
use std::cmp::Ordering;
@@ -915,10 +914,6 @@ impl<'tcx> GlobalCtxt<'tcx> {
915914
}
916915

917916
impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
918-
pub fn cstore_untracked(&self) -> &CrateStore {
919-
&*self.cstore
920-
}
921-
922917
pub fn alloc_generics(self, generics: ty::Generics) -> &'gcx ty::Generics {
923918
self.global_arenas.generics.alloc(generics)
924919
}
@@ -1183,6 +1178,54 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
11831178
pub fn crates(self) -> Rc<Vec<CrateNum>> {
11841179
self.all_crate_nums(LOCAL_CRATE)
11851180
}
1181+
1182+
pub fn def_key(self, id: DefId) -> hir_map::DefKey {
1183+
if id.is_local() {
1184+
self.hir.def_key(id)
1185+
} else {
1186+
self.cstore.def_key(id)
1187+
}
1188+
}
1189+
1190+
/// Convert a `DefId` into its fully expanded `DefPath` (every
1191+
/// `DefId` is really just an interned def-path).
1192+
///
1193+
/// Note that if `id` is not local to this crate, the result will
1194+
/// be a non-local `DefPath`.
1195+
pub fn def_path(self, id: DefId) -> hir_map::DefPath {
1196+
if id.is_local() {
1197+
self.hir.def_path(id)
1198+
} else {
1199+
self.cstore.def_path(id)
1200+
}
1201+
}
1202+
1203+
#[inline]
1204+
pub fn def_path_hash(self, def_id: DefId) -> hir_map::DefPathHash {
1205+
if def_id.is_local() {
1206+
self.hir.definitions().def_path_hash(def_id.index)
1207+
} else {
1208+
self.cstore.def_path_hash(def_id)
1209+
}
1210+
}
1211+
1212+
pub fn metadata_encoding_version(self) -> Vec<u8> {
1213+
self.cstore.metadata_encoding_version().to_vec()
1214+
}
1215+
1216+
// Note that this is *untracked* and should only be used within the query
1217+
// system if the result is otherwise tracked through queries
1218+
pub fn crate_data_as_rc_any(self, cnum: CrateNum) -> Rc<Any> {
1219+
self.cstore.crate_data_as_rc_any(cnum)
1220+
}
1221+
}
1222+
1223+
impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
1224+
pub fn encode_metadata(self, link_meta: &LinkMeta, reachable: &NodeSet)
1225+
-> (EncodedMetadata, EncodedMetadataHashes)
1226+
{
1227+
self.cstore.encode_metadata(self, link_meta, reachable)
1228+
}
11861229
}
11871230

11881231
impl<'gcx: 'tcx, 'tcx> GlobalCtxt<'gcx> {
@@ -2163,4 +2206,16 @@ pub fn provide(providers: &mut ty::maps::Providers) {
21632206
let id = tcx.hir.definitions().def_index_to_hir_id(id.index);
21642207
tcx.stability().local_deprecation_entry(id)
21652208
};
2209+
providers.extern_mod_stmt_cnum = |tcx, id| {
2210+
let id = tcx.hir.as_local_node_id(id).unwrap();
2211+
tcx.cstore.extern_mod_stmt_cnum_untracked(id)
2212+
};
2213+
providers.all_crate_nums = |tcx, cnum| {
2214+
assert_eq!(cnum, LOCAL_CRATE);
2215+
Rc::new(tcx.cstore.crates_untracked())
2216+
};
2217+
providers.postorder_cnums = |tcx, cnum| {
2218+
assert_eq!(cnum, LOCAL_CRATE);
2219+
Rc::new(tcx.cstore.postorder_cnums_untracked())
2220+
};
21662221
}

src/librustc/ty/item_path.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
151151
}
152152
}
153153

154-
cur_path.push(self.cstore_untracked().def_key(cur_def)
154+
cur_path.push(self.def_key(cur_def)
155155
.disambiguated_data.data.get_opt_name().unwrap_or_else(||
156156
Symbol::intern("<unnamed>").as_str()));
157157
match visible_parent_map.get(&cur_def) {

src/librustc/ty/mod.rs

+1-31
Original file line numberDiff line numberDiff line change
@@ -2170,43 +2170,13 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
21702170
}
21712171
}
21722172

2173-
pub fn def_key(self, id: DefId) -> hir_map::DefKey {
2174-
if id.is_local() {
2175-
self.hir.def_key(id)
2176-
} else {
2177-
self.cstore_untracked().def_key(id)
2178-
}
2179-
}
2180-
2181-
/// Convert a `DefId` into its fully expanded `DefPath` (every
2182-
/// `DefId` is really just an interned def-path).
2183-
///
2184-
/// Note that if `id` is not local to this crate, the result will
2185-
/// be a non-local `DefPath`.
2186-
pub fn def_path(self, id: DefId) -> hir_map::DefPath {
2187-
if id.is_local() {
2188-
self.hir.def_path(id)
2189-
} else {
2190-
self.cstore_untracked().def_path(id)
2191-
}
2192-
}
2193-
2194-
#[inline]
2195-
pub fn def_path_hash(self, def_id: DefId) -> hir_map::DefPathHash {
2196-
if def_id.is_local() {
2197-
self.hir.definitions().def_path_hash(def_id.index)
2198-
} else {
2199-
self.cstore_untracked().def_path_hash(def_id)
2200-
}
2201-
}
2202-
22032173
pub fn item_name(self, id: DefId) -> InternedString {
22042174
if let Some(id) = self.hir.as_local_node_id(id) {
22052175
self.hir.name(id).as_str()
22062176
} else if id.index == CRATE_DEF_INDEX {
22072177
self.original_crate_name(id.krate).as_str()
22082178
} else {
2209-
let def_key = self.cstore_untracked().def_key(id);
2179+
let def_key = self.def_key(id);
22102180
// The name of a StructCtor is that of its struct parent.
22112181
if let hir_map::DefPathData::StructCtor = def_key.disambiguated_data.data {
22122182
self.item_name(DefId {

src/librustc_driver/driver.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ pub fn compile_input(sess: &Session,
274274
phase5_result);
275275
phase5_result?;
276276

277-
phase_6_link_output(sess, cstore, &trans, &outputs);
277+
phase_6_link_output(sess, &trans, &outputs);
278278

279279
// Now that we won't touch anything in the incremental compilation directory
280280
// any more, we can finalize it (which involves renaming it)
@@ -1153,12 +1153,10 @@ pub fn phase_5_run_llvm_passes(sess: &Session,
11531153
/// This should produce either a finished executable or library.
11541154
#[cfg(feature="llvm")]
11551155
pub fn phase_6_link_output(sess: &Session,
1156-
cstore: &CrateStore,
11571156
trans: &trans::CrateTranslation,
11581157
outputs: &OutputFilenames) {
11591158
time(sess.time_passes(), "linking", || {
11601159
::rustc_trans::back::link::link_binary(sess,
1161-
cstore,
11621160
trans,
11631161
outputs,
11641162
&trans.crate_name.as_str())

src/librustc_metadata/cstore_impl.rs

+1-15
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ macro_rules! provide {
6060

6161
$tcx.dep_graph.read(dep_node);
6262

63-
let $cdata = $tcx.cstore_untracked().crate_data_as_rc_any($def_id.krate);
63+
let $cdata = $tcx.crate_data_as_rc_any($def_id.krate);
6464
let $cdata = $cdata.downcast_ref::<cstore::CrateMetadata>()
6565
.expect("CrateStore crated ata is not a CrateMetadata");
6666
$compute
@@ -275,15 +275,6 @@ pub fn provide_local<'tcx>(providers: &mut Providers<'tcx>) {
275275
assert_eq!(cnum, LOCAL_CRATE);
276276
Rc::new(link_args::collect(tcx))
277277
},
278-
extern_mod_stmt_cnum: |tcx, id| {
279-
let id = tcx.hir.as_local_node_id(id).unwrap();
280-
tcx.cstore_untracked().extern_mod_stmt_cnum_untracked(id)
281-
},
282-
283-
all_crate_nums: |tcx, cnum| {
284-
assert_eq!(cnum, LOCAL_CRATE);
285-
Rc::new(tcx.cstore_untracked().crates_untracked())
286-
},
287278

288279
// Returns a map from a sufficiently visible external item (i.e. an
289280
// 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>) {
342333
Rc::new(visible_parent_map)
343334
},
344335

345-
postorder_cnums: |tcx, cnum| {
346-
assert_eq!(cnum, LOCAL_CRATE);
347-
Rc::new(tcx.cstore_untracked().postorder_cnums_untracked())
348-
},
349-
350336
..*providers
351337
};
352338
}

src/librustc_trans/base.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -777,16 +777,13 @@ fn write_metadata<'a, 'gcx>(tcx: TyCtxt<'a, 'gcx, 'gcx>,
777777
EncodedMetadataHashes::new());
778778
}
779779

780-
let cstore = tcx.cstore_untracked();
781-
let (metadata, hashes) = cstore.encode_metadata(tcx,
782-
&link_meta,
783-
exported_symbols);
780+
let (metadata, hashes) = tcx.encode_metadata(link_meta, exported_symbols);
784781
if kind == MetadataKind::Uncompressed {
785782
return (metadata_llcx, metadata_llmod, metadata, hashes);
786783
}
787784

788785
assert!(kind == MetadataKind::Compressed);
789-
let mut compressed = cstore.metadata_encoding_version().to_vec();
786+
let mut compressed = tcx.metadata_encoding_version();
790787
DeflateEncoder::new(&mut compressed, Compression::Fast)
791788
.write_all(&metadata.raw_data).unwrap();
792789

src/librustdoc/build.rs

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ fn main() {
2626
.file("../rt/hoedown/src/version.c")
2727
.warnings(false)
2828
.include(src_dir)
29+
.warnings(false)
2930
.compile("libhoedown.a");
3031
}
3132

src/librustdoc/core.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ pub fn run_core(search_paths: SearchPaths,
215215
debug!("crate: {:?}", tcx.hir.krate());
216216

217217
let krate = {
218-
let mut v = RustdocVisitor::new(&ctxt);
218+
let mut v = RustdocVisitor::new(&*cstore, &ctxt);
219219
v.visit(tcx.hir.krate());
220220
v.clean(&ctxt)
221221
};

src/librustdoc/visit_ast.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use syntax_pos::Span;
2121
use rustc::hir::map as hir_map;
2222
use rustc::hir::def::Def;
2323
use rustc::hir::def_id::{DefId, LOCAL_CRATE};
24-
use rustc::middle::cstore::LoadedMacro;
24+
use rustc::middle::cstore::{LoadedMacro, CrateStore};
2525
use rustc::middle::privacy::AccessLevel;
2626
use rustc::util::nodemap::FxHashSet;
2727

@@ -40,6 +40,7 @@ use doctree::*;
4040
// framework from syntax?
4141

4242
pub struct RustdocVisitor<'a, 'tcx: 'a> {
43+
cstore: &'tcx CrateStore,
4344
pub module: Module,
4445
pub attrs: hir::HirVec<ast::Attribute>,
4546
pub cx: &'a core::DocContext<'a, 'tcx>,
@@ -51,7 +52,8 @@ pub struct RustdocVisitor<'a, 'tcx: 'a> {
5152
}
5253

5354
impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
54-
pub fn new(cx: &'a core::DocContext<'a, 'tcx>) -> RustdocVisitor<'a, 'tcx> {
55+
pub fn new(cstore: &'tcx CrateStore,
56+
cx: &'a core::DocContext<'a, 'tcx>) -> RustdocVisitor<'a, 'tcx> {
5557
// If the root is reexported, terminate all recursion.
5658
let mut stack = FxHashSet();
5759
stack.insert(ast::CRATE_NODE_ID);
@@ -63,6 +65,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
6365
inlining: false,
6466
inside_public_path: true,
6567
reexported_macros: FxHashSet(),
68+
cstore,
6669
}
6770
}
6871

@@ -208,8 +211,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
208211
}
209212

210213
let imported_from = self.cx.tcx.original_crate_name(def_id.krate);
211-
let cstore = &self.cx.sess().cstore;
212-
let def = match cstore.load_macro_untracked(def_id, self.cx.sess()) {
214+
let def = match self.cstore.load_macro_untracked(def_id, self.cx.sess()) {
213215
LoadedMacro::MacroDef(macro_def) => macro_def,
214216
// FIXME(jseyfried): document proc macro reexports
215217
LoadedMacro::ProcMacro(..) => continue,

src/tools/rls

Submodule rls updated from 303671e to 8dd7094

0 commit comments

Comments
 (0)