Skip to content

Commit c3eccc6

Browse files
committed
Auto merge of #44420 - alexcrichton:private-cstore, r=michaelwoerister
rustc: Make `CrateStore` private to `TyCtxt` This commit makes the `CrateStore` object private to the `ty/context.rs` module and also absent on the `Session` itself. cc #44390 cc #44341 (initial commit pulled and rebased from here)
2 parents 7eefed3 + 921750b commit c3eccc6

File tree

26 files changed

+194
-135
lines changed

26 files changed

+194
-135
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/hir/lowering.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ use hir::map::{Definitions, DefKey};
4545
use hir::def_id::{DefIndex, DefId, CRATE_DEF_INDEX};
4646
use hir::def::{Def, PathResolution};
4747
use lint::builtin::PARENTHESIZED_PARAMS_IN_TYPES_AND_MODULES;
48+
use middle::cstore::CrateStore;
4849
use rustc_data_structures::indexed_vec::IndexVec;
4950
use session::Session;
5051
use util::common::FN_OUTPUT_NAME;
@@ -74,6 +75,8 @@ pub struct LoweringContext<'a> {
7475
// Use to assign ids to hir nodes that do not directly correspond to an ast node
7576
sess: &'a Session,
7677

78+
cstore: &'a CrateStore,
79+
7780
// As we walk the AST we must keep track of the current 'parent' def id (in
7881
// the form of a DefIndex) so that if we create a new node which introduces
7982
// a definition, then we can properly create the def id.
@@ -118,6 +121,7 @@ pub trait Resolver {
118121
}
119122

120123
pub fn lower_crate(sess: &Session,
124+
cstore: &CrateStore,
121125
krate: &Crate,
122126
resolver: &mut Resolver)
123127
-> hir::Crate {
@@ -129,6 +133,7 @@ pub fn lower_crate(sess: &Session,
129133
LoweringContext {
130134
crate_root: std_inject::injected_crate_name(krate),
131135
sess,
136+
cstore,
132137
parent_def: None,
133138
resolver,
134139
name_map: FxHashMap(),
@@ -534,7 +539,7 @@ impl<'a> LoweringContext<'a> {
534539
if id.is_local() {
535540
self.resolver.definitions().def_key(id.index)
536541
} else {
537-
self.sess.cstore.def_key(id)
542+
self.cstore.def_key(id)
538543
}
539544
}
540545

@@ -786,7 +791,7 @@ impl<'a> LoweringContext<'a> {
786791
return n;
787792
}
788793
assert!(!def_id.is_local());
789-
let n = self.sess.cstore.item_generics_cloned_untracked(def_id).regions.len();
794+
let n = self.cstore.item_generics_cloned_untracked(def_id).regions.len();
790795
self.type_def_lifetime_params.insert(def_id, n);
791796
n
792797
});

src/librustc/middle/resolve_lifetime.rs

+9-4
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@
1616
//! way. Therefore we break lifetime name resolution into a separate pass.
1717
1818
use hir::map::Map;
19-
use session::Session;
2019
use hir::def::Def;
2120
use hir::def_id::DefId;
21+
use middle::cstore::CrateStore;
22+
use session::Session;
2223
use ty;
2324

2425
use std::cell::Cell;
@@ -160,6 +161,7 @@ pub struct NamedRegionMap {
160161

161162
struct LifetimeContext<'a, 'tcx: 'a> {
162163
sess: &'a Session,
164+
cstore: &'a CrateStore,
163165
hir_map: &'a Map<'tcx>,
164166
map: &'a mut NamedRegionMap,
165167
scope: ScopeRef<'a>,
@@ -251,6 +253,7 @@ type ScopeRef<'a> = &'a Scope<'a>;
251253
const ROOT_SCOPE: ScopeRef<'static> = &Scope::Root;
252254

253255
pub fn krate(sess: &Session,
256+
cstore: &CrateStore,
254257
hir_map: &Map)
255258
-> Result<NamedRegionMap, ErrorReported> {
256259
let krate = hir_map.krate();
@@ -262,6 +265,7 @@ pub fn krate(sess: &Session,
262265
sess.track_errors(|| {
263266
let mut visitor = LifetimeContext {
264267
sess,
268+
cstore,
265269
hir_map,
266270
map: &mut map,
267271
scope: ROOT_SCOPE,
@@ -765,12 +769,13 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
765769
fn with<F>(&mut self, wrap_scope: Scope, f: F) where
766770
F: for<'b> FnOnce(ScopeRef, &mut LifetimeContext<'b, 'tcx>),
767771
{
768-
let LifetimeContext {sess, hir_map, ref mut map, ..} = *self;
772+
let LifetimeContext {sess, cstore, hir_map, ref mut map, ..} = *self;
769773
let labels_in_fn = replace(&mut self.labels_in_fn, vec![]);
770774
let xcrate_object_lifetime_defaults =
771775
replace(&mut self.xcrate_object_lifetime_defaults, DefIdMap());
772776
let mut this = LifetimeContext {
773777
sess,
778+
cstore,
774779
hir_map,
775780
map: *map,
776781
scope: &wrap_scope,
@@ -932,7 +937,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
932937
let def_key = if def_id.is_local() {
933938
this.hir_map.def_key(def_id)
934939
} else {
935-
this.sess.cstore.def_key(def_id)
940+
this.cstore.def_key(def_id)
936941
};
937942
DefId {
938943
krate: def_id.krate,
@@ -976,7 +981,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
976981
let unsubst = if let Some(id) = self.hir_map.as_local_node_id(def_id) {
977982
&map.object_lifetime_defaults[&id]
978983
} else {
979-
let cstore = &self.sess.cstore;
984+
let cstore = self.cstore;
980985
self.xcrate_object_lifetime_defaults.entry(def_id).or_insert_with(|| {
981986
cstore.item_generics_cloned_untracked(def_id).types.into_iter().map(|def| {
982987
def.object_lifetime_default

src/librustc/session/config.rs

+6-11
Original file line numberDiff line numberDiff line change
@@ -1953,13 +1953,12 @@ mod tests {
19531953
use errors;
19541954
use getopts;
19551955
use lint;
1956-
use middle::cstore::{self, DummyCrateStore};
1956+
use middle::cstore;
19571957
use session::config::{build_configuration, build_session_options_and_crate_config};
19581958
use session::build_session;
19591959
use std::collections::{BTreeMap, BTreeSet};
19601960
use std::iter::FromIterator;
19611961
use std::path::PathBuf;
1962-
use std::rc::Rc;
19631962
use super::{OutputType, OutputTypes, Externs};
19641963
use rustc_back::{PanicStrategy, RelroLevel};
19651964
use syntax::symbol::Symbol;
@@ -1991,7 +1990,7 @@ mod tests {
19911990
};
19921991
let registry = errors::registry::Registry::new(&[]);
19931992
let (sessopts, cfg) = build_session_options_and_crate_config(matches);
1994-
let sess = build_session(sessopts, &dep_graph, None, registry, Rc::new(DummyCrateStore));
1993+
let sess = build_session(sessopts, &dep_graph, None, registry);
19951994
let cfg = build_configuration(&sess, cfg);
19961995
assert!(cfg.contains(&(Symbol::intern("test"), None)));
19971996
}
@@ -2010,8 +2009,7 @@ mod tests {
20102009
};
20112010
let registry = errors::registry::Registry::new(&[]);
20122011
let (sessopts, cfg) = build_session_options_and_crate_config(matches);
2013-
let sess = build_session(sessopts, &dep_graph, None, registry,
2014-
Rc::new(DummyCrateStore));
2012+
let sess = build_session(sessopts, &dep_graph, None, registry);
20152013
let cfg = build_configuration(&sess, cfg);
20162014
let mut test_items = cfg.iter().filter(|&&(name, _)| name == "test");
20172015
assert!(test_items.next().is_some());
@@ -2027,8 +2025,7 @@ mod tests {
20272025
]).unwrap();
20282026
let registry = errors::registry::Registry::new(&[]);
20292027
let (sessopts, _) = build_session_options_and_crate_config(&matches);
2030-
let sess = build_session(sessopts, &dep_graph, None, registry,
2031-
Rc::new(DummyCrateStore));
2028+
let sess = build_session(sessopts, &dep_graph, None, registry);
20322029
assert!(!sess.diagnostic().can_emit_warnings);
20332030
}
20342031

@@ -2039,8 +2036,7 @@ mod tests {
20392036
]).unwrap();
20402037
let registry = errors::registry::Registry::new(&[]);
20412038
let (sessopts, _) = build_session_options_and_crate_config(&matches);
2042-
let sess = build_session(sessopts, &dep_graph, None, registry,
2043-
Rc::new(DummyCrateStore));
2039+
let sess = build_session(sessopts, &dep_graph, None, registry);
20442040
assert!(sess.diagnostic().can_emit_warnings);
20452041
}
20462042

@@ -2050,8 +2046,7 @@ mod tests {
20502046
]).unwrap();
20512047
let registry = errors::registry::Registry::new(&[]);
20522048
let (sessopts, _) = build_session_options_and_crate_config(&matches);
2053-
let sess = build_session(sessopts, &dep_graph, None, registry,
2054-
Rc::new(DummyCrateStore));
2049+
let sess = build_session(sessopts, &dep_graph, None, registry);
20552050
assert!(sess.diagnostic().can_emit_warnings);
20562051
}
20572052
}

src/librustc/session/mod.rs

+3-11
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ use dep_graph::DepGraph;
1515
use hir::def_id::{CrateNum, DefIndex};
1616

1717
use lint;
18-
use middle::cstore::CrateStore;
1918
use middle::allocator::AllocatorKind;
2019
use middle::dependency_format;
2120
use session::search_paths::PathKind;
@@ -63,7 +62,6 @@ pub struct Session {
6362
pub target: config::Config,
6463
pub host: Target,
6564
pub opts: config::Options,
66-
pub cstore: Rc<CrateStore>,
6765
pub parse_sess: ParseSess,
6866
// For a library crate, this is always none
6967
pub entry_fn: RefCell<Option<(NodeId, Span)>>,
@@ -621,16 +619,14 @@ impl Session {
621619
pub fn build_session(sopts: config::Options,
622620
dep_graph: &DepGraph,
623621
local_crate_source_file: Option<PathBuf>,
624-
registry: errors::registry::Registry,
625-
cstore: Rc<CrateStore>)
622+
registry: errors::registry::Registry)
626623
-> Session {
627624
let file_path_mapping = sopts.file_path_mapping();
628625

629626
build_session_with_codemap(sopts,
630627
dep_graph,
631628
local_crate_source_file,
632629
registry,
633-
cstore,
634630
Rc::new(codemap::CodeMap::new(file_path_mapping)),
635631
None)
636632
}
@@ -639,7 +635,6 @@ pub fn build_session_with_codemap(sopts: config::Options,
639635
dep_graph: &DepGraph,
640636
local_crate_source_file: Option<PathBuf>,
641637
registry: errors::registry::Registry,
642-
cstore: Rc<CrateStore>,
643638
codemap: Rc<codemap::CodeMap>,
644639
emitter_dest: Option<Box<Write + Send>>)
645640
-> Session {
@@ -680,16 +675,14 @@ pub fn build_session_with_codemap(sopts: config::Options,
680675
dep_graph,
681676
local_crate_source_file,
682677
diagnostic_handler,
683-
codemap,
684-
cstore)
678+
codemap)
685679
}
686680

687681
pub fn build_session_(sopts: config::Options,
688682
dep_graph: &DepGraph,
689683
local_crate_source_file: Option<PathBuf>,
690684
span_diagnostic: errors::Handler,
691-
codemap: Rc<codemap::CodeMap>,
692-
cstore: Rc<CrateStore>)
685+
codemap: Rc<codemap::CodeMap>)
693686
-> Session {
694687
let host = match Target::search(config::host_triple()) {
695688
Ok(t) => t,
@@ -726,7 +719,6 @@ pub fn build_session_(sopts: config::Options,
726719
target: target_cfg,
727720
host,
728721
opts: sopts,
729-
cstore,
730722
parse_sess: p_s,
731723
// For a library crate, this is always none
732724
entry_fn: RefCell::new(None),

0 commit comments

Comments
 (0)