Skip to content

rustc: Make CrateStore private to TyCtxt #44420

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 7 additions & 2 deletions src/librustc/hir/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -118,6 +121,7 @@ pub trait Resolver {
}

pub fn lower_crate(sess: &Session,
cstore: &CrateStore,
krate: &Crate,
resolver: &mut Resolver)
-> hir::Crate {
Expand All @@ -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(),
Expand Down Expand Up @@ -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)
}
}

Expand Down Expand Up @@ -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
});
Expand Down
13 changes: 9 additions & 4 deletions src/librustc/middle/resolve_lifetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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>,
Expand Down Expand Up @@ -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();
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
17 changes: 6 additions & 11 deletions src/librustc/session/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)));
}
Expand All @@ -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());
Expand All @@ -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);
}

Expand All @@ -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);
}

Expand All @@ -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);
}
}
Expand Down
14 changes: 3 additions & 11 deletions src/librustc/session/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)>>,
Expand Down Expand Up @@ -621,16 +619,14 @@ 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();

build_session_with_codemap(sopts,
dep_graph,
local_crate_source_file,
registry,
cstore,
Rc::new(codemap::CodeMap::new(file_path_mapping)),
None)
}
Expand All @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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),
Expand Down
Loading