Auto merge of #44418 - alexcrichton:remove-dep-graph, r=michaelwoerister

rustc: Remove `DepGraph` handling from rustc_metadata

This should now be entirely tracked through queries, so no need to have a
`DepGraph` in the `CStore` object any more!

cc #44390
This commit is contained in:
bors 2017-09-10 07:33:46 +00:00
commit 34035d23ff
11 changed files with 102 additions and 245 deletions

View File

@ -294,7 +294,7 @@ pub fn run_compiler<'a>(args: &[String],
};
let dep_graph = DepGraph::new(sopts.build_dep_graph());
let cstore = Rc::new(CStore::new(&dep_graph, box ::MetadataLoader));
let cstore = Rc::new(CStore::new(box ::MetadataLoader));
let loader = file_loader.unwrap_or(box RealFileLoader);
let codemap = Rc::new(CodeMap::with_file_loader(loader, sopts.file_path_mapping()));
@ -574,7 +574,7 @@ impl<'a> CompilerCalls<'a> for RustcDefaultCalls {
return None;
}
let dep_graph = DepGraph::new(sopts.build_dep_graph());
let cstore = Rc::new(CStore::new(&dep_graph, box ::MetadataLoader));
let cstore = Rc::new(CStore::new(box ::MetadataLoader));
let mut sess = build_session(sopts.clone(),
&dep_graph,
None,

View File

@ -104,7 +104,7 @@ fn test_env<F>(source_string: &str,
let dep_graph = DepGraph::new(false);
let _ignore = dep_graph.in_ignore();
let cstore = Rc::new(CStore::new(&dep_graph, box ::MetadataLoader));
let cstore = Rc::new(CStore::new(box ::MetadataLoader));
let sess = session::build_session_(options,
&dep_graph,
None,

View File

@ -13,7 +13,7 @@
use cstore::{self, CStore, CrateSource, MetadataBlob};
use locator::{self, CratePaths};
use native_libs::relevant_lib;
use schema::{CrateRoot, Tracked};
use schema::CrateRoot;
use rustc::hir::def_id::{CrateNum, DefIndex};
use rustc::hir::svh::Svh;
@ -261,16 +261,13 @@ impl<'a> CrateLoader<'a> {
crate_root.def_path_table.decode(&metadata)
});
let exported_symbols = crate_root.exported_symbols
.map(|x| x.decode(&metadata).collect());
let exported_symbols = crate_root.exported_symbols.decode(&metadata).collect();
let trait_impls = crate_root
.impls
.map(|impls| {
impls.decode(&metadata)
.map(|trait_impls| (trait_impls.trait_id, trait_impls.impls))
.collect()
});
.decode(&metadata)
.map(|trait_impls| (trait_impls.trait_id, trait_impls.impls))
.collect();
let mut cmeta = cstore::CrateMetadata {
name,
@ -295,23 +292,17 @@ impl<'a> CrateLoader<'a> {
},
// Initialize this with an empty set. The field is populated below
// after we were able to deserialize its contents.
dllimport_foreign_items: Tracked::new(FxHashSet()),
dllimport_foreign_items: FxHashSet(),
};
let dllimports: Tracked<FxHashSet<_>> = cmeta
let dllimports: FxHashSet<_> = cmeta
.root
.native_libraries
.map(|native_libraries| {
let native_libraries: Vec<_> = native_libraries.decode(&cmeta)
.collect();
native_libraries
.iter()
.filter(|lib| relevant_lib(self.sess, lib) &&
lib.kind == cstore::NativeLibraryKind::NativeUnknown)
.flat_map(|lib| lib.foreign_items.iter())
.map(|id| *id)
.collect()
});
.decode(&cmeta)
.filter(|lib| relevant_lib(self.sess, lib) &&
lib.kind == cstore::NativeLibraryKind::NativeUnknown)
.flat_map(|lib| lib.foreign_items.into_iter())
.collect();
cmeta.dllimport_foreign_items = dllimports;
@ -469,7 +460,6 @@ impl<'a> CrateLoader<'a> {
// We map 0 and all other holes in the map to our parent crate. The "additional"
// self-dependencies should be harmless.
::std::iter::once(krate).chain(crate_root.crate_deps
.get_untracked()
.decode(metadata)
.map(|dep| {
debug!("resolving dep crate {} hash: `{}`", dep.name, dep.hash);
@ -692,16 +682,14 @@ impl<'a> CrateLoader<'a> {
let mut needs_panic_runtime = attr::contains_name(&krate.attrs,
"needs_panic_runtime");
let dep_graph = &self.sess.dep_graph;
self.cstore.iter_crate_data(|cnum, data| {
needs_panic_runtime = needs_panic_runtime ||
data.needs_panic_runtime(dep_graph);
if data.is_panic_runtime(dep_graph) {
data.needs_panic_runtime();
if data.is_panic_runtime() {
// Inject a dependency from all #![needs_panic_runtime] to this
// #![panic_runtime] crate.
self.inject_dependency_if(cnum, "a panic runtime",
&|data| data.needs_panic_runtime(dep_graph));
&|data| data.needs_panic_runtime());
runtime_found = runtime_found || data.dep_kind.get() == DepKind::Explicit;
}
});
@ -737,11 +725,11 @@ impl<'a> CrateLoader<'a> {
// Sanity check the loaded crate to ensure it is indeed a panic runtime
// and the panic strategy is indeed what we thought it was.
if !data.is_panic_runtime(dep_graph) {
if !data.is_panic_runtime() {
self.sess.err(&format!("the crate `{}` is not a panic runtime",
name));
}
if data.panic_strategy(dep_graph) != desired_strategy {
if data.panic_strategy() != desired_strategy {
self.sess.err(&format!("the crate `{}` does not have the panic \
strategy `{}`",
name, desired_strategy.desc()));
@ -749,7 +737,7 @@ impl<'a> CrateLoader<'a> {
self.sess.injected_panic_runtime.set(Some(cnum));
self.inject_dependency_if(cnum, "a panic runtime",
&|data| data.needs_panic_runtime(dep_graph));
&|data| data.needs_panic_runtime());
}
fn inject_sanitizer_runtime(&mut self) {
@ -844,7 +832,7 @@ impl<'a> CrateLoader<'a> {
PathKind::Crate, dep_kind);
// Sanity check the loaded crate to ensure it is indeed a sanitizer runtime
if !data.is_sanitizer_runtime(&self.sess.dep_graph) {
if !data.is_sanitizer_runtime() {
self.sess.err(&format!("the crate `{}` is not a sanitizer runtime",
name));
}
@ -865,7 +853,7 @@ impl<'a> CrateLoader<'a> {
PathKind::Crate, dep_kind);
// Sanity check the loaded crate to ensure it is indeed a profiler runtime
if !data.is_profiler_runtime(&self.sess.dep_graph) {
if !data.is_profiler_runtime() {
self.sess.err(&format!("the crate `profiler_builtins` is not \
a profiler runtime"));
}
@ -883,9 +871,8 @@ impl<'a> CrateLoader<'a> {
// written down in liballoc.
let mut needs_allocator = attr::contains_name(&krate.attrs,
"needs_allocator");
let dep_graph = &self.sess.dep_graph;
self.cstore.iter_crate_data(|_, data| {
needs_allocator = needs_allocator || data.needs_allocator(dep_graph);
needs_allocator = needs_allocator || data.needs_allocator();
});
if !needs_allocator {
return
@ -917,14 +904,13 @@ impl<'a> CrateLoader<'a> {
// First up we check for global allocators. Look at the crate graph here
// and see what's a global allocator, including if we ourselves are a
// global allocator.
let dep_graph = &self.sess.dep_graph;
let mut global_allocator = if has_global_allocator {
Some(None)
} else {
None
};
self.cstore.iter_crate_data(|_, data| {
if !data.has_global_allocator(dep_graph) {
if !data.has_global_allocator() {
return
}
match global_allocator {
@ -983,12 +969,6 @@ impl<'a> CrateLoader<'a> {
DUMMY_SP,
PathKind::Crate, dep_kind);
self.sess.injected_allocator.set(Some(cnum));
// self.cstore.iter_crate_data(|_, data| {
// if !data.needs_allocator(dep_graph) {
// return
// }
// data.cnum_map.borrow_mut().push(cnum);
// });
}
// We're not actually going to inject an allocator, we're going to
@ -1001,7 +981,7 @@ impl<'a> CrateLoader<'a> {
attr::contains_name(&krate.attrs, "default_lib_allocator");
self.cstore.iter_crate_data(|_, data| {
if !found_lib_allocator {
if data.has_default_lib_allocator(dep_graph) {
if data.has_default_lib_allocator() {
found_lib_allocator = true;
}
}

View File

@ -11,11 +11,10 @@
// The crate store - a central repo for information collected about external
// crates and libraries
use schema::{self, Tracked};
use schema;
use rustc::dep_graph::DepGraph;
use rustc::hir::def_id::{CRATE_DEF_INDEX, CrateNum, DefIndex, DefId};
use rustc::hir::map::definitions::{DefPathTable, GlobalMetaDataKind};
use rustc::hir::def_id::{CRATE_DEF_INDEX, CrateNum, DefIndex};
use rustc::hir::map::definitions::DefPathTable;
use rustc::hir::svh::Svh;
use rustc::middle::cstore::{DepKind, ExternCrate, MetadataLoader};
use rustc_back::PanicStrategy;
@ -78,20 +77,19 @@ pub struct CrateMetadata {
/// compilation support.
pub def_path_table: Rc<DefPathTable>,
pub exported_symbols: Tracked<FxHashSet<DefIndex>>,
pub exported_symbols: FxHashSet<DefIndex>,
pub trait_impls: Tracked<FxHashMap<(u32, DefIndex), schema::LazySeq<DefIndex>>>,
pub trait_impls: FxHashMap<(u32, DefIndex), schema::LazySeq<DefIndex>>,
pub dep_kind: Cell<DepKind>,
pub source: CrateSource,
pub proc_macros: Option<Vec<(ast::Name, Rc<SyntaxExtension>)>>,
// Foreign items imported from a dylib (Windows only)
pub dllimport_foreign_items: Tracked<FxHashSet<DefIndex>>,
pub dllimport_foreign_items: FxHashSet<DefIndex>,
}
pub struct CStore {
pub dep_graph: DepGraph,
metas: RefCell<FxHashMap<CrateNum, Rc<CrateMetadata>>>,
/// Map from NodeId's of local extern crate statements to crate numbers
extern_mod_crate_map: RefCell<NodeMap<CrateNum>>,
@ -99,9 +97,8 @@ pub struct CStore {
}
impl CStore {
pub fn new(dep_graph: &DepGraph, metadata_loader: Box<MetadataLoader>) -> CStore {
pub fn new(metadata_loader: Box<MetadataLoader>) -> CStore {
CStore {
dep_graph: dep_graph.clone(),
metas: RefCell::new(FxHashMap()),
extern_mod_crate_map: RefCell::new(FxHashMap()),
metadata_loader,
@ -165,13 +162,6 @@ impl CStore {
pub fn do_extern_mod_stmt_cnum(&self, emod_id: ast::NodeId) -> Option<CrateNum> {
self.extern_mod_crate_map.borrow().get(&emod_id).cloned()
}
pub fn read_dep_node(&self, def_id: DefId) {
use rustc::middle::cstore::CrateStore;
let def_path_hash = self.def_path_hash(def_id);
let dep_node = def_path_hash.to_dep_node(::rustc::dep_graph::DepKind::MetaData);
self.dep_graph.read(dep_node);
}
}
impl CrateMetadata {
@ -185,62 +175,50 @@ impl CrateMetadata {
self.root.disambiguator
}
pub fn needs_allocator(&self, dep_graph: &DepGraph) -> bool {
let attrs = self.get_item_attrs(CRATE_DEF_INDEX, dep_graph);
pub fn needs_allocator(&self) -> bool {
let attrs = self.get_item_attrs(CRATE_DEF_INDEX);
attr::contains_name(&attrs, "needs_allocator")
}
pub fn has_global_allocator(&self, dep_graph: &DepGraph) -> bool {
let dep_node = self.metadata_dep_node(GlobalMetaDataKind::Krate);
self.root
.has_global_allocator
.get(dep_graph, dep_node)
.clone()
pub fn has_global_allocator(&self) -> bool {
self.root.has_global_allocator.clone()
}
pub fn has_default_lib_allocator(&self, dep_graph: &DepGraph) -> bool {
let dep_node = self.metadata_dep_node(GlobalMetaDataKind::Krate);
self.root
.has_default_lib_allocator
.get(dep_graph, dep_node)
.clone()
pub fn has_default_lib_allocator(&self) -> bool {
self.root.has_default_lib_allocator.clone()
}
pub fn is_panic_runtime(&self, dep_graph: &DepGraph) -> bool {
let attrs = self.get_item_attrs(CRATE_DEF_INDEX, dep_graph);
pub fn is_panic_runtime(&self) -> bool {
let attrs = self.get_item_attrs(CRATE_DEF_INDEX);
attr::contains_name(&attrs, "panic_runtime")
}
pub fn needs_panic_runtime(&self, dep_graph: &DepGraph) -> bool {
let attrs = self.get_item_attrs(CRATE_DEF_INDEX, dep_graph);
pub fn needs_panic_runtime(&self) -> bool {
let attrs = self.get_item_attrs(CRATE_DEF_INDEX);
attr::contains_name(&attrs, "needs_panic_runtime")
}
pub fn is_compiler_builtins(&self, dep_graph: &DepGraph) -> bool {
let attrs = self.get_item_attrs(CRATE_DEF_INDEX, dep_graph);
pub fn is_compiler_builtins(&self) -> bool {
let attrs = self.get_item_attrs(CRATE_DEF_INDEX);
attr::contains_name(&attrs, "compiler_builtins")
}
pub fn is_sanitizer_runtime(&self, dep_graph: &DepGraph) -> bool {
let attrs = self.get_item_attrs(CRATE_DEF_INDEX, dep_graph);
pub fn is_sanitizer_runtime(&self) -> bool {
let attrs = self.get_item_attrs(CRATE_DEF_INDEX);
attr::contains_name(&attrs, "sanitizer_runtime")
}
pub fn is_profiler_runtime(&self, dep_graph: &DepGraph) -> bool {
let attrs = self.get_item_attrs(CRATE_DEF_INDEX, dep_graph);
pub fn is_profiler_runtime(&self) -> bool {
let attrs = self.get_item_attrs(CRATE_DEF_INDEX);
attr::contains_name(&attrs, "profiler_runtime")
}
pub fn is_no_builtins(&self, dep_graph: &DepGraph) -> bool {
let attrs = self.get_item_attrs(CRATE_DEF_INDEX, dep_graph);
pub fn is_no_builtins(&self) -> bool {
let attrs = self.get_item_attrs(CRATE_DEF_INDEX);
attr::contains_name(&attrs, "no_builtins")
}
pub fn panic_strategy(&self, dep_graph: &DepGraph) -> PanicStrategy {
let dep_node = self.metadata_dep_node(GlobalMetaDataKind::Krate);
self.root
.panic_strategy
.get(dep_graph, dep_node)
.clone()
pub fn panic_strategy(&self) -> PanicStrategy {
self.root.panic_strategy.clone()
}
}

View File

@ -27,7 +27,7 @@ use rustc::ty::maps::Providers;
use rustc::hir::def_id::{CrateNum, DefId, LOCAL_CRATE, CRATE_DEF_INDEX};
use rustc::hir::map::{DefKey, DefPath, DefPathHash};
use rustc::hir::map::blocks::FnLikeNode;
use rustc::hir::map::definitions::{DefPathTable, GlobalMetaDataKind};
use rustc::hir::map::definitions::DefPathTable;
use rustc::util::nodemap::{NodeSet, DefIdMap};
use std::any::Any;
@ -148,7 +148,7 @@ provide! { <'tcx> tcx, def_id, other, cdata,
lookup_deprecation_entry => {
cdata.get_deprecation(def_id.index).map(DeprecationEntry::external)
}
item_attrs => { cdata.get_item_attrs(def_id.index, &tcx.dep_graph) }
item_attrs => { cdata.get_item_attrs(def_id.index) }
// FIXME(#38501) We've skipped a `read` on the `HirBody` of
// a `fn` when encoding, so the dep-tracking wouldn't work.
// This is only used by rustdoc anyway, which shouldn't have
@ -157,8 +157,7 @@ provide! { <'tcx> tcx, def_id, other, cdata,
impl_parent => { cdata.get_parent_impl(def_id.index) }
trait_of_item => { cdata.get_trait_of_item(def_id.index) }
is_exported_symbol => {
let dep_node = cdata.metadata_dep_node(GlobalMetaDataKind::ExportedSymbols);
cdata.exported_symbols.get(&tcx.dep_graph, dep_node).contains(&def_id.index)
cdata.exported_symbols.contains(&def_id.index)
}
item_body_nested_bodies => { Rc::new(cdata.item_body_nested_bodies(def_id.index)) }
const_is_rvalue_promotable_to_static => {
@ -166,18 +165,18 @@ provide! { <'tcx> tcx, def_id, other, cdata,
}
is_mir_available => { cdata.is_item_mir_available(def_id.index) }
dylib_dependency_formats => { Rc::new(cdata.get_dylib_dependency_formats(&tcx.dep_graph)) }
is_panic_runtime => { cdata.is_panic_runtime(&tcx.dep_graph) }
is_compiler_builtins => { cdata.is_compiler_builtins(&tcx.dep_graph) }
has_global_allocator => { cdata.has_global_allocator(&tcx.dep_graph) }
is_sanitizer_runtime => { cdata.is_sanitizer_runtime(&tcx.dep_graph) }
is_profiler_runtime => { cdata.is_profiler_runtime(&tcx.dep_graph) }
panic_strategy => { cdata.panic_strategy(&tcx.dep_graph) }
dylib_dependency_formats => { Rc::new(cdata.get_dylib_dependency_formats()) }
is_panic_runtime => { cdata.is_panic_runtime() }
is_compiler_builtins => { cdata.is_compiler_builtins() }
has_global_allocator => { cdata.has_global_allocator() }
is_sanitizer_runtime => { cdata.is_sanitizer_runtime() }
is_profiler_runtime => { cdata.is_profiler_runtime() }
panic_strategy => { cdata.panic_strategy() }
extern_crate => { Rc::new(cdata.extern_crate.get()) }
is_no_builtins => { cdata.is_no_builtins(&tcx.dep_graph) }
is_no_builtins => { cdata.is_no_builtins() }
impl_defaultness => { cdata.get_impl_defaultness(def_id.index) }
exported_symbols => { Rc::new(cdata.get_exported_symbols(&tcx.dep_graph)) }
native_libraries => { Rc::new(cdata.get_native_libraries(&tcx.dep_graph)) }
exported_symbols => { Rc::new(cdata.get_exported_symbols()) }
native_libraries => { Rc::new(cdata.get_native_libraries()) }
plugin_registrar_fn => {
cdata.root.plugin_registrar_fn.map(|index| {
DefId { krate: def_id.krate, index }
@ -195,18 +194,18 @@ provide! { <'tcx> tcx, def_id, other, cdata,
implementations_of_trait => {
let mut result = vec![];
let filter = Some(other);
cdata.get_implementations_for_trait(filter, &tcx.dep_graph, &mut result);
cdata.get_implementations_for_trait(filter, &mut result);
Rc::new(result)
}
all_trait_implementations => {
let mut result = vec![];
cdata.get_implementations_for_trait(None, &tcx.dep_graph, &mut result);
cdata.get_implementations_for_trait(None, &mut result);
Rc::new(result)
}
is_dllimport_foreign_item => {
cdata.is_dllimport_foreign_item(def_id.index, &tcx.dep_graph)
cdata.is_dllimport_foreign_item(def_id.index)
}
visibility => { cdata.get_visibility(def_id.index) }
dep_kind => { cdata.dep_kind.get() }
@ -216,8 +215,8 @@ provide! { <'tcx> tcx, def_id, other, cdata,
cdata.each_child_of_item(def_id.index, |child| result.push(child), tcx.sess);
Rc::new(result)
}
defined_lang_items => { Rc::new(cdata.get_lang_items(&tcx.dep_graph)) }
missing_lang_items => { Rc::new(cdata.get_missing_lang_items(&tcx.dep_graph)) }
defined_lang_items => { Rc::new(cdata.get_lang_items()) }
missing_lang_items => { Rc::new(cdata.get_missing_lang_items()) }
extern_const_body => {
debug!("item_body({:?}): inlining item", def_id);
@ -362,34 +361,25 @@ impl CrateStore for cstore::CStore {
}
fn visibility_untracked(&self, def: DefId) -> ty::Visibility {
self.read_dep_node(def);
self.get_crate_data(def.krate).get_visibility(def.index)
}
fn item_generics_cloned_untracked(&self, def: DefId) -> ty::Generics {
self.read_dep_node(def);
self.get_crate_data(def.krate).get_generics(def.index)
}
fn associated_item_cloned_untracked(&self, def: DefId) -> ty::AssociatedItem
{
self.read_dep_node(def);
self.get_crate_data(def.krate).get_associated_item(def.index)
}
fn dep_kind_untracked(&self, cnum: CrateNum) -> DepKind
{
let data = self.get_crate_data(cnum);
let dep_node = data.metadata_dep_node(GlobalMetaDataKind::CrateDeps);
self.dep_graph.read(dep_node);
data.dep_kind.get()
self.get_crate_data(cnum).dep_kind.get()
}
fn export_macros_untracked(&self, cnum: CrateNum) {
let data = self.get_crate_data(cnum);
let dep_node = data.metadata_dep_node(GlobalMetaDataKind::CrateDeps);
self.dep_graph.read(dep_node);
if data.dep_kind.get() == DepKind::UnexportedMacrosOnly {
data.dep_kind.set(DepKind::MacrosOnly)
}
@ -431,13 +421,11 @@ impl CrateStore for cstore::CStore {
fn struct_field_names_untracked(&self, def: DefId) -> Vec<ast::Name>
{
self.read_dep_node(def);
self.get_crate_data(def.krate).get_struct_field_names(def.index)
}
fn item_children_untracked(&self, def_id: DefId, sess: &Session) -> Vec<def::Export>
{
self.read_dep_node(def_id);
let mut result = vec![];
self.get_crate_data(def_id.krate)
.each_child_of_item(def_id.index, |child| result.push(child), sess);
@ -462,7 +450,7 @@ impl CrateStore for cstore::CStore {
let body = filemap_to_stream(&sess.parse_sess, filemap, None);
// Mark the attrs as used
let attrs = data.get_item_attrs(id.index, &self.dep_graph);
let attrs = data.get_item_attrs(id.index);
for attr in attrs.iter() {
attr::mark_used(attr);
}

View File

@ -13,9 +13,7 @@
use cstore::{self, CrateMetadata, MetadataBlob, NativeLibrary};
use schema::*;
use rustc::dep_graph::{DepGraph, DepNode, DepKind};
use rustc::hir::map::{DefKey, DefPath, DefPathData, DefPathHash};
use rustc::hir::map::definitions::GlobalMetaDataKind;
use rustc::hir;
use rustc::middle::cstore::LinkagePreference;
@ -402,7 +400,6 @@ impl<'a, 'tcx> MetadataBlob {
write!(out, "=External Dependencies=\n")?;
let root = self.get_root();
for (i, dep) in root.crate_deps
.get_untracked()
.decode(self)
.enumerate() {
write!(out, "{} {}-{}\n", i + 1, dep.name, dep.hash)?;
@ -646,11 +643,9 @@ impl<'a, 'tcx> CrateMetadata {
}
/// Iterates over the language items in the given crate.
pub fn get_lang_items(&self, dep_graph: &DepGraph) -> Vec<(DefIndex, usize)> {
let dep_node = self.metadata_dep_node(GlobalMetaDataKind::LangItems);
pub fn get_lang_items(&self) -> Vec<(DefIndex, usize)> {
self.root
.lang_items
.get(dep_graph, dep_node)
.decode(self)
.collect()
}
@ -869,18 +864,13 @@ impl<'a, 'tcx> CrateMetadata {
}
}
pub fn get_item_attrs(&self,
node_id: DefIndex,
dep_graph: &DepGraph) -> Rc<[ast::Attribute]> {
pub fn get_item_attrs(&self, node_id: DefIndex) -> Rc<[ast::Attribute]> {
let (node_as, node_index) =
(node_id.address_space().index(), node_id.as_array_index());
if self.is_proc_macro(node_id) {
return Rc::new([]);
}
let dep_node = self.def_path_hash(node_id).to_dep_node(DepKind::MetaData);
dep_graph.read(dep_node);
if let Some(&Some(ref val)) =
self.attribute_cache.borrow()[node_as].get(node_index) {
return val.clone();
@ -947,7 +937,6 @@ impl<'a, 'tcx> CrateMetadata {
pub fn get_implementations_for_trait(&self,
filter: Option<DefId>,
dep_graph: &DepGraph,
result: &mut Vec<DefId>) {
// Do a reverse lookup beforehand to avoid touching the crate_num
// hash map in the loop below.
@ -958,16 +947,13 @@ impl<'a, 'tcx> CrateMetadata {
None => None,
};
let dep_node = self.metadata_dep_node(GlobalMetaDataKind::Impls);
if let Some(filter) = filter {
if let Some(impls) = self.trait_impls
.get(dep_graph, dep_node)
.get(&filter) {
result.extend(impls.decode(self).map(|idx| self.local_def_id(idx)));
}
} else {
for impls in self.trait_impls.get(dep_graph, dep_node).values() {
for impls in self.trait_impls.values() {
result.extend(impls.decode(self).map(|idx| self.local_def_id(idx)));
}
}
@ -983,25 +969,13 @@ impl<'a, 'tcx> CrateMetadata {
}
pub fn get_native_libraries(&self,
dep_graph: &DepGraph)
-> Vec<NativeLibrary> {
let dep_node = self.metadata_dep_node(GlobalMetaDataKind::NativeLibraries);
self.root
.native_libraries
.get(dep_graph, dep_node)
.decode(self)
.collect()
pub fn get_native_libraries(&self) -> Vec<NativeLibrary> {
self.root.native_libraries.decode(self).collect()
}
pub fn get_dylib_dependency_formats(&self,
dep_graph: &DepGraph)
-> Vec<(CrateNum, LinkagePreference)> {
let dep_node =
self.metadata_dep_node(GlobalMetaDataKind::DylibDependencyFormats);
pub fn get_dylib_dependency_formats(&self) -> Vec<(CrateNum, LinkagePreference)> {
self.root
.dylib_dependency_formats
.get(dep_graph, dep_node)
.decode(self)
.enumerate()
.flat_map(|(i, link)| {
@ -1011,11 +985,9 @@ impl<'a, 'tcx> CrateMetadata {
.collect()
}
pub fn get_missing_lang_items(&self, dep_graph: &DepGraph) -> Vec<lang_items::LangItem> {
let dep_node = self.metadata_dep_node(GlobalMetaDataKind::LangItemsMissing);
pub fn get_missing_lang_items(&self) -> Vec<lang_items::LangItem> {
self.root
.lang_items_missing
.get(dep_graph, dep_node)
.decode(self)
.collect()
}
@ -1030,10 +1002,8 @@ impl<'a, 'tcx> CrateMetadata {
arg_names.decode(self).collect()
}
pub fn get_exported_symbols(&self, dep_graph: &DepGraph) -> Vec<DefId> {
let dep_node = self.metadata_dep_node(GlobalMetaDataKind::ExportedSymbols);
pub fn get_exported_symbols(&self) -> Vec<DefId> {
self.exported_symbols
.get(dep_graph, dep_node)
.iter()
.map(|&index| self.local_def_id(index))
.collect()
@ -1065,11 +1035,8 @@ impl<'a, 'tcx> CrateMetadata {
}
}
pub fn is_dllimport_foreign_item(&self, id: DefIndex, dep_graph: &DepGraph) -> bool {
let dep_node = self.metadata_dep_node(GlobalMetaDataKind::NativeLibraries);
self.dllimport_foreign_items
.get(dep_graph, dep_node)
.contains(&id)
pub fn is_dllimport_foreign_item(&self, id: DefIndex) -> bool {
self.dllimport_foreign_items.contains(&id)
}
pub fn is_default_impl(&self, impl_id: DefIndex) -> bool {
@ -1221,10 +1188,4 @@ impl<'a, 'tcx> CrateMetadata {
*self.codemap_import_info.borrow_mut() = imported_filemaps;
self.codemap_import_info.borrow()
}
pub fn metadata_dep_node(&self, kind: GlobalMetaDataKind) -> DepNode {
let def_index = kind.def_index(&self.def_path_table);
let def_path_hash = self.def_path_table.def_path_hash(def_index);
def_path_hash.to_dep_node(DepKind::MetaData)
}
}

View File

@ -248,7 +248,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
def_index: DefIndex,
op: fn(&mut IsolatedEncoder<'x, 'a, 'tcx>, DATA) -> R,
data: DATA)
-> Tracked<R> {
-> R {
let mut entry_builder = IsolatedEncoder::new(self);
let ret = op(&mut entry_builder, data);
let (fingerprint, this) = entry_builder.finish();
@ -260,7 +260,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
})
}
Tracked::new(ret)
ret
}
fn encode_info_for_items(&mut self) -> Index {
@ -408,9 +408,9 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
triple: tcx.sess.opts.target_triple.clone(),
hash: link_meta.crate_hash,
disambiguator: tcx.sess.local_crate_disambiguator(),
panic_strategy: Tracked::new(tcx.sess.panic_strategy()),
has_global_allocator: Tracked::new(has_global_allocator),
has_default_lib_allocator: Tracked::new(has_default_lib_allocator),
panic_strategy: tcx.sess.panic_strategy(),
has_global_allocator: has_global_allocator,
has_default_lib_allocator: has_default_lib_allocator,
plugin_registrar_fn: tcx.sess
.plugin_registrar_fn
.get()

View File

@ -32,8 +32,6 @@ use std::mem;
use rustc_data_structures::stable_hasher::{StableHasher, HashStable,
StableHasherResult};
use rustc::dep_graph::{DepGraph, DepNode};
pub fn rustc_version() -> String {
format!("rustc {}",
option_env!("CFG_VERSION").unwrap_or("unknown version"))
@ -188,75 +186,27 @@ pub enum LazyState {
Previous(usize),
}
/// A `Tracked<T>` wraps a value so that one can only access it when specifying
/// the `DepNode` for that value. This makes it harder to forget registering
/// reads.
#[derive(RustcEncodable, RustcDecodable)]
pub struct Tracked<T> {
state: T,
}
impl<T> Tracked<T> {
pub fn new(state: T) -> Tracked<T> {
Tracked {
state,
}
}
pub fn get(&self, dep_graph: &DepGraph, dep_node: DepNode) -> &T {
dep_graph.read(dep_node);
&self.state
}
pub fn get_untracked(&self) -> &T {
&self.state
}
pub fn map<F, R>(&self, f: F) -> Tracked<R>
where F: FnOnce(&T) -> R
{
Tracked {
state: f(&self.state),
}
}
}
impl<'a, 'gcx, 'tcx, T> HashStable<StableHashingContext<'a, 'gcx, 'tcx>> for Tracked<T>
where T: HashStable<StableHashingContext<'a, 'gcx, 'tcx>>
{
fn hash_stable<W: StableHasherResult>(&self,
hcx: &mut StableHashingContext<'a, 'gcx, 'tcx>,
hasher: &mut StableHasher<W>) {
let Tracked {
ref state
} = *self;
state.hash_stable(hcx, hasher);
}
}
#[derive(RustcEncodable, RustcDecodable)]
pub struct CrateRoot {
pub name: Symbol,
pub triple: String,
pub hash: hir::svh::Svh,
pub disambiguator: Symbol,
pub panic_strategy: Tracked<PanicStrategy>,
pub has_global_allocator: Tracked<bool>,
pub has_default_lib_allocator: Tracked<bool>,
pub panic_strategy: PanicStrategy,
pub has_global_allocator: bool,
pub has_default_lib_allocator: bool,
pub plugin_registrar_fn: Option<DefIndex>,
pub macro_derive_registrar: Option<DefIndex>,
pub crate_deps: Tracked<LazySeq<CrateDep>>,
pub dylib_dependency_formats: Tracked<LazySeq<Option<LinkagePreference>>>,
pub lang_items: Tracked<LazySeq<(DefIndex, usize)>>,
pub lang_items_missing: Tracked<LazySeq<lang_items::LangItem>>,
pub native_libraries: Tracked<LazySeq<NativeLibrary>>,
pub crate_deps: LazySeq<CrateDep>,
pub dylib_dependency_formats: LazySeq<Option<LinkagePreference>>,
pub lang_items: LazySeq<(DefIndex, usize)>,
pub lang_items_missing: LazySeq<lang_items::LangItem>,
pub native_libraries: LazySeq<NativeLibrary>,
pub codemap: LazySeq<syntax_pos::FileMap>,
pub def_path_table: Lazy<hir::map::definitions::DefPathTable>,
pub impls: Tracked<LazySeq<TraitImpls>>,
pub exported_symbols: Tracked<LazySeq<DefIndex>>,
pub impls: LazySeq<TraitImpls>,
pub exported_symbols: LazySeq<DefIndex>,
pub index: LazySeq<index::Index>,
}

View File

@ -146,7 +146,7 @@ pub fn run_core(search_paths: SearchPaths,
let dep_graph = DepGraph::new(false);
let _ignore = dep_graph.in_ignore();
let cstore = Rc::new(CStore::new(&dep_graph, box rustc_trans::LlvmMetadataLoader));
let cstore = Rc::new(CStore::new(box rustc_trans::LlvmMetadataLoader));
let mut sess = session::build_session_(
sessopts, &dep_graph, cpath, diagnostic_handler, codemap, cstore.clone()
);

View File

@ -85,7 +85,7 @@ pub fn run(input: &str,
let dep_graph = DepGraph::new(false);
let _ignore = dep_graph.in_ignore();
let cstore = Rc::new(CStore::new(&dep_graph, box rustc_trans::LlvmMetadataLoader));
let cstore = Rc::new(CStore::new(box rustc_trans::LlvmMetadataLoader));
let mut sess = session::build_session_(
sessopts, &dep_graph, Some(input_path.clone()), handler, codemap.clone(), cstore.clone(),
);
@ -238,7 +238,7 @@ fn run_test(test: &str, cratename: &str, filename: &str, cfgs: Vec<String>, libs
let diagnostic_handler = errors::Handler::with_emitter(true, false, box emitter);
let dep_graph = DepGraph::new(false);
let cstore = Rc::new(CStore::new(&dep_graph, box rustc_trans::LlvmMetadataLoader));
let cstore = Rc::new(CStore::new(box rustc_trans::LlvmMetadataLoader));
let mut sess = session::build_session_(
sessopts, &dep_graph, None, diagnostic_handler, codemap, cstore.clone(),
);

View File

@ -59,7 +59,7 @@ fn basic_sess(sysroot: PathBuf) -> (Session, Rc<CStore>) {
let descriptions = Registry::new(&rustc::DIAGNOSTICS);
let dep_graph = DepGraph::new(opts.build_dep_graph());
let cstore = Rc::new(CStore::new(&dep_graph, 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());
rustc_trans::init(&sess);
rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess));