1
Fork 0

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)
This commit is contained in:
bors 2017-09-13 05:32:00 +00:00
commit c3eccc694c
26 changed files with 194 additions and 135 deletions

6
src/Cargo.lock generated
View file

@ -1336,7 +1336,7 @@ dependencies = [
"racer 2.0.10 (registry+https://github.com/rust-lang/crates.io-index)", "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-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-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-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)", "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)", "rustfmt-nightly 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1371,7 +1371,7 @@ dependencies = [
[[package]] [[package]]
name = "rls-rustc" name = "rls-rustc"
version = "0.1.0" version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]] [[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 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-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-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-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 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" "checksum rustc-demangle 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "aee45432acc62f7b9a108cc054142dac51f979e69e71ddce7d6fc7adf29e817e"

View file

@ -45,6 +45,7 @@ use hir::map::{Definitions, DefKey};
use hir::def_id::{DefIndex, DefId, CRATE_DEF_INDEX}; use hir::def_id::{DefIndex, DefId, CRATE_DEF_INDEX};
use hir::def::{Def, PathResolution}; use hir::def::{Def, PathResolution};
use lint::builtin::PARENTHESIZED_PARAMS_IN_TYPES_AND_MODULES; use lint::builtin::PARENTHESIZED_PARAMS_IN_TYPES_AND_MODULES;
use middle::cstore::CrateStore;
use rustc_data_structures::indexed_vec::IndexVec; use rustc_data_structures::indexed_vec::IndexVec;
use session::Session; use session::Session;
use util::common::FN_OUTPUT_NAME; 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 // Use to assign ids to hir nodes that do not directly correspond to an ast node
sess: &'a Session, sess: &'a Session,
cstore: &'a CrateStore,
// As we walk the AST we must keep track of the current 'parent' def id (in // 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 // 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. // a definition, then we can properly create the def id.
@ -118,6 +121,7 @@ pub trait Resolver {
} }
pub fn lower_crate(sess: &Session, pub fn lower_crate(sess: &Session,
cstore: &CrateStore,
krate: &Crate, krate: &Crate,
resolver: &mut Resolver) resolver: &mut Resolver)
-> hir::Crate { -> hir::Crate {
@ -129,6 +133,7 @@ pub fn lower_crate(sess: &Session,
LoweringContext { LoweringContext {
crate_root: std_inject::injected_crate_name(krate), crate_root: std_inject::injected_crate_name(krate),
sess, sess,
cstore,
parent_def: None, parent_def: None,
resolver, resolver,
name_map: FxHashMap(), name_map: FxHashMap(),
@ -534,7 +539,7 @@ impl<'a> LoweringContext<'a> {
if id.is_local() { if id.is_local() {
self.resolver.definitions().def_key(id.index) self.resolver.definitions().def_key(id.index)
} else { } else {
self.sess.cstore.def_key(id) self.cstore.def_key(id)
} }
} }
@ -786,7 +791,7 @@ impl<'a> LoweringContext<'a> {
return n; return n;
} }
assert!(!def_id.is_local()); 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); self.type_def_lifetime_params.insert(def_id, n);
n n
}); });

View file

@ -16,9 +16,10 @@
//! way. Therefore we break lifetime name resolution into a separate pass. //! way. Therefore we break lifetime name resolution into a separate pass.
use hir::map::Map; use hir::map::Map;
use session::Session;
use hir::def::Def; use hir::def::Def;
use hir::def_id::DefId; use hir::def_id::DefId;
use middle::cstore::CrateStore;
use session::Session;
use ty; use ty;
use std::cell::Cell; use std::cell::Cell;
@ -160,6 +161,7 @@ pub struct NamedRegionMap {
struct LifetimeContext<'a, 'tcx: 'a> { struct LifetimeContext<'a, 'tcx: 'a> {
sess: &'a Session, sess: &'a Session,
cstore: &'a CrateStore,
hir_map: &'a Map<'tcx>, hir_map: &'a Map<'tcx>,
map: &'a mut NamedRegionMap, map: &'a mut NamedRegionMap,
scope: ScopeRef<'a>, scope: ScopeRef<'a>,
@ -251,6 +253,7 @@ type ScopeRef<'a> = &'a Scope<'a>;
const ROOT_SCOPE: ScopeRef<'static> = &Scope::Root; const ROOT_SCOPE: ScopeRef<'static> = &Scope::Root;
pub fn krate(sess: &Session, pub fn krate(sess: &Session,
cstore: &CrateStore,
hir_map: &Map) hir_map: &Map)
-> Result<NamedRegionMap, ErrorReported> { -> Result<NamedRegionMap, ErrorReported> {
let krate = hir_map.krate(); let krate = hir_map.krate();
@ -262,6 +265,7 @@ pub fn krate(sess: &Session,
sess.track_errors(|| { sess.track_errors(|| {
let mut visitor = LifetimeContext { let mut visitor = LifetimeContext {
sess, sess,
cstore,
hir_map, hir_map,
map: &mut map, map: &mut map,
scope: ROOT_SCOPE, scope: ROOT_SCOPE,
@ -765,12 +769,13 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
fn with<F>(&mut self, wrap_scope: Scope, f: F) where fn with<F>(&mut self, wrap_scope: Scope, f: F) where
F: for<'b> FnOnce(ScopeRef, &mut LifetimeContext<'b, 'tcx>), 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 labels_in_fn = replace(&mut self.labels_in_fn, vec![]);
let xcrate_object_lifetime_defaults = let xcrate_object_lifetime_defaults =
replace(&mut self.xcrate_object_lifetime_defaults, DefIdMap()); replace(&mut self.xcrate_object_lifetime_defaults, DefIdMap());
let mut this = LifetimeContext { let mut this = LifetimeContext {
sess, sess,
cstore,
hir_map, hir_map,
map: *map, map: *map,
scope: &wrap_scope, scope: &wrap_scope,
@ -932,7 +937,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
let def_key = if def_id.is_local() { let def_key = if def_id.is_local() {
this.hir_map.def_key(def_id) this.hir_map.def_key(def_id)
} else { } else {
this.sess.cstore.def_key(def_id) this.cstore.def_key(def_id)
}; };
DefId { DefId {
krate: def_id.krate, 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) { let unsubst = if let Some(id) = self.hir_map.as_local_node_id(def_id) {
&map.object_lifetime_defaults[&id] &map.object_lifetime_defaults[&id]
} else { } else {
let cstore = &self.sess.cstore; let cstore = self.cstore;
self.xcrate_object_lifetime_defaults.entry(def_id).or_insert_with(|| { self.xcrate_object_lifetime_defaults.entry(def_id).or_insert_with(|| {
cstore.item_generics_cloned_untracked(def_id).types.into_iter().map(|def| { cstore.item_generics_cloned_untracked(def_id).types.into_iter().map(|def| {
def.object_lifetime_default def.object_lifetime_default

View file

@ -1953,13 +1953,12 @@ mod tests {
use errors; use errors;
use getopts; use getopts;
use lint; use lint;
use middle::cstore::{self, DummyCrateStore}; use middle::cstore;
use session::config::{build_configuration, build_session_options_and_crate_config}; use session::config::{build_configuration, build_session_options_and_crate_config};
use session::build_session; use session::build_session;
use std::collections::{BTreeMap, BTreeSet}; use std::collections::{BTreeMap, BTreeSet};
use std::iter::FromIterator; use std::iter::FromIterator;
use std::path::PathBuf; use std::path::PathBuf;
use std::rc::Rc;
use super::{OutputType, OutputTypes, Externs}; use super::{OutputType, OutputTypes, Externs};
use rustc_back::{PanicStrategy, RelroLevel}; use rustc_back::{PanicStrategy, RelroLevel};
use syntax::symbol::Symbol; use syntax::symbol::Symbol;
@ -1991,7 +1990,7 @@ mod tests {
}; };
let registry = errors::registry::Registry::new(&[]); let registry = errors::registry::Registry::new(&[]);
let (sessopts, cfg) = build_session_options_and_crate_config(matches); 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 cfg = build_configuration(&sess, cfg);
assert!(cfg.contains(&(Symbol::intern("test"), None))); assert!(cfg.contains(&(Symbol::intern("test"), None)));
} }
@ -2010,8 +2009,7 @@ mod tests {
}; };
let registry = errors::registry::Registry::new(&[]); let registry = errors::registry::Registry::new(&[]);
let (sessopts, cfg) = build_session_options_and_crate_config(matches); let (sessopts, cfg) = build_session_options_and_crate_config(matches);
let sess = build_session(sessopts, &dep_graph, None, registry, let sess = build_session(sessopts, &dep_graph, None, registry);
Rc::new(DummyCrateStore));
let cfg = build_configuration(&sess, cfg); let cfg = build_configuration(&sess, cfg);
let mut test_items = cfg.iter().filter(|&&(name, _)| name == "test"); let mut test_items = cfg.iter().filter(|&&(name, _)| name == "test");
assert!(test_items.next().is_some()); assert!(test_items.next().is_some());
@ -2027,8 +2025,7 @@ mod tests {
]).unwrap(); ]).unwrap();
let registry = errors::registry::Registry::new(&[]); let registry = errors::registry::Registry::new(&[]);
let (sessopts, _) = build_session_options_and_crate_config(&matches); let (sessopts, _) = build_session_options_and_crate_config(&matches);
let sess = build_session(sessopts, &dep_graph, None, registry, let sess = build_session(sessopts, &dep_graph, None, registry);
Rc::new(DummyCrateStore));
assert!(!sess.diagnostic().can_emit_warnings); assert!(!sess.diagnostic().can_emit_warnings);
} }
@ -2039,8 +2036,7 @@ mod tests {
]).unwrap(); ]).unwrap();
let registry = errors::registry::Registry::new(&[]); let registry = errors::registry::Registry::new(&[]);
let (sessopts, _) = build_session_options_and_crate_config(&matches); let (sessopts, _) = build_session_options_and_crate_config(&matches);
let sess = build_session(sessopts, &dep_graph, None, registry, let sess = build_session(sessopts, &dep_graph, None, registry);
Rc::new(DummyCrateStore));
assert!(sess.diagnostic().can_emit_warnings); assert!(sess.diagnostic().can_emit_warnings);
} }
@ -2050,8 +2046,7 @@ mod tests {
]).unwrap(); ]).unwrap();
let registry = errors::registry::Registry::new(&[]); let registry = errors::registry::Registry::new(&[]);
let (sessopts, _) = build_session_options_and_crate_config(&matches); let (sessopts, _) = build_session_options_and_crate_config(&matches);
let sess = build_session(sessopts, &dep_graph, None, registry, let sess = build_session(sessopts, &dep_graph, None, registry);
Rc::new(DummyCrateStore));
assert!(sess.diagnostic().can_emit_warnings); assert!(sess.diagnostic().can_emit_warnings);
} }
} }

View file

@ -15,7 +15,6 @@ use dep_graph::DepGraph;
use hir::def_id::{CrateNum, DefIndex}; use hir::def_id::{CrateNum, DefIndex};
use lint; use lint;
use middle::cstore::CrateStore;
use middle::allocator::AllocatorKind; use middle::allocator::AllocatorKind;
use middle::dependency_format; use middle::dependency_format;
use session::search_paths::PathKind; use session::search_paths::PathKind;
@ -63,7 +62,6 @@ pub struct Session {
pub target: config::Config, pub target: config::Config,
pub host: Target, pub host: Target,
pub opts: config::Options, pub opts: config::Options,
pub cstore: Rc<CrateStore>,
pub parse_sess: ParseSess, pub parse_sess: ParseSess,
// For a library crate, this is always none // For a library crate, this is always none
pub entry_fn: RefCell<Option<(NodeId, Span)>>, pub entry_fn: RefCell<Option<(NodeId, Span)>>,
@ -621,8 +619,7 @@ impl Session {
pub fn build_session(sopts: config::Options, pub fn build_session(sopts: config::Options,
dep_graph: &DepGraph, dep_graph: &DepGraph,
local_crate_source_file: Option<PathBuf>, local_crate_source_file: Option<PathBuf>,
registry: errors::registry::Registry, registry: errors::registry::Registry)
cstore: Rc<CrateStore>)
-> Session { -> Session {
let file_path_mapping = sopts.file_path_mapping(); let file_path_mapping = sopts.file_path_mapping();
@ -630,7 +627,6 @@ pub fn build_session(sopts: config::Options,
dep_graph, dep_graph,
local_crate_source_file, local_crate_source_file,
registry, registry,
cstore,
Rc::new(codemap::CodeMap::new(file_path_mapping)), Rc::new(codemap::CodeMap::new(file_path_mapping)),
None) None)
} }
@ -639,7 +635,6 @@ pub fn build_session_with_codemap(sopts: config::Options,
dep_graph: &DepGraph, dep_graph: &DepGraph,
local_crate_source_file: Option<PathBuf>, local_crate_source_file: Option<PathBuf>,
registry: errors::registry::Registry, registry: errors::registry::Registry,
cstore: Rc<CrateStore>,
codemap: Rc<codemap::CodeMap>, codemap: Rc<codemap::CodeMap>,
emitter_dest: Option<Box<Write + Send>>) emitter_dest: Option<Box<Write + Send>>)
-> Session { -> Session {
@ -680,16 +675,14 @@ pub fn build_session_with_codemap(sopts: config::Options,
dep_graph, dep_graph,
local_crate_source_file, local_crate_source_file,
diagnostic_handler, diagnostic_handler,
codemap, codemap)
cstore)
} }
pub fn build_session_(sopts: config::Options, pub fn build_session_(sopts: config::Options,
dep_graph: &DepGraph, dep_graph: &DepGraph,
local_crate_source_file: Option<PathBuf>, local_crate_source_file: Option<PathBuf>,
span_diagnostic: errors::Handler, span_diagnostic: errors::Handler,
codemap: Rc<codemap::CodeMap>, codemap: Rc<codemap::CodeMap>)
cstore: Rc<CrateStore>)
-> Session { -> Session {
let host = match Target::search(config::host_triple()) { let host = match Target::search(config::host_triple()) {
Ok(t) => t, Ok(t) => t,
@ -726,7 +719,6 @@ pub fn build_session_(sopts: config::Options,
target: target_cfg, target: target_cfg,
host, host,
opts: sopts, opts: sopts,
cstore,
parse_sess: p_s, parse_sess: p_s,
// For a library crate, this is always none // For a library crate, this is always none
entry_fn: RefCell::new(None), entry_fn: RefCell::new(None),

View file

@ -22,6 +22,8 @@ use hir::map::DefPathHash;
use lint::{self, Lint}; use lint::{self, Lint};
use ich::{self, StableHashingContext, NodeIdHashingMode}; use ich::{self, StableHashingContext, NodeIdHashingMode};
use middle::const_val::ConstVal; use middle::const_val::ConstVal;
use middle::cstore::{CrateStore, LinkMeta, EncodedMetadataHashes};
use middle::cstore::EncodedMetadata;
use middle::free_region::FreeRegionMap; use middle::free_region::FreeRegionMap;
use middle::lang_items; use middle::lang_items;
use middle::resolve_lifetime::{self, ObjectLifetimeDefault}; use middle::resolve_lifetime::{self, ObjectLifetimeDefault};
@ -52,6 +54,7 @@ use rustc_data_structures::stable_hasher::{HashStable, StableHasher,
use arena::{TypedArena, DroplessArena}; use arena::{TypedArena, DroplessArena};
use rustc_const_math::{ConstInt, ConstUsize}; use rustc_const_math::{ConstInt, ConstUsize};
use rustc_data_structures::indexed_vec::IndexVec; use rustc_data_structures::indexed_vec::IndexVec;
use std::any::Any;
use std::borrow::Borrow; use std::borrow::Borrow;
use std::cell::{Cell, RefCell}; use std::cell::{Cell, RefCell};
use std::cmp::Ordering; use std::cmp::Ordering;
@ -810,8 +813,11 @@ pub struct GlobalCtxt<'tcx> {
global_arenas: &'tcx GlobalArenas<'tcx>, global_arenas: &'tcx GlobalArenas<'tcx>,
global_interners: CtxtInterners<'tcx>, global_interners: CtxtInterners<'tcx>,
cstore: &'tcx CrateStore,
pub sess: &'tcx Session, pub sess: &'tcx Session,
pub trans_trait_caches: traits::trans::TransTraitCaches<'tcx>, pub trans_trait_caches: traits::trans::TransTraitCaches<'tcx>,
pub dep_graph: DepGraph, pub dep_graph: DepGraph,
@ -1009,6 +1015,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
/// value (types, substs, etc.) can only be used while `ty::tls` has a valid /// 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. /// reference to the context, to allow formatting values that need it.
pub fn create_and_enter<F, R>(s: &'tcx Session, pub fn create_and_enter<F, R>(s: &'tcx Session,
cstore: &'tcx CrateStore,
local_providers: ty::maps::Providers<'tcx>, local_providers: ty::maps::Providers<'tcx>,
extern_providers: ty::maps::Providers<'tcx>, extern_providers: ty::maps::Providers<'tcx>,
mir_passes: Rc<Passes>, mir_passes: Rc<Passes>,
@ -1025,16 +1032,15 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
let interners = CtxtInterners::new(arena); let interners = CtxtInterners::new(arena);
let common_types = CommonTypes::new(&interners); let common_types = CommonTypes::new(&interners);
let dep_graph = hir.dep_graph.clone(); 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); let mut providers = IndexVec::from_elem_n(extern_providers, max_cnum + 1);
providers[LOCAL_CRATE] = local_providers; providers[LOCAL_CRATE] = local_providers;
let def_path_hash_to_def_id = if s.opts.build_dep_graph() { let def_path_hash_to_def_id = if s.opts.build_dep_graph() {
let upstream_def_path_tables: Vec<(CrateNum, Rc<_>)> = s let upstream_def_path_tables: Vec<(CrateNum, Rc<_>)> = cstore
.cstore
.crates_untracked() .crates_untracked()
.iter() .iter()
.map(|&cnum| (cnum, s.cstore.def_path_table(cnum))) .map(|&cnum| (cnum, cstore.def_path_table(cnum)))
.collect(); .collect();
let def_path_tables = || { let def_path_tables = || {
@ -1093,6 +1099,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
tls::enter_global(GlobalCtxt { tls::enter_global(GlobalCtxt {
sess: s, sess: s,
cstore,
trans_trait_caches: traits::trans::TransTraitCaches::new(dep_graph.clone()), trans_trait_caches: traits::trans::TransTraitCaches::new(dep_graph.clone()),
global_arenas: arenas, global_arenas: arenas,
global_interners: interners, global_interners: interners,
@ -1171,6 +1178,54 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
pub fn crates(self) -> Rc<Vec<CrateNum>> { pub fn crates(self) -> Rc<Vec<CrateNum>> {
self.all_crate_nums(LOCAL_CRATE) 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> { impl<'gcx: 'tcx, 'tcx> GlobalCtxt<'gcx> {
@ -2151,4 +2206,16 @@ pub fn provide(providers: &mut ty::maps::Providers) {
let id = tcx.hir.definitions().def_index_to_hir_id(id.index); let id = tcx.hir.definitions().def_index_to_hir_id(id.index);
tcx.stability().local_deprecation_entry(id) 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())
};
} }

View file

@ -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.def_key(cur_def)
.disambiguated_data.data.get_opt_name().unwrap_or_else(|| .disambiguated_data.data.get_opt_name().unwrap_or_else(||
Symbol::intern("<unnamed>").as_str())); Symbol::intern("<unnamed>").as_str()));
match visible_parent_map.get(&cur_def) { match visible_parent_map.get(&cur_def) {

View file

@ -2170,43 +2170,13 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
} }
} }
pub fn def_key(self, id: DefId) -> hir_map::DefKey {
if id.is_local() {
self.hir.def_key(id)
} else {
self.sess.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.sess.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.sess.cstore.def_path_hash(def_id)
}
}
pub fn item_name(self, id: DefId) -> InternedString { pub fn item_name(self, id: DefId) -> InternedString {
if let Some(id) = self.hir.as_local_node_id(id) { if let Some(id) = self.hir.as_local_node_id(id) {
self.hir.name(id).as_str() self.hir.name(id).as_str()
} else if id.index == CRATE_DEF_INDEX { } else if id.index == CRATE_DEF_INDEX {
self.original_crate_name(id.krate).as_str() self.original_crate_name(id.krate).as_str()
} else { } else {
let def_key = self.sess.cstore.def_key(id); let def_key = self.def_key(id);
// The name of a StructCtor is that of its struct parent. // The name of a StructCtor is that of its struct parent.
if let hir_map::DefPathData::StructCtor = def_key.disambiguated_data.data { if let hir_map::DefPathData::StructCtor = def_key.disambiguated_data.data {
self.item_name(DefId { self.item_name(DefId {

View file

@ -21,6 +21,7 @@ use rustc::session::config::{self, Input, OutputFilenames, OutputType};
use rustc::session::search_paths::PathKind; use rustc::session::search_paths::PathKind;
use rustc::lint; use rustc::lint;
use rustc::middle::{self, stability, reachable}; use rustc::middle::{self, stability, reachable};
use rustc::middle::cstore::CrateStore;
use rustc::middle::privacy::AccessLevels; use rustc::middle::privacy::AccessLevels;
use rustc::mir::transform::{MIR_CONST, MIR_VALIDATED, MIR_OPTIMIZED, Passes}; use rustc::mir::transform::{MIR_CONST, MIR_VALIDATED, MIR_OPTIMIZED, Passes};
use rustc::ty::{self, TyCtxt, Resolutions, GlobalArenas}; use rustc::ty::{self, TyCtxt, Resolutions, GlobalArenas};
@ -200,6 +201,7 @@ pub fn compile_input(sess: &Session,
}; };
phase_3_run_analysis_passes(sess, phase_3_run_analysis_passes(sess,
cstore,
hir_map, hir_map,
analysis, analysis,
resolutions, resolutions,
@ -385,7 +387,7 @@ pub struct CompileState<'a, 'tcx: 'a> {
pub session: &'tcx Session, pub session: &'tcx Session,
pub krate: Option<ast::Crate>, pub krate: Option<ast::Crate>,
pub registry: Option<Registry<'a>>, pub registry: Option<Registry<'a>>,
pub cstore: Option<&'a CStore>, pub cstore: Option<&'tcx CStore>,
pub crate_name: Option<&'a str>, pub crate_name: Option<&'a str>,
pub output_filenames: Option<&'a OutputFilenames>, pub output_filenames: Option<&'a OutputFilenames>,
pub out_dir: Option<&'a Path>, pub out_dir: Option<&'a Path>,
@ -433,7 +435,7 @@ impl<'a, 'tcx> CompileState<'a, 'tcx> {
out_dir: &'a Option<PathBuf>, out_dir: &'a Option<PathBuf>,
out_file: &'a Option<PathBuf>, out_file: &'a Option<PathBuf>,
krate: ast::Crate, krate: ast::Crate,
cstore: &'a CStore) cstore: &'tcx CStore)
-> Self { -> Self {
CompileState { CompileState {
// Initialize the registry before moving `krate` // Initialize the registry before moving `krate`
@ -449,7 +451,7 @@ impl<'a, 'tcx> CompileState<'a, 'tcx> {
session: &'tcx Session, session: &'tcx Session,
out_dir: &'a Option<PathBuf>, out_dir: &'a Option<PathBuf>,
out_file: &'a Option<PathBuf>, out_file: &'a Option<PathBuf>,
cstore: &'a CStore, cstore: &'tcx CStore,
expanded_crate: &'a ast::Crate, expanded_crate: &'a ast::Crate,
crate_name: &'a str) crate_name: &'a str)
-> Self { -> Self {
@ -468,7 +470,7 @@ impl<'a, 'tcx> CompileState<'a, 'tcx> {
out_file: &'a Option<PathBuf>, out_file: &'a Option<PathBuf>,
arena: &'tcx DroplessArena, arena: &'tcx DroplessArena,
arenas: &'tcx GlobalArenas<'tcx>, arenas: &'tcx GlobalArenas<'tcx>,
cstore: &'a CStore, cstore: &'tcx CStore,
hir_map: &'a hir_map::Map<'tcx>, hir_map: &'a hir_map::Map<'tcx>,
analysis: &'a ty::CrateAnalysis, analysis: &'a ty::CrateAnalysis,
resolutions: &'a Resolutions, resolutions: &'a Resolutions,
@ -696,6 +698,7 @@ pub fn phase_2_configure_and_expand<F>(sess: &Session,
let mut crate_loader = CrateLoader::new(sess, &cstore, crate_name); let mut crate_loader = CrateLoader::new(sess, &cstore, crate_name);
let resolver_arenas = Resolver::arenas(); let resolver_arenas = Resolver::arenas();
let mut resolver = Resolver::new(sess, let mut resolver = Resolver::new(sess,
cstore,
&krate, &krate,
crate_name, crate_name,
make_glob_map, make_glob_map,
@ -844,7 +847,7 @@ pub fn phase_2_configure_and_expand<F>(sess: &Session,
// Lower ast -> hir. // Lower ast -> hir.
let hir_forest = time(time_passes, "lowering ast -> hir", || { let hir_forest = time(time_passes, "lowering ast -> hir", || {
let hir_crate = lower_crate(sess, &krate, &mut resolver); let hir_crate = lower_crate(sess, cstore, &krate, &mut resolver);
if sess.opts.debugging_opts.hir_stats { if sess.opts.debugging_opts.hir_stats {
hir_stats::print_hir_stats(&hir_crate); hir_stats::print_hir_stats(&hir_crate);
@ -886,6 +889,7 @@ pub fn phase_2_configure_and_expand<F>(sess: &Session,
/// miscellaneous analysis passes on the crate. Return various /// miscellaneous analysis passes on the crate. Return various
/// structures carrying the results of the analysis. /// structures carrying the results of the analysis.
pub fn phase_3_run_analysis_passes<'tcx, F, R>(sess: &'tcx Session, pub fn phase_3_run_analysis_passes<'tcx, F, R>(sess: &'tcx Session,
cstore: &'tcx CrateStore,
hir_map: hir_map::Map<'tcx>, hir_map: hir_map::Map<'tcx>,
mut analysis: ty::CrateAnalysis, mut analysis: ty::CrateAnalysis,
resolutions: Resolutions, resolutions: Resolutions,
@ -915,7 +919,7 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(sess: &'tcx Session,
let named_region_map = time(time_passes, let named_region_map = time(time_passes,
"lifetime resolution", "lifetime resolution",
|| middle::resolve_lifetime::krate(sess, &hir_map))?; || middle::resolve_lifetime::krate(sess, cstore, &hir_map))?;
time(time_passes, time(time_passes,
"looking for entry point", "looking for entry point",
@ -1012,6 +1016,7 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(sess: &'tcx Session,
passes.push_pass(MIR_OPTIMIZED, mir::transform::dump_mir::Marker("PreTrans")); passes.push_pass(MIR_OPTIMIZED, mir::transform::dump_mir::Marker("PreTrans"));
TyCtxt::create_and_enter(sess, TyCtxt::create_and_enter(sess,
cstore,
local_providers, local_providers,
extern_providers, extern_providers,
Rc::new(passes), Rc::new(passes),
@ -1151,7 +1156,10 @@ pub fn phase_6_link_output(sess: &Session,
trans: &trans::CrateTranslation, trans: &trans::CrateTranslation,
outputs: &OutputFilenames) { outputs: &OutputFilenames) {
time(sess.time_passes(), "linking", || { time(sess.time_passes(), "linking", || {
::rustc_trans::back::link::link_binary(sess, trans, outputs, &trans.crate_name.as_str()) ::rustc_trans::back::link::link_binary(sess,
trans,
outputs,
&trans.crate_name.as_str())
}); });
} }

View file

@ -72,6 +72,7 @@ use rustc::session::config::nightly_options;
use rustc::session::{early_error, early_warn}; use rustc::session::{early_error, early_warn};
use rustc::lint::Lint; use rustc::lint::Lint;
use rustc::lint; use rustc::lint;
use rustc::middle::cstore::CrateStore;
use rustc_metadata::locator; use rustc_metadata::locator;
use rustc_metadata::cstore::CStore; use rustc_metadata::cstore::CStore;
use rustc::util::common::{time, ErrorReported}; use rustc::util::common::{time, ErrorReported};
@ -299,7 +300,7 @@ pub fn run_compiler<'a>(args: &[String],
let loader = file_loader.unwrap_or(box RealFileLoader); let loader = file_loader.unwrap_or(box RealFileLoader);
let codemap = Rc::new(CodeMap::with_file_loader(loader, sopts.file_path_mapping())); let codemap = Rc::new(CodeMap::with_file_loader(loader, sopts.file_path_mapping()));
let mut sess = session::build_session_with_codemap( let mut sess = session::build_session_with_codemap(
sopts, &dep_graph, input_file_path, descriptions, cstore.clone(), codemap, emitter_dest, sopts, &dep_graph, input_file_path, descriptions, codemap, emitter_dest,
); );
rustc_trans::init(&sess); rustc_trans::init(&sess);
rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess)); rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess));
@ -308,7 +309,12 @@ pub fn run_compiler<'a>(args: &[String],
target_features::add_configuration(&mut cfg, &sess); target_features::add_configuration(&mut cfg, &sess);
sess.parse_sess.config = cfg; sess.parse_sess.config = cfg;
do_or_return!(callbacks.late_callback(&matches, &sess, &input, &odir, &ofile), Some(sess)); do_or_return!(callbacks.late_callback(&matches,
&sess,
&*cstore,
&input,
&odir,
&ofile), Some(sess));
let plugins = sess.opts.debugging_opts.extra_plugins.clone(); let plugins = sess.opts.debugging_opts.extra_plugins.clone();
let control = callbacks.build_controller(&sess, &matches); let control = callbacks.build_controller(&sess, &matches);
@ -400,6 +406,7 @@ pub trait CompilerCalls<'a> {
fn late_callback(&mut self, fn late_callback(&mut self,
_: &getopts::Matches, _: &getopts::Matches,
_: &Session, _: &Session,
_: &CrateStore,
_: &Input, _: &Input,
_: &Option<PathBuf>, _: &Option<PathBuf>,
_: &Option<PathBuf>) _: &Option<PathBuf>)
@ -574,12 +581,10 @@ impl<'a> CompilerCalls<'a> for RustcDefaultCalls {
return None; return None;
} }
let dep_graph = DepGraph::new(sopts.build_dep_graph()); let dep_graph = DepGraph::new(sopts.build_dep_graph());
let cstore = Rc::new(CStore::new(box ::MetadataLoader));
let mut sess = build_session(sopts.clone(), let mut sess = build_session(sopts.clone(),
&dep_graph, &dep_graph,
None, None,
descriptions.clone(), descriptions.clone());
cstore.clone());
rustc_trans::init(&sess); rustc_trans::init(&sess);
rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess)); rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess));
let mut cfg = config::build_configuration(&sess, cfg.clone()); let mut cfg = config::build_configuration(&sess, cfg.clone());
@ -601,12 +606,13 @@ impl<'a> CompilerCalls<'a> for RustcDefaultCalls {
fn late_callback(&mut self, fn late_callback(&mut self,
matches: &getopts::Matches, matches: &getopts::Matches,
sess: &Session, sess: &Session,
cstore: &CrateStore,
input: &Input, input: &Input,
odir: &Option<PathBuf>, odir: &Option<PathBuf>,
ofile: &Option<PathBuf>) ofile: &Option<PathBuf>)
-> Compilation { -> Compilation {
RustcDefaultCalls::print_crate_info(sess, Some(input), odir, ofile) RustcDefaultCalls::print_crate_info(sess, Some(input), odir, ofile)
.and_then(|| RustcDefaultCalls::list_metadata(sess, matches, input)) .and_then(|| RustcDefaultCalls::list_metadata(sess, cstore, matches, input))
} }
fn build_controller(&mut self, fn build_controller(&mut self,
@ -627,6 +633,7 @@ impl<'a> CompilerCalls<'a> for RustcDefaultCalls {
}; };
control.after_hir_lowering.callback = box move |state| { control.after_hir_lowering.callback = box move |state| {
pretty::print_after_hir_lowering(state.session, pretty::print_after_hir_lowering(state.session,
state.cstore.unwrap(),
state.hir_map.unwrap(), state.hir_map.unwrap(),
state.analysis.unwrap(), state.analysis.unwrap(),
state.resolutions.unwrap(), state.resolutions.unwrap(),
@ -711,7 +718,11 @@ fn save_analysis(sess: &Session) -> bool {
} }
impl RustcDefaultCalls { impl RustcDefaultCalls {
pub fn list_metadata(sess: &Session, matches: &getopts::Matches, input: &Input) -> Compilation { pub fn list_metadata(sess: &Session,
cstore: &CrateStore,
matches: &getopts::Matches,
input: &Input)
-> Compilation {
let r = matches.opt_strs("Z"); let r = matches.opt_strs("Z");
if r.contains(&("ls".to_string())) { if r.contains(&("ls".to_string())) {
match input { match input {
@ -720,7 +731,7 @@ impl RustcDefaultCalls {
let mut v = Vec::new(); let mut v = Vec::new();
locator::list_file_metadata(&sess.target.target, locator::list_file_metadata(&sess.target.target,
path, path,
sess.cstore.metadata_loader(), cstore.metadata_loader(),
&mut v) &mut v)
.unwrap(); .unwrap();
println!("{}", String::from_utf8(v).unwrap()); println!("{}", String::from_utf8(v).unwrap());

View file

@ -21,6 +21,7 @@ use rustc::ty::{self, TyCtxt, GlobalArenas, Resolutions};
use rustc::cfg; use rustc::cfg;
use rustc::cfg::graphviz::LabelledCFG; use rustc::cfg::graphviz::LabelledCFG;
use rustc::dep_graph::DepGraph; use rustc::dep_graph::DepGraph;
use rustc::middle::cstore::CrateStore;
use rustc::session::Session; use rustc::session::Session;
use rustc::session::config::Input; use rustc::session::config::Input;
use rustc_borrowck as borrowck; use rustc_borrowck as borrowck;
@ -198,6 +199,7 @@ impl PpSourceMode {
} }
fn call_with_pp_support_hir<'tcx, A, F>(&self, fn call_with_pp_support_hir<'tcx, A, F>(&self,
sess: &'tcx Session, sess: &'tcx Session,
cstore: &'tcx CrateStore,
hir_map: &hir_map::Map<'tcx>, hir_map: &hir_map::Map<'tcx>,
analysis: &ty::CrateAnalysis, analysis: &ty::CrateAnalysis,
resolutions: &Resolutions, resolutions: &Resolutions,
@ -226,6 +228,7 @@ impl PpSourceMode {
} }
PpmTyped => { PpmTyped => {
abort_on_err(driver::phase_3_run_analysis_passes(sess, abort_on_err(driver::phase_3_run_analysis_passes(sess,
cstore,
hir_map.clone(), hir_map.clone(),
analysis.clone(), analysis.clone(),
resolutions.clone(), resolutions.clone(),
@ -875,6 +878,7 @@ pub fn print_after_parsing(sess: &Session,
} }
pub fn print_after_hir_lowering<'tcx, 'a: 'tcx>(sess: &'a Session, pub fn print_after_hir_lowering<'tcx, 'a: 'tcx>(sess: &'a Session,
cstore: &'tcx CrateStore,
hir_map: &hir_map::Map<'tcx>, hir_map: &hir_map::Map<'tcx>,
analysis: &ty::CrateAnalysis, analysis: &ty::CrateAnalysis,
resolutions: &Resolutions, resolutions: &Resolutions,
@ -891,6 +895,7 @@ pub fn print_after_hir_lowering<'tcx, 'a: 'tcx>(sess: &'a Session,
if ppm.needs_analysis() { if ppm.needs_analysis() {
print_with_analysis(sess, print_with_analysis(sess,
cstore,
hir_map, hir_map,
analysis, analysis,
resolutions, resolutions,
@ -929,6 +934,7 @@ pub fn print_after_hir_lowering<'tcx, 'a: 'tcx>(sess: &'a Session,
(PpmHir(s), None) => { (PpmHir(s), None) => {
let out: &mut Write = &mut out; let out: &mut Write = &mut out;
s.call_with_pp_support_hir(sess, s.call_with_pp_support_hir(sess,
cstore,
hir_map, hir_map,
analysis, analysis,
resolutions, resolutions,
@ -952,6 +958,7 @@ pub fn print_after_hir_lowering<'tcx, 'a: 'tcx>(sess: &'a Session,
(PpmHir(s), Some(uii)) => { (PpmHir(s), Some(uii)) => {
let out: &mut Write = &mut out; let out: &mut Write = &mut out;
s.call_with_pp_support_hir(sess, s.call_with_pp_support_hir(sess,
cstore,
hir_map, hir_map,
analysis, analysis,
resolutions, resolutions,
@ -993,6 +1000,7 @@ pub fn print_after_hir_lowering<'tcx, 'a: 'tcx>(sess: &'a Session,
// with a different callback than the standard driver, so that isn't easy. // with a different callback than the standard driver, so that isn't easy.
// Instead, we call that function ourselves. // Instead, we call that function ourselves.
fn print_with_analysis<'tcx, 'a: 'tcx>(sess: &'a Session, fn print_with_analysis<'tcx, 'a: 'tcx>(sess: &'a Session,
cstore: &'a CrateStore,
hir_map: &hir_map::Map<'tcx>, hir_map: &hir_map::Map<'tcx>,
analysis: &ty::CrateAnalysis, analysis: &ty::CrateAnalysis,
resolutions: &Resolutions, resolutions: &Resolutions,
@ -1013,6 +1021,7 @@ fn print_with_analysis<'tcx, 'a: 'tcx>(sess: &'a Session,
let mut out = Vec::new(); let mut out = Vec::new();
abort_on_err(driver::phase_3_run_analysis_passes(sess, abort_on_err(driver::phase_3_run_analysis_passes(sess,
cstore,
hir_map.clone(), hir_map.clone(),
analysis.clone(), analysis.clone(),
resolutions.clone(), resolutions.clone(),

View file

@ -109,8 +109,7 @@ fn test_env<F>(source_string: &str,
&dep_graph, &dep_graph,
None, None,
diagnostic_handler, diagnostic_handler,
Rc::new(CodeMap::new(FilePathMapping::empty())), Rc::new(CodeMap::new(FilePathMapping::empty())));
cstore.clone());
rustc_trans::init(&sess); rustc_trans::init(&sess);
rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess)); rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess));
let input = config::Input::Str { let input = config::Input::Str {
@ -138,8 +137,9 @@ fn test_env<F>(source_string: &str,
let hir_map = hir_map::map_crate(&mut hir_forest, defs); let hir_map = hir_map::map_crate(&mut hir_forest, defs);
// run just enough stuff to build a tcx: // run just enough stuff to build a tcx:
let named_region_map = resolve_lifetime::krate(&sess, &hir_map); let named_region_map = resolve_lifetime::krate(&sess, &*cstore, &hir_map);
TyCtxt::create_and_enter(&sess, TyCtxt::create_and_enter(&sess,
&*cstore,
ty::maps::Providers::default(), ty::maps::Providers::default(),
ty::maps::Providers::default(), ty::maps::Providers::default(),
Rc::new(Passes::new()), Rc::new(Passes::new()),

View file

@ -60,7 +60,7 @@ macro_rules! provide {
$tcx.dep_graph.read(dep_node); $tcx.dep_graph.read(dep_node);
let $cdata = $tcx.sess.cstore.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>() let $cdata = $cdata.downcast_ref::<cstore::CrateMetadata>()
.expect("CrateStore crated ata is not a CrateMetadata"); .expect("CrateStore crated ata is not a CrateMetadata");
$compute $compute
@ -275,15 +275,6 @@ pub fn provide_local<'tcx>(providers: &mut Providers<'tcx>) {
assert_eq!(cnum, LOCAL_CRATE); assert_eq!(cnum, LOCAL_CRATE);
Rc::new(link_args::collect(tcx)) Rc::new(link_args::collect(tcx))
}, },
extern_mod_stmt_cnum: |tcx, id| {
let id = tcx.hir.as_local_node_id(id).unwrap();
tcx.sess.cstore.extern_mod_stmt_cnum_untracked(id)
},
all_crate_nums: |tcx, cnum| {
assert_eq!(cnum, LOCAL_CRATE);
Rc::new(tcx.sess.cstore.crates_untracked())
},
// Returns a map from a sufficiently visible external item (i.e. an // 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 // 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>) {
Rc::new(visible_parent_map) Rc::new(visible_parent_map)
}, },
postorder_cnums: |tcx, cnum| {
assert_eq!(cnum, LOCAL_CRATE);
Rc::new(tcx.sess.cstore.postorder_cnums_untracked())
},
..*providers ..*providers
}; };
} }

View file

@ -254,7 +254,7 @@ impl<'a> Resolver<'a> {
self.crate_loader.process_item(item, &self.definitions); self.crate_loader.process_item(item, &self.definitions);
// n.b. we don't need to look at the path option here, because cstore already did // n.b. we don't need to look at the path option here, because cstore already did
let crate_id = self.session.cstore.extern_mod_stmt_cnum_untracked(item.id).unwrap(); let crate_id = self.cstore.extern_mod_stmt_cnum_untracked(item.id).unwrap();
let module = let module =
self.get_module(DefId { krate: crate_id, index: CRATE_DEF_INDEX }); self.get_module(DefId { krate: crate_id, index: CRATE_DEF_INDEX });
self.populate_module_if_necessary(module); self.populate_module_if_necessary(module);
@ -450,7 +450,7 @@ impl<'a> Resolver<'a> {
let ident = child.ident; let ident = child.ident;
let def = child.def; let def = child.def;
let def_id = def.def_id(); let def_id = def.def_id();
let vis = self.session.cstore.visibility_untracked(def_id); let vis = self.cstore.visibility_untracked(def_id);
let span = child.span; let span = child.span;
let expansion = Mark::root(); // FIXME(jseyfried) intercrate hygiene let expansion = Mark::root(); // FIXME(jseyfried) intercrate hygiene
match def { match def {
@ -472,7 +472,7 @@ impl<'a> Resolver<'a> {
self.define(parent, ident, ValueNS, (def, vis, DUMMY_SP, expansion)); self.define(parent, ident, ValueNS, (def, vis, DUMMY_SP, expansion));
if let Some(struct_def_id) = if let Some(struct_def_id) =
self.session.cstore.def_key(def_id).parent self.cstore.def_key(def_id).parent
.map(|index| DefId { krate: def_id.krate, index: index }) { .map(|index| DefId { krate: def_id.krate, index: index }) {
self.struct_constructors.insert(struct_def_id, (def, vis)); self.struct_constructors.insert(struct_def_id, (def, vis));
} }
@ -486,12 +486,12 @@ impl<'a> Resolver<'a> {
span); span);
self.define(parent, ident, TypeNS, (module, vis, DUMMY_SP, expansion)); self.define(parent, ident, TypeNS, (module, vis, DUMMY_SP, expansion));
for child in self.session.cstore.item_children_untracked(def_id, self.session) { for child in self.cstore.item_children_untracked(def_id, self.session) {
let ns = if let Def::AssociatedTy(..) = child.def { TypeNS } else { ValueNS }; let ns = if let Def::AssociatedTy(..) = child.def { TypeNS } else { ValueNS };
self.define(module, child.ident, ns, self.define(module, child.ident, ns,
(child.def, ty::Visibility::Public, DUMMY_SP, expansion)); (child.def, ty::Visibility::Public, DUMMY_SP, expansion));
if self.session.cstore.associated_item_cloned_untracked(child.def.def_id()) if self.cstore.associated_item_cloned_untracked(child.def.def_id())
.method_has_self_argument { .method_has_self_argument {
self.has_self.insert(child.def.def_id()); self.has_self.insert(child.def.def_id());
} }
@ -502,7 +502,7 @@ impl<'a> Resolver<'a> {
self.define(parent, ident, TypeNS, (def, vis, DUMMY_SP, expansion)); self.define(parent, ident, TypeNS, (def, vis, DUMMY_SP, expansion));
// Record field names for error reporting. // Record field names for error reporting.
let field_names = self.session.cstore.struct_field_names_untracked(def_id); let field_names = self.cstore.struct_field_names_untracked(def_id);
self.insert_field_names(def_id, field_names); self.insert_field_names(def_id, field_names);
} }
Def::Macro(..) => { Def::Macro(..) => {
@ -517,15 +517,15 @@ impl<'a> Resolver<'a> {
return self.module_map[&def_id] return self.module_map[&def_id]
} }
let macros_only = self.session.cstore.dep_kind_untracked(def_id.krate).macros_only(); let macros_only = self.cstore.dep_kind_untracked(def_id.krate).macros_only();
if let Some(&module) = self.extern_module_map.get(&(def_id, macros_only)) { if let Some(&module) = self.extern_module_map.get(&(def_id, macros_only)) {
return module; return module;
} }
let (name, parent) = if def_id.index == CRATE_DEF_INDEX { let (name, parent) = if def_id.index == CRATE_DEF_INDEX {
(self.session.cstore.crate_name_untracked(def_id.krate).as_str(), None) (self.cstore.crate_name_untracked(def_id.krate).as_str(), None)
} else { } else {
let def_key = self.session.cstore.def_key(def_id); let def_key = self.cstore.def_key(def_id);
(def_key.disambiguated_data.data.get_opt_name().unwrap(), (def_key.disambiguated_data.data.get_opt_name().unwrap(),
Some(self.get_module(DefId { index: def_key.parent.unwrap(), ..def_id }))) Some(self.get_module(DefId { index: def_key.parent.unwrap(), ..def_id })))
}; };
@ -559,7 +559,7 @@ impl<'a> Resolver<'a> {
return ext.clone(); return ext.clone();
} }
let macro_def = match self.session.cstore.load_macro_untracked(def_id, &self.session) { let macro_def = match self.cstore.load_macro_untracked(def_id, &self.session) {
LoadedMacro::MacroDef(macro_def) => macro_def, LoadedMacro::MacroDef(macro_def) => macro_def,
LoadedMacro::ProcMacro(ext) => return ext, LoadedMacro::ProcMacro(ext) => return ext,
}; };
@ -576,7 +576,7 @@ impl<'a> Resolver<'a> {
pub fn populate_module_if_necessary(&mut self, module: Module<'a>) { pub fn populate_module_if_necessary(&mut self, module: Module<'a>) {
if module.populated.get() { return } if module.populated.get() { return }
let def_id = module.def_id().unwrap(); let def_id = module.def_id().unwrap();
for child in self.session.cstore.item_children_untracked(def_id, self.session) { for child in self.cstore.item_children_untracked(def_id, self.session) {
self.build_reduced_graph_for_external_crate_def(module, child); self.build_reduced_graph_for_external_crate_def(module, child);
} }
module.populated.set(true) module.populated.set(true)
@ -607,7 +607,7 @@ impl<'a> Resolver<'a> {
span_err!(self.session, item.span, E0468, span_err!(self.session, item.span, E0468,
"an `extern crate` loading macros must be at the crate root"); "an `extern crate` loading macros must be at the crate root");
} else if !self.use_extern_macros && !used && } else if !self.use_extern_macros && !used &&
self.session.cstore.dep_kind_untracked(module.def_id().unwrap().krate) self.cstore.dep_kind_untracked(module.def_id().unwrap().krate)
.macros_only() { .macros_only() {
let msg = "proc macro crates and `#[no_link]` crates have no effect without \ let msg = "proc macro crates and `#[no_link]` crates have no effect without \
`#[macro_use]`"; `#[macro_use]`";
@ -651,7 +651,7 @@ impl<'a> Resolver<'a> {
} }
} }
for (name, span) in legacy_imports.reexports { for (name, span) in legacy_imports.reexports {
self.session.cstore.export_macros_untracked(module.def_id().unwrap().krate); self.cstore.export_macros_untracked(module.def_id().unwrap().krate);
let ident = Ident::with_empty_ctxt(name); let ident = Ident::with_empty_ctxt(name);
let result = self.resolve_ident_in_module(module, ident, MacroNS, false, false, span); let result = self.resolve_ident_in_module(module, ident, MacroNS, false, false, span);
if let Ok(binding) = result { if let Ok(binding) = result {

View file

@ -31,7 +31,7 @@ use self::RibKind::*;
use rustc::hir::map::{Definitions, DefCollector}; use rustc::hir::map::{Definitions, DefCollector};
use rustc::hir::{self, PrimTy, TyBool, TyChar, TyFloat, TyInt, TyUint, TyStr}; use rustc::hir::{self, PrimTy, TyBool, TyChar, TyFloat, TyInt, TyUint, TyStr};
use rustc::middle::cstore::CrateLoader; use rustc::middle::cstore::{CrateStore, CrateLoader};
use rustc::session::Session; use rustc::session::Session;
use rustc::lint; use rustc::lint;
use rustc::hir::def::*; use rustc::hir::def::*;
@ -1176,6 +1176,7 @@ impl PrimitiveTypeTable {
/// The main resolver class. /// The main resolver class.
pub struct Resolver<'a> { pub struct Resolver<'a> {
session: &'a Session, session: &'a Session,
cstore: &'a CrateStore,
pub definitions: Definitions, pub definitions: Definitions,
@ -1343,7 +1344,7 @@ impl<'a, 'b: 'a> ty::DefIdTree for &'a Resolver<'b> {
fn parent(self, id: DefId) -> Option<DefId> { fn parent(self, id: DefId) -> Option<DefId> {
match id.krate { match id.krate {
LOCAL_CRATE => self.definitions.def_key(id.index).parent, LOCAL_CRATE => self.definitions.def_key(id.index).parent,
_ => self.session.cstore.def_key(id).parent, _ => self.cstore.def_key(id).parent,
}.map(|index| DefId { index: index, ..id }) }.map(|index| DefId { index: index, ..id })
} }
} }
@ -1383,6 +1384,7 @@ impl<'a> hir::lowering::Resolver for Resolver<'a> {
impl<'a> Resolver<'a> { impl<'a> Resolver<'a> {
pub fn new(session: &'a Session, pub fn new(session: &'a Session,
cstore: &'a CrateStore,
krate: &Crate, krate: &Crate,
crate_name: &str, crate_name: &str,
make_glob_map: MakeGlobMap, make_glob_map: MakeGlobMap,
@ -1414,6 +1416,8 @@ impl<'a> Resolver<'a> {
Resolver { Resolver {
session, session,
cstore,
definitions, definitions,
// The outermost module has def ID 0; this is not reflected in the // The outermost module has def ID 0; this is not reflected in the

View file

@ -778,7 +778,7 @@ impl<'a> Resolver<'a> {
_ => return, _ => return,
}; };
let crate_name = self.session.cstore.crate_name_untracked(krate); let crate_name = self.cstore.crate_name_untracked(krate);
self.session.struct_span_err(use_span, warn_msg) self.session.struct_span_err(use_span, warn_msg)
.help(&format!("instead, import the procedural macro like any other item: \ .help(&format!("instead, import the procedural macro like any other item: \

View file

@ -844,7 +844,7 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
let def = binding.def(); let def = binding.def();
if def != Def::Err { if def != Def::Err {
if !def.def_id().is_local() { if !def.def_id().is_local() {
self.session.cstore.export_macros_untracked(def.def_id().krate); self.cstore.export_macros_untracked(def.def_id().krate);
} }
if let Def::Macro(..) = def { if let Def::Macro(..) = def {
if let Some(&span) = exported_macro_names.get(&ident.modern()) { if let Some(&span) = exported_macro_names.get(&ident.modern()) {

View file

@ -185,7 +185,11 @@ pub fn link_binary(sess: &Session,
bug!("invalid output type `{:?}` for target os `{}`", bug!("invalid output type `{:?}` for target os `{}`",
crate_type, sess.opts.target_triple); crate_type, sess.opts.target_triple);
} }
let mut out_files = link_binary_output(sess, trans, crate_type, outputs, crate_name); let mut out_files = link_binary_output(sess,
trans,
crate_type,
outputs,
crate_name);
out_filenames.append(&mut out_files); out_filenames.append(&mut out_files);
} }
@ -346,8 +350,8 @@ fn link_binary_output(sess: &Session,
tmpdir.path()); tmpdir.path());
} }
_ => { _ => {
link_natively(sess, crate_type, &objects, &out_filename, trans, link_natively(sess, crate_type, &objects, &out_filename,
outputs, tmpdir.path()); trans, outputs, tmpdir.path());
} }
} }
out_filenames.push(out_filename); out_filenames.push(out_filename);

View file

@ -777,16 +777,13 @@ fn write_metadata<'a, 'gcx>(tcx: TyCtxt<'a, 'gcx, 'gcx>,
EncodedMetadataHashes::new()); EncodedMetadataHashes::new());
} }
let cstore = &tcx.sess.cstore; let (metadata, hashes) = tcx.encode_metadata(link_meta, exported_symbols);
let (metadata, hashes) = cstore.encode_metadata(tcx,
&link_meta,
exported_symbols);
if kind == MetadataKind::Uncompressed { if kind == MetadataKind::Uncompressed {
return (metadata_llcx, metadata_llmod, metadata, hashes); return (metadata_llcx, metadata_llmod, metadata, hashes);
} }
assert!(kind == MetadataKind::Compressed); 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) DeflateEncoder::new(&mut compressed, Compression::Fast)
.write_all(&metadata.raw_data).unwrap(); .write_all(&metadata.raw_data).unwrap();

View file

@ -26,6 +26,7 @@ fn main() {
.file("../rt/hoedown/src/version.c") .file("../rt/hoedown/src/version.c")
.warnings(false) .warnings(false)
.include(src_dir) .include(src_dir)
.warnings(false)
.compile("libhoedown.a"); .compile("libhoedown.a");
} }

View file

@ -148,7 +148,7 @@ pub fn run_core(search_paths: SearchPaths,
let _ignore = dep_graph.in_ignore(); let _ignore = dep_graph.in_ignore();
let cstore = Rc::new(CStore::new(box rustc_trans::LlvmMetadataLoader)); let cstore = Rc::new(CStore::new(box rustc_trans::LlvmMetadataLoader));
let mut sess = session::build_session_( let mut sess = session::build_session_(
sessopts, &dep_graph, cpath, diagnostic_handler, codemap, cstore.clone() sessopts, &dep_graph, cpath, diagnostic_handler, codemap
); );
rustc_trans::init(&sess); rustc_trans::init(&sess);
rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess)); rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess));
@ -181,6 +181,7 @@ pub fn run_core(search_paths: SearchPaths,
let hir_map = hir_map::map_crate(&mut hir_forest, defs); let hir_map = hir_map::map_crate(&mut hir_forest, defs);
abort_on_err(driver::phase_3_run_analysis_passes(&sess, abort_on_err(driver::phase_3_run_analysis_passes(&sess,
&*cstore,
hir_map, hir_map,
analysis, analysis,
resolutions, resolutions,
@ -214,7 +215,7 @@ pub fn run_core(search_paths: SearchPaths,
debug!("crate: {:?}", tcx.hir.krate()); debug!("crate: {:?}", tcx.hir.krate());
let krate = { let krate = {
let mut v = RustdocVisitor::new(&ctxt); let mut v = RustdocVisitor::new(&*cstore, &ctxt);
v.visit(tcx.hir.krate()); v.visit(tcx.hir.krate());
v.clean(&ctxt) v.clean(&ctxt)
}; };

View file

@ -87,7 +87,7 @@ pub fn run(input: &str,
let _ignore = dep_graph.in_ignore(); let _ignore = dep_graph.in_ignore();
let cstore = Rc::new(CStore::new(box rustc_trans::LlvmMetadataLoader)); let cstore = Rc::new(CStore::new(box rustc_trans::LlvmMetadataLoader));
let mut sess = session::build_session_( let mut sess = session::build_session_(
sessopts, &dep_graph, Some(input_path.clone()), handler, codemap.clone(), cstore.clone(), sessopts, &dep_graph, Some(input_path.clone()), handler, codemap.clone()
); );
rustc_trans::init(&sess); rustc_trans::init(&sess);
rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess)); rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess));
@ -240,7 +240,7 @@ fn run_test(test: &str, cratename: &str, filename: &str, cfgs: Vec<String>, libs
let dep_graph = DepGraph::new(false); let dep_graph = DepGraph::new(false);
let cstore = Rc::new(CStore::new(box rustc_trans::LlvmMetadataLoader)); let cstore = Rc::new(CStore::new(box rustc_trans::LlvmMetadataLoader));
let mut sess = session::build_session_( let mut sess = session::build_session_(
sessopts, &dep_graph, None, diagnostic_handler, codemap, cstore.clone(), sessopts, &dep_graph, None, diagnostic_handler, codemap
); );
rustc_trans::init(&sess); rustc_trans::init(&sess);
rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess)); rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess));

View file

@ -21,7 +21,7 @@ use syntax_pos::Span;
use rustc::hir::map as hir_map; use rustc::hir::map as hir_map;
use rustc::hir::def::Def; use rustc::hir::def::Def;
use rustc::hir::def_id::{DefId, LOCAL_CRATE}; 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::middle::privacy::AccessLevel;
use rustc::util::nodemap::FxHashSet; use rustc::util::nodemap::FxHashSet;
@ -40,6 +40,7 @@ use doctree::*;
// framework from syntax? // framework from syntax?
pub struct RustdocVisitor<'a, 'tcx: 'a> { pub struct RustdocVisitor<'a, 'tcx: 'a> {
cstore: &'tcx CrateStore,
pub module: Module, pub module: Module,
pub attrs: hir::HirVec<ast::Attribute>, pub attrs: hir::HirVec<ast::Attribute>,
pub cx: &'a core::DocContext<'a, 'tcx>, pub cx: &'a core::DocContext<'a, 'tcx>,
@ -51,7 +52,8 @@ pub struct RustdocVisitor<'a, 'tcx: 'a> {
} }
impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> { 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. // If the root is reexported, terminate all recursion.
let mut stack = FxHashSet(); let mut stack = FxHashSet();
stack.insert(ast::CRATE_NODE_ID); stack.insert(ast::CRATE_NODE_ID);
@ -63,6 +65,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
inlining: false, inlining: false,
inside_public_path: true, inside_public_path: true,
reexported_macros: FxHashSet(), reexported_macros: FxHashSet(),
cstore,
} }
} }
@ -208,8 +211,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
} }
let imported_from = self.cx.tcx.original_crate_name(def_id.krate); let imported_from = self.cx.tcx.original_crate_name(def_id.krate);
let cstore = &self.cx.sess().cstore; let def = match self.cstore.load_macro_untracked(def_id, self.cx.sess()) {
let def = match cstore.load_macro_untracked(def_id, self.cx.sess()) {
LoadedMacro::MacroDef(macro_def) => macro_def, LoadedMacro::MacroDef(macro_def) => macro_def,
// FIXME(jseyfried): document proc macro reexports // FIXME(jseyfried): document proc macro reexports
LoadedMacro::ProcMacro(..) => continue, LoadedMacro::ProcMacro(..) => continue,

View file

@ -60,7 +60,7 @@ fn basic_sess(sysroot: PathBuf) -> (Session, Rc<CStore>) {
let descriptions = Registry::new(&rustc::DIAGNOSTICS); let descriptions = Registry::new(&rustc::DIAGNOSTICS);
let dep_graph = DepGraph::new(opts.build_dep_graph()); let dep_graph = DepGraph::new(opts.build_dep_graph());
let cstore = Rc::new(CStore::new(Box::new(rustc_trans::LlvmMetadataLoader))); let cstore = Rc::new(CStore::new(Box::new(rustc_trans::LlvmMetadataLoader)));
let sess = build_session(opts, &dep_graph, None, descriptions, cstore.clone()); let sess = build_session(opts, &dep_graph, None, descriptions);
rustc_trans::init(&sess); rustc_trans::init(&sess);
rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess)); rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess));
(sess, cstore) (sess, cstore)

View file

@ -21,6 +21,7 @@ extern crate rustc_driver;
extern crate syntax; extern crate syntax;
extern crate rustc_errors as errors; extern crate rustc_errors as errors;
use rustc::middle::cstore::CrateStore;
use rustc::session::Session; use rustc::session::Session;
use rustc::session::config::{self, Input}; use rustc::session::config::{self, Input};
use rustc_driver::{driver, CompilerCalls, Compilation}; use rustc_driver::{driver, CompilerCalls, Compilation};
@ -47,6 +48,7 @@ impl<'a> CompilerCalls<'a> for TestCalls {
fn late_callback(&mut self, fn late_callback(&mut self,
_: &getopts::Matches, _: &getopts::Matches,
_: &Session, _: &Session,
_: &CrateStore,
_: &Input, _: &Input,
_: &Option<PathBuf>, _: &Option<PathBuf>,
_: &Option<PathBuf>) _: &Option<PathBuf>)

@ -1 +1 @@
Subproject commit 303671ea8103cbc39575a1f47a204159546a04d0 Subproject commit 8dd70945fb049df3f9dc7685cdc58d94e05e8ffc