Remove the cstore reference from Session in order to prepare encapsulating CrateStore access in tcx.
This commit is contained in:
parent
817e1b81e2
commit
54fa047d92
22 changed files with 135 additions and 85 deletions
|
|
@ -45,6 +45,7 @@ use hir::map::{Definitions, DefKey};
|
|||
use hir::def_id::{DefIndex, DefId, CRATE_DEF_INDEX};
|
||||
use hir::def::{Def, PathResolution};
|
||||
use lint::builtin::PARENTHESIZED_PARAMS_IN_TYPES_AND_MODULES;
|
||||
use middle::cstore::CrateStore;
|
||||
use rustc_data_structures::indexed_vec::IndexVec;
|
||||
use session::Session;
|
||||
use util::common::FN_OUTPUT_NAME;
|
||||
|
|
@ -74,6 +75,8 @@ pub struct LoweringContext<'a> {
|
|||
// Use to assign ids to hir nodes that do not directly correspond to an ast node
|
||||
sess: &'a Session,
|
||||
|
||||
cstore: &'a CrateStore,
|
||||
|
||||
// As we walk the AST we must keep track of the current 'parent' def id (in
|
||||
// the form of a DefIndex) so that if we create a new node which introduces
|
||||
// a definition, then we can properly create the def id.
|
||||
|
|
@ -118,6 +121,7 @@ pub trait Resolver {
|
|||
}
|
||||
|
||||
pub fn lower_crate(sess: &Session,
|
||||
cstore: &CrateStore,
|
||||
krate: &Crate,
|
||||
resolver: &mut Resolver)
|
||||
-> hir::Crate {
|
||||
|
|
@ -129,6 +133,7 @@ pub fn lower_crate(sess: &Session,
|
|||
LoweringContext {
|
||||
crate_root: std_inject::injected_crate_name(krate),
|
||||
sess,
|
||||
cstore,
|
||||
parent_def: None,
|
||||
resolver,
|
||||
name_map: FxHashMap(),
|
||||
|
|
@ -534,7 +539,7 @@ impl<'a> LoweringContext<'a> {
|
|||
if id.is_local() {
|
||||
self.resolver.definitions().def_key(id.index)
|
||||
} else {
|
||||
self.sess.cstore.def_key(id)
|
||||
self.cstore.def_key(id)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -786,7 +791,7 @@ impl<'a> LoweringContext<'a> {
|
|||
return n;
|
||||
}
|
||||
assert!(!def_id.is_local());
|
||||
let n = self.sess.cstore.item_generics_cloned_untracked(def_id).regions.len();
|
||||
let n = self.cstore.item_generics_cloned_untracked(def_id).regions.len();
|
||||
self.type_def_lifetime_params.insert(def_id, n);
|
||||
n
|
||||
});
|
||||
|
|
|
|||
|
|
@ -16,9 +16,10 @@
|
|||
//! way. Therefore we break lifetime name resolution into a separate pass.
|
||||
|
||||
use hir::map::Map;
|
||||
use session::Session;
|
||||
use hir::def::Def;
|
||||
use hir::def_id::DefId;
|
||||
use middle::cstore::CrateStore;
|
||||
use session::Session;
|
||||
use ty;
|
||||
|
||||
use std::cell::Cell;
|
||||
|
|
@ -160,6 +161,7 @@ pub struct NamedRegionMap {
|
|||
|
||||
struct LifetimeContext<'a, 'tcx: 'a> {
|
||||
sess: &'a Session,
|
||||
cstore: &'a CrateStore,
|
||||
hir_map: &'a Map<'tcx>,
|
||||
map: &'a mut NamedRegionMap,
|
||||
scope: ScopeRef<'a>,
|
||||
|
|
@ -251,6 +253,7 @@ type ScopeRef<'a> = &'a Scope<'a>;
|
|||
const ROOT_SCOPE: ScopeRef<'static> = &Scope::Root;
|
||||
|
||||
pub fn krate(sess: &Session,
|
||||
cstore: &CrateStore,
|
||||
hir_map: &Map)
|
||||
-> Result<NamedRegionMap, ErrorReported> {
|
||||
let krate = hir_map.krate();
|
||||
|
|
@ -262,6 +265,7 @@ pub fn krate(sess: &Session,
|
|||
sess.track_errors(|| {
|
||||
let mut visitor = LifetimeContext {
|
||||
sess,
|
||||
cstore,
|
||||
hir_map,
|
||||
map: &mut map,
|
||||
scope: ROOT_SCOPE,
|
||||
|
|
@ -765,12 +769,13 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
|
|||
fn with<F>(&mut self, wrap_scope: Scope, f: F) where
|
||||
F: for<'b> FnOnce(ScopeRef, &mut LifetimeContext<'b, 'tcx>),
|
||||
{
|
||||
let LifetimeContext {sess, hir_map, ref mut map, ..} = *self;
|
||||
let LifetimeContext {sess, cstore, hir_map, ref mut map, ..} = *self;
|
||||
let labels_in_fn = replace(&mut self.labels_in_fn, vec![]);
|
||||
let xcrate_object_lifetime_defaults =
|
||||
replace(&mut self.xcrate_object_lifetime_defaults, DefIdMap());
|
||||
let mut this = LifetimeContext {
|
||||
sess,
|
||||
cstore,
|
||||
hir_map,
|
||||
map: *map,
|
||||
scope: &wrap_scope,
|
||||
|
|
@ -932,7 +937,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
|
|||
let def_key = if def_id.is_local() {
|
||||
this.hir_map.def_key(def_id)
|
||||
} else {
|
||||
this.sess.cstore.def_key(def_id)
|
||||
this.cstore.def_key(def_id)
|
||||
};
|
||||
DefId {
|
||||
krate: def_id.krate,
|
||||
|
|
@ -976,7 +981,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
|
|||
let unsubst = if let Some(id) = self.hir_map.as_local_node_id(def_id) {
|
||||
&map.object_lifetime_defaults[&id]
|
||||
} else {
|
||||
let cstore = &self.sess.cstore;
|
||||
let cstore = self.cstore;
|
||||
self.xcrate_object_lifetime_defaults.entry(def_id).or_insert_with(|| {
|
||||
cstore.item_generics_cloned_untracked(def_id).types.into_iter().map(|def| {
|
||||
def.object_lifetime_default
|
||||
|
|
|
|||
|
|
@ -1953,13 +1953,12 @@ mod tests {
|
|||
use errors;
|
||||
use getopts;
|
||||
use lint;
|
||||
use middle::cstore::{self, DummyCrateStore};
|
||||
use middle::cstore;
|
||||
use session::config::{build_configuration, build_session_options_and_crate_config};
|
||||
use session::build_session;
|
||||
use std::collections::{BTreeMap, BTreeSet};
|
||||
use std::iter::FromIterator;
|
||||
use std::path::PathBuf;
|
||||
use std::rc::Rc;
|
||||
use super::{OutputType, OutputTypes, Externs};
|
||||
use rustc_back::{PanicStrategy, RelroLevel};
|
||||
use syntax::symbol::Symbol;
|
||||
|
|
@ -1991,7 +1990,7 @@ mod tests {
|
|||
};
|
||||
let registry = errors::registry::Registry::new(&[]);
|
||||
let (sessopts, cfg) = build_session_options_and_crate_config(matches);
|
||||
let sess = build_session(sessopts, &dep_graph, None, registry, Rc::new(DummyCrateStore));
|
||||
let sess = build_session(sessopts, &dep_graph, None, registry);
|
||||
let cfg = build_configuration(&sess, cfg);
|
||||
assert!(cfg.contains(&(Symbol::intern("test"), None)));
|
||||
}
|
||||
|
|
@ -2010,8 +2009,7 @@ mod tests {
|
|||
};
|
||||
let registry = errors::registry::Registry::new(&[]);
|
||||
let (sessopts, cfg) = build_session_options_and_crate_config(matches);
|
||||
let sess = build_session(sessopts, &dep_graph, None, registry,
|
||||
Rc::new(DummyCrateStore));
|
||||
let sess = build_session(sessopts, &dep_graph, None, registry);
|
||||
let cfg = build_configuration(&sess, cfg);
|
||||
let mut test_items = cfg.iter().filter(|&&(name, _)| name == "test");
|
||||
assert!(test_items.next().is_some());
|
||||
|
|
@ -2027,8 +2025,7 @@ mod tests {
|
|||
]).unwrap();
|
||||
let registry = errors::registry::Registry::new(&[]);
|
||||
let (sessopts, _) = build_session_options_and_crate_config(&matches);
|
||||
let sess = build_session(sessopts, &dep_graph, None, registry,
|
||||
Rc::new(DummyCrateStore));
|
||||
let sess = build_session(sessopts, &dep_graph, None, registry);
|
||||
assert!(!sess.diagnostic().can_emit_warnings);
|
||||
}
|
||||
|
||||
|
|
@ -2039,8 +2036,7 @@ mod tests {
|
|||
]).unwrap();
|
||||
let registry = errors::registry::Registry::new(&[]);
|
||||
let (sessopts, _) = build_session_options_and_crate_config(&matches);
|
||||
let sess = build_session(sessopts, &dep_graph, None, registry,
|
||||
Rc::new(DummyCrateStore));
|
||||
let sess = build_session(sessopts, &dep_graph, None, registry);
|
||||
assert!(sess.diagnostic().can_emit_warnings);
|
||||
}
|
||||
|
||||
|
|
@ -2050,8 +2046,7 @@ mod tests {
|
|||
]).unwrap();
|
||||
let registry = errors::registry::Registry::new(&[]);
|
||||
let (sessopts, _) = build_session_options_and_crate_config(&matches);
|
||||
let sess = build_session(sessopts, &dep_graph, None, registry,
|
||||
Rc::new(DummyCrateStore));
|
||||
let sess = build_session(sessopts, &dep_graph, None, registry);
|
||||
assert!(sess.diagnostic().can_emit_warnings);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,7 +15,6 @@ use dep_graph::DepGraph;
|
|||
use hir::def_id::{CrateNum, DefIndex};
|
||||
|
||||
use lint;
|
||||
use middle::cstore::CrateStore;
|
||||
use middle::allocator::AllocatorKind;
|
||||
use middle::dependency_format;
|
||||
use session::search_paths::PathKind;
|
||||
|
|
@ -63,7 +62,6 @@ pub struct Session {
|
|||
pub target: config::Config,
|
||||
pub host: Target,
|
||||
pub opts: config::Options,
|
||||
pub cstore: Rc<CrateStore>,
|
||||
pub parse_sess: ParseSess,
|
||||
// For a library crate, this is always none
|
||||
pub entry_fn: RefCell<Option<(NodeId, Span)>>,
|
||||
|
|
@ -621,8 +619,7 @@ impl Session {
|
|||
pub fn build_session(sopts: config::Options,
|
||||
dep_graph: &DepGraph,
|
||||
local_crate_source_file: Option<PathBuf>,
|
||||
registry: errors::registry::Registry,
|
||||
cstore: Rc<CrateStore>)
|
||||
registry: errors::registry::Registry)
|
||||
-> Session {
|
||||
let file_path_mapping = sopts.file_path_mapping();
|
||||
|
||||
|
|
@ -630,7 +627,6 @@ pub fn build_session(sopts: config::Options,
|
|||
dep_graph,
|
||||
local_crate_source_file,
|
||||
registry,
|
||||
cstore,
|
||||
Rc::new(codemap::CodeMap::new(file_path_mapping)),
|
||||
None)
|
||||
}
|
||||
|
|
@ -639,7 +635,6 @@ pub fn build_session_with_codemap(sopts: config::Options,
|
|||
dep_graph: &DepGraph,
|
||||
local_crate_source_file: Option<PathBuf>,
|
||||
registry: errors::registry::Registry,
|
||||
cstore: Rc<CrateStore>,
|
||||
codemap: Rc<codemap::CodeMap>,
|
||||
emitter_dest: Option<Box<Write + Send>>)
|
||||
-> Session {
|
||||
|
|
@ -680,16 +675,14 @@ pub fn build_session_with_codemap(sopts: config::Options,
|
|||
dep_graph,
|
||||
local_crate_source_file,
|
||||
diagnostic_handler,
|
||||
codemap,
|
||||
cstore)
|
||||
codemap)
|
||||
}
|
||||
|
||||
pub fn build_session_(sopts: config::Options,
|
||||
dep_graph: &DepGraph,
|
||||
local_crate_source_file: Option<PathBuf>,
|
||||
span_diagnostic: errors::Handler,
|
||||
codemap: Rc<codemap::CodeMap>,
|
||||
cstore: Rc<CrateStore>)
|
||||
codemap: Rc<codemap::CodeMap>)
|
||||
-> Session {
|
||||
let host = match Target::search(config::host_triple()) {
|
||||
Ok(t) => t,
|
||||
|
|
@ -726,7 +719,6 @@ pub fn build_session_(sopts: config::Options,
|
|||
target: target_cfg,
|
||||
host,
|
||||
opts: sopts,
|
||||
cstore,
|
||||
parse_sess: p_s,
|
||||
// For a library crate, this is always none
|
||||
entry_fn: RefCell::new(None),
|
||||
|
|
|
|||
|
|
@ -21,7 +21,11 @@ use hir::map as hir_map;
|
|||
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::free_region::FreeRegionMap;
|
||||
use middle::lang_items;
|
||||
use middle::resolve_lifetime::{self, ObjectLifetimeDefault};
|
||||
|
|
@ -810,8 +814,11 @@ pub struct GlobalCtxt<'tcx> {
|
|||
global_arenas: &'tcx GlobalArenas<'tcx>,
|
||||
global_interners: CtxtInterners<'tcx>,
|
||||
|
||||
cstore: &'tcx CrateStore,
|
||||
|
||||
pub sess: &'tcx Session,
|
||||
|
||||
|
||||
pub trans_trait_caches: traits::trans::TransTraitCaches<'tcx>,
|
||||
|
||||
pub dep_graph: DepGraph,
|
||||
|
|
@ -908,6 +915,10 @@ 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)
|
||||
}
|
||||
|
|
@ -1009,6 +1020,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
|||
/// value (types, substs, etc.) can only be used while `ty::tls` has a valid
|
||||
/// reference to the context, to allow formatting values that need it.
|
||||
pub fn create_and_enter<F, R>(s: &'tcx Session,
|
||||
cstore: &'tcx CrateStore,
|
||||
local_providers: ty::maps::Providers<'tcx>,
|
||||
extern_providers: ty::maps::Providers<'tcx>,
|
||||
mir_passes: Rc<Passes>,
|
||||
|
|
@ -1025,16 +1037,15 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
|||
let interners = CtxtInterners::new(arena);
|
||||
let common_types = CommonTypes::new(&interners);
|
||||
let dep_graph = hir.dep_graph.clone();
|
||||
let max_cnum = s.cstore.crates_untracked().iter().map(|c| c.as_usize()).max().unwrap_or(0);
|
||||
let max_cnum = cstore.crates_untracked().iter().map(|c| c.as_usize()).max().unwrap_or(0);
|
||||
let mut providers = IndexVec::from_elem_n(extern_providers, max_cnum + 1);
|
||||
providers[LOCAL_CRATE] = local_providers;
|
||||
|
||||
let def_path_hash_to_def_id = if s.opts.build_dep_graph() {
|
||||
let upstream_def_path_tables: Vec<(CrateNum, Rc<_>)> = s
|
||||
.cstore
|
||||
let upstream_def_path_tables: Vec<(CrateNum, Rc<_>)> = cstore
|
||||
.crates_untracked()
|
||||
.iter()
|
||||
.map(|&cnum| (cnum, s.cstore.def_path_table(cnum)))
|
||||
.map(|&cnum| (cnum, cstore.def_path_table(cnum)))
|
||||
.collect();
|
||||
|
||||
let def_path_tables = || {
|
||||
|
|
@ -1093,6 +1104,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
|||
|
||||
tls::enter_global(GlobalCtxt {
|
||||
sess: s,
|
||||
cstore,
|
||||
trans_trait_caches: traits::trans::TransTraitCaches::new(dep_graph.clone()),
|
||||
global_arenas: arenas,
|
||||
global_interners: interners,
|
||||
|
|
|
|||
|
|
@ -151,7 +151,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
cur_path.push(self.sess.cstore.def_key(cur_def)
|
||||
cur_path.push(self.cstore_untracked().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) {
|
||||
|
|
|
|||
|
|
@ -2174,7 +2174,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
|||
if id.is_local() {
|
||||
self.hir.def_key(id)
|
||||
} else {
|
||||
self.sess.cstore.def_key(id)
|
||||
self.cstore_untracked().def_key(id)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -2187,7 +2187,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
|||
if id.is_local() {
|
||||
self.hir.def_path(id)
|
||||
} else {
|
||||
self.sess.cstore.def_path(id)
|
||||
self.cstore_untracked().def_path(id)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -2196,7 +2196,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
|||
if def_id.is_local() {
|
||||
self.hir.definitions().def_path_hash(def_id.index)
|
||||
} else {
|
||||
self.sess.cstore.def_path_hash(def_id)
|
||||
self.cstore_untracked().def_path_hash(def_id)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -2206,7 +2206,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
|||
} else if id.index == CRATE_DEF_INDEX {
|
||||
self.original_crate_name(id.krate).as_str()
|
||||
} else {
|
||||
let def_key = self.sess.cstore.def_key(id);
|
||||
let def_key = self.cstore_untracked().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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue