Skip to content

rustc: Remove DepGraph handling from rustc_metadata #44418

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 1 commit into from
Sep 10, 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
4 changes: 2 additions & 2 deletions src/librustc_driver/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_driver/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
66 changes: 23 additions & 43 deletions src/librustc_metadata/creader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand All @@ -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;

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
});
Expand Down Expand Up @@ -737,19 +725,19 @@ 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()));
}

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) {
Expand Down Expand Up @@ -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));
}
Expand All @@ -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"));
}
Expand All @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand All @@ -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;
}
}
Expand Down
76 changes: 27 additions & 49 deletions src/librustc_metadata/cstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -78,30 +77,28 @@ 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>>,
pub metadata_loader: Box<MetadataLoader>,
}

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,
Expand Down Expand Up @@ -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 {
Expand All @@ -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()
}
}
Loading