diff --git a/src/librustc/dep_graph/dep_node.rs b/src/librustc/dep_graph/dep_node.rs index b81aa582236..3e43c8e2c93 100644 --- a/src/librustc/dep_graph/dep_node.rs +++ b/src/librustc/dep_graph/dep_node.rs @@ -32,12 +32,6 @@ pub enum DepNode { // Represents the HIR node with the given node-id Hir(D), - // Represents the meta-data for a node. For local def-ids, this is - // created by trans. For remote def-ids, we add a read of this - // node each time we pull the information for an item out of the - // crate store. - MetaData(D), - // Represents different phases in the compiler. CrateReader, CollectLanguageItems, diff --git a/src/librustc/hir/map/mod.rs b/src/librustc/hir/map/mod.rs index c0bbccad5f2..e3976482dca 100644 --- a/src/librustc/hir/map/mod.rs +++ b/src/librustc/hir/map/mod.rs @@ -160,10 +160,10 @@ pub struct Forest { } impl Forest { - pub fn new(krate: Crate, dep_graph: DepGraph) -> Forest { + pub fn new(krate: Crate, dep_graph: &DepGraph) -> Forest { Forest { krate: krate, - dep_graph: dep_graph, + dep_graph: dep_graph.clone(), inlined_items: TypedArena::new() } } diff --git a/src/librustc/middle/cstore.rs b/src/librustc/middle/cstore.rs index 85c31774cc4..17c6442c019 100644 --- a/src/librustc/middle/cstore.rs +++ b/src/librustc/middle/cstore.rs @@ -34,7 +34,6 @@ use session::Session; use session::config::PanicStrategy; use session::search_paths::PathKind; use util::nodemap::{FnvHashMap, NodeMap, NodeSet, DefIdMap}; -use std::any::Any; use std::cell::RefCell; use std::rc::Rc; use std::path::PathBuf; diff --git a/src/librustc/session/config.rs b/src/librustc/session/config.rs index 7d1d5dba398..7bb96c5ab2b 100644 --- a/src/librustc/session/config.rs +++ b/src/librustc/session/config.rs @@ -1420,6 +1420,7 @@ impl fmt::Display for CrateType { #[cfg(test)] mod tests { + use dep_graph::DepGraph; use middle::cstore::DummyCrateStore; use session::config::{build_configuration, build_session_options}; use session::build_session; @@ -1439,6 +1440,7 @@ mod tests { // When the user supplies --test we should implicitly supply --cfg test #[test] fn test_switch_implies_cfg_test() { + let dep_graph = DepGraph::new(false); let matches = &match getopts(&["--test".to_string()], &optgroups()) { Ok(m) => m, @@ -1446,7 +1448,7 @@ mod tests { }; let registry = diagnostics::registry::Registry::new(&[]); let sessopts = build_session_options(matches); - let sess = build_session(sessopts, None, registry, Rc::new(DummyCrateStore)); + let sess = build_session(sessopts, &dep_graph, None, registry, Rc::new(DummyCrateStore)); let cfg = build_configuration(&sess); assert!((attr::contains_name(&cfg[..], "test"))); } @@ -1455,6 +1457,7 @@ mod tests { // another --cfg test #[test] fn test_switch_implies_cfg_test_unless_cfg_test() { + let dep_graph = DepGraph::new(false); let matches = &match getopts(&["--test".to_string(), "--cfg=test".to_string()], &optgroups()) { @@ -1465,7 +1468,7 @@ mod tests { }; let registry = diagnostics::registry::Registry::new(&[]); let sessopts = build_session_options(matches); - let sess = build_session(sessopts, None, registry, + let sess = build_session(sessopts, &dep_graph, None, registry, Rc::new(DummyCrateStore)); let cfg = build_configuration(&sess); let mut test_items = cfg.iter().filter(|m| m.name() == "test"); @@ -1475,13 +1478,14 @@ mod tests { #[test] fn test_can_print_warnings() { + let dep_graph = DepGraph::new(false); { let matches = getopts(&[ "-Awarnings".to_string() ], &optgroups()).unwrap(); let registry = diagnostics::registry::Registry::new(&[]); let sessopts = build_session_options(&matches); - let sess = build_session(sessopts, None, registry, + let sess = build_session(sessopts, &dep_graph, None, registry, Rc::new(DummyCrateStore)); assert!(!sess.diagnostic().can_emit_warnings); } @@ -1493,7 +1497,7 @@ mod tests { ], &optgroups()).unwrap(); let registry = diagnostics::registry::Registry::new(&[]); let sessopts = build_session_options(&matches); - let sess = build_session(sessopts, None, registry, + let sess = build_session(sessopts, &dep_graph, None, registry, Rc::new(DummyCrateStore)); assert!(sess.diagnostic().can_emit_warnings); } @@ -1504,7 +1508,7 @@ mod tests { ], &optgroups()).unwrap(); let registry = diagnostics::registry::Registry::new(&[]); let sessopts = build_session_options(&matches); - let sess = build_session(sessopts, None, registry, + let sess = build_session(sessopts, &dep_graph, None, registry, Rc::new(DummyCrateStore)); assert!(sess.diagnostic().can_emit_warnings); } diff --git a/src/librustc/session/mod.rs b/src/librustc/session/mod.rs index 1bea01c4849..61d6acfe061 100644 --- a/src/librustc/session/mod.rs +++ b/src/librustc/session/mod.rs @@ -8,6 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +use dep_graph::DepGraph; use lint; use middle::cstore::CrateStore; use middle::dependency_format; @@ -49,6 +50,7 @@ pub mod search_paths; // Represents the data associated with a compilation // session for a single crate. pub struct Session { + pub dep_graph: DepGraph, pub target: config::Config, pub host: Target, pub opts: config::Options, @@ -408,18 +410,21 @@ fn split_msg_into_multilines(msg: &str) -> Option { } pub fn build_session(sopts: config::Options, + dep_graph: &DepGraph, local_crate_source_file: Option, registry: diagnostics::registry::Registry, cstore: Rc CrateStore<'a>>) -> Session { build_session_with_codemap(sopts, - local_crate_source_file, - registry, - cstore, - Rc::new(codemap::CodeMap::new())) + dep_graph, + local_crate_source_file, + registry, + cstore, + Rc::new(codemap::CodeMap::new())) } pub fn build_session_with_codemap(sopts: config::Options, + dep_graph: &DepGraph, local_crate_source_file: Option, registry: diagnostics::registry::Registry, cstore: Rc CrateStore<'a>>, @@ -450,10 +455,16 @@ pub fn build_session_with_codemap(sopts: config::Options, treat_err_as_bug, emitter); - build_session_(sopts, local_crate_source_file, diagnostic_handler, codemap, cstore) + build_session_(sopts, + dep_graph, + local_crate_source_file, + diagnostic_handler, + codemap, + cstore) } pub fn build_session_(sopts: config::Options, + dep_graph: &DepGraph, local_crate_source_file: Option, span_diagnostic: errors::Handler, codemap: Rc, @@ -482,6 +493,7 @@ pub fn build_session_(sopts: config::Options, ); let sess = Session { + dep_graph: dep_graph.clone(), target: target_cfg, host: host, opts: sopts, diff --git a/src/librustc_driver/driver.rs b/src/librustc_driver/driver.rs index 46356add8c6..da6af914092 100644 --- a/src/librustc_driver/driver.rs +++ b/src/librustc_driver/driver.rs @@ -152,7 +152,6 @@ pub fn compile_input(sess: &Session, Ok(())); let expanded_crate = assign_node_ids(sess, expanded_crate); - let dep_graph = DepGraph::new(sess.opts.build_dep_graph()); // Collect defintions for def ids. let mut defs = time(sess.time_passes(), @@ -161,15 +160,15 @@ pub fn compile_input(sess: &Session, time(sess.time_passes(), "external crate/lib resolution", - || read_local_crates(sess, &cstore, &defs, &expanded_crate, &id, &dep_graph)); + || read_local_crates(sess, &cstore, &defs, &expanded_crate, &id, &sess.dep_graph)); time(sess.time_passes(), "early lint checks", || lint::check_ast_crate(sess, &expanded_crate)); let (analysis, resolutions, mut hir_forest) = { - lower_and_resolve(sess, &id, &mut defs, &expanded_crate, dep_graph, - control.make_glob_map) + lower_and_resolve(sess, &id, &mut defs, &expanded_crate, + &sess.dep_graph, control.make_glob_map) }; // Discard MTWT tables that aren't required past lowering to HIR. @@ -805,7 +804,7 @@ pub fn lower_and_resolve<'a>(sess: &Session, id: &'a str, defs: &mut hir_map::Definitions, krate: &ast::Crate, - dep_graph: DepGraph, + dep_graph: &DepGraph, make_glob_map: resolve::MakeGlobMap) -> (ty::CrateAnalysis<'a>, Resolutions, hir_map::Forest) { resolve::with_resolver(sess, defs, make_glob_map, |mut resolver| { diff --git a/src/librustc_driver/lib.rs b/src/librustc_driver/lib.rs index 2a4b30e016f..06133c508d9 100644 --- a/src/librustc_driver/lib.rs +++ b/src/librustc_driver/lib.rs @@ -67,6 +67,7 @@ use pretty::{PpMode, UserIdentifiedItem}; use rustc_resolve as resolve; use rustc_save_analysis as save; use rustc_trans::back::link; +use rustc::dep_graph::DepGraph; use rustc::session::{self, config, Session, build_session, CompileResult}; use rustc::session::config::{Input, PrintRequest, OutputType, ErrorOutputType}; use rustc::session::config::{get_unstable_features_setting, nightly_options}; @@ -196,9 +197,11 @@ pub fn run_compiler_with_file_loader<'a, L>(args: &[String], }, }; - let cstore = Rc::new(CStore::new(token::get_ident_interner())); + let dep_graph = DepGraph::new(sopts.build_dep_graph()); + let cstore = Rc::new(CStore::new(&dep_graph, token::get_ident_interner())); let codemap = Rc::new(CodeMap::with_file_loader(loader)); let sess = session::build_session_with_codemap(sopts, + &dep_graph, input_file_path, descriptions, cstore.clone(), @@ -425,9 +428,13 @@ impl<'a> CompilerCalls<'a> for RustcDefaultCalls { describe_lints(&ls, false); return None; } - let cstore = Rc::new(CStore::new(token::get_ident_interner())); - let sess = build_session(sopts.clone(), None, descriptions.clone(), - cstore.clone()); + let dep_graph = DepGraph::new(sopts.build_dep_graph()); + let cstore = Rc::new(CStore::new(&dep_graph, token::get_ident_interner())); + let sess = build_session(sopts.clone(), + &dep_graph, + None, + descriptions.clone(), + cstore.clone()); rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess)); let should_stop = RustcDefaultCalls::print_crate_info(&sess, None, odir, ofile); if should_stop == Compilation::Stop { diff --git a/src/librustc_driver/pretty.rs b/src/librustc_driver/pretty.rs index 9aae9f04c92..8c84e561e31 100644 --- a/src/librustc_driver/pretty.rs +++ b/src/librustc_driver/pretty.rs @@ -18,10 +18,10 @@ use self::NodesMatchingUII::*; use abort_on_err; use driver::{self, Resolutions}; -use rustc::dep_graph::DepGraph; use rustc::ty::{self, TyCtxt}; use rustc::cfg; use rustc::cfg::graphviz::LabelledCFG; +use rustc::dep_graph::DepGraph; use rustc::session::Session; use rustc::session::config::Input; use rustc_borrowck as borrowck; diff --git a/src/librustc_driver/test.rs b/src/librustc_driver/test.rs index bbda1965c7f..e0d693c4230 100644 --- a/src/librustc_driver/test.rs +++ b/src/librustc_driver/test.rs @@ -104,8 +104,10 @@ fn test_env(source_string: &str, options.unstable_features = UnstableFeatures::Allow; let diagnostic_handler = errors::Handler::with_emitter(true, false, emitter); - let cstore = Rc::new(CStore::new(token::get_ident_interner())); - let sess = session::build_session_(options, None, diagnostic_handler, + let dep_graph = DepGraph::new(false); + let _ignore = dep_graph.in_ignore(); + let cstore = Rc::new(CStore::new(&dep_graph, token::get_ident_interner())); + let sess = session::build_session_(options, &dep_graph, None, diagnostic_handler, Rc::new(CodeMap::new()), cstore.clone()); rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess)); let krate_config = Vec::new(); @@ -117,15 +119,14 @@ fn test_env(source_string: &str, let krate = driver::phase_2_configure_and_expand(&sess, &cstore, krate, "test", None) .expect("phase 2 aborted"); - let dep_graph = DepGraph::new(false); let krate = driver::assign_node_ids(&sess, krate); let mut defs = hir_map::collect_definitions(&krate); read_local_crates(&sess, &cstore, &defs, &krate, "test_crate", &dep_graph); let _ignore = dep_graph.in_ignore(); let (_, resolutions, mut hir_forest) = { - driver::lower_and_resolve(&sess, "test-crate", &mut defs, &krate, dep_graph.clone(), - MakeGlobMap::No) + driver::lower_and_resolve(&sess, "test-crate", &mut defs, &krate, + &sess.dep_graph, MakeGlobMap::No) }; let arenas = ty::CtxtArenas::new(); diff --git a/src/librustc_metadata/cstore.rs b/src/librustc_metadata/cstore.rs index 04b6e1c42b9..940688f5507 100644 --- a/src/librustc_metadata/cstore.rs +++ b/src/librustc_metadata/cstore.rs @@ -20,6 +20,7 @@ use decoder; use index; use loader; +use rustc::dep_graph::DepGraph; use rustc::hir::def_id::DefId; use rustc::hir::svh::Svh; use rustc::middle::cstore::{ExternCrate}; @@ -86,6 +87,7 @@ pub struct crate_metadata { } pub struct CStore { + _dep_graph: DepGraph, metas: RefCell>>, /// Map from NodeId's of local extern crate statements to crate numbers extern_mod_crate_map: RefCell>, @@ -98,8 +100,10 @@ pub struct CStore { } impl CStore { - pub fn new(intr: Rc) -> CStore { + pub fn new(dep_graph: &DepGraph, + intr: Rc) -> CStore { CStore { + _dep_graph: dep_graph.clone(), metas: RefCell::new(FnvHashMap()), extern_mod_crate_map: RefCell::new(FnvHashMap()), used_crate_sources: RefCell::new(Vec::new()), diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index 6d45980b45d..4ae869c3259 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -134,8 +134,10 @@ pub fn run_core(search_paths: SearchPaths, false, codemap.clone()); - let cstore = Rc::new(CStore::new(token::get_ident_interner())); - let sess = session::build_session_(sessopts, cpath, diagnostic_handler, + let dep_graph = DepGraph::new(false); + let _ignore = dep_graph.in_ignore(); + let cstore = Rc::new(CStore::new(&dep_graph, token::get_ident_interner())); + let sess = session::build_session_(sessopts, &dep_graph, cpath, diagnostic_handler, codemap, cstore.clone()); rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess)); @@ -151,15 +153,14 @@ pub fn run_core(search_paths: SearchPaths, .expect("phase_2_configure_and_expand aborted in rustdoc!"); let krate = driver::assign_node_ids(&sess, krate); - let dep_graph = DepGraph::new(false); let mut defs = hir_map::collect_definitions(&krate); read_local_crates(&sess, &cstore, &defs, &krate, &name, &dep_graph); // Lower ast -> hir and resolve. let (analysis, resolutions, mut hir_forest) = { - driver::lower_and_resolve(&sess, &name, &mut defs, &krate, dep_graph, - resolve::MakeGlobMap::No) + driver::lower_and_resolve(&sess, &name, &mut defs, &krate, + &sess.dep_graph, resolve::MakeGlobMap::No) }; let arenas = ty::CtxtArenas::new(); @@ -177,7 +178,6 @@ pub fn run_core(search_paths: SearchPaths, return None } - let _ignore = tcx.dep_graph.in_ignore(); let ty::CrateAnalysis { access_levels, .. } = analysis; // Convert from a NodeId set to a DefId set since we don't always have easy access diff --git a/src/librustdoc/test.rs b/src/librustdoc/test.rs index e4fbdba77a4..bec18d2cc63 100644 --- a/src/librustdoc/test.rs +++ b/src/librustdoc/test.rs @@ -79,8 +79,11 @@ pub fn run(input: &str, false, codemap.clone()); - let cstore = Rc::new(CStore::new(token::get_ident_interner())); + let dep_graph = DepGraph::new(false); + let _ignore = dep_graph.in_ignore(); + let cstore = Rc::new(CStore::new(&dep_graph, token::get_ident_interner())); let sess = session::build_session_(sessopts, + &dep_graph, Some(input_path.clone()), diagnostic_handler, codemap, @@ -103,7 +106,7 @@ pub fn run(input: &str, let opts = scrape_test_config(&krate); let _ignore = dep_graph.in_ignore(); - let mut forest = hir_map::Forest::new(krate, dep_graph.clone()); + let mut forest = hir_map::Forest::new(krate, &dep_graph); let map = hir_map::map_crate(&mut forest, defs); let ctx = core::DocContext { @@ -238,8 +241,10 @@ fn runtest(test: &str, cratename: &str, cfgs: Vec, libs: SearchPaths, // Compile the code let diagnostic_handler = errors::Handler::with_emitter(true, false, box emitter); - let cstore = Rc::new(CStore::new(token::get_ident_interner())); + let dep_graph = DepGraph::new(false); + let cstore = Rc::new(CStore::new(&dep_graph, token::get_ident_interner())); let sess = session::build_session_(sessopts, + &dep_graph, None, diagnostic_handler, codemap, diff --git a/src/test/run-make/execution-engine/test.rs b/src/test/run-make/execution-engine/test.rs index 0ad113b8d8b..0e84a0f5221 100644 --- a/src/test/run-make/execution-engine/test.rs +++ b/src/test/run-make/execution-engine/test.rs @@ -223,8 +223,12 @@ fn compile_program(input: &str, sysroot: PathBuf) let handle = thread.spawn(move || { let opts = build_exec_options(sysroot); - let cstore = Rc::new(CStore::new(token::get_ident_interner())); - let sess = build_session(opts, None, Registry::new(&rustc::DIAGNOSTICS), + let dep_graph = DepGraph::new(opts.build_dep_graph()); + let cstore = Rc::new(CStore::new(&dep_graph, token::get_ident_interner())); + let sess = build_session(opts, + &dep_graph, + None, + Registry::new(&rustc::DIAGNOSTICS), cstore.clone()); rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess)); @@ -237,12 +241,12 @@ fn compile_program(input: &str, sysroot: PathBuf) let krate = driver::phase_2_configure_and_expand(&sess, &cstore, krate, &id, None) .expect("phase_2 returned `None`"); - let dep_graph = DepGraph::new(sess.opts.build_dep_graph()); let krate = driver::assign_node_ids(&sess, krate); let mut defs = ast_map::collect_definitions(&krate); read_local_crates(&sess, &cstore, &defs, &krate, &id, &dep_graph); let (analysis, resolutions, mut hir_forest) = { - driver::lower_and_resolve(&sess, &id, &mut defs, &krate, dep_graph, MakeGlobMap::No) + driver::lower_and_resolve(&sess, &id, &mut defs, &krate, + &sess.dep_graph, MakeGlobMap::No) }; let arenas = ty::CtxtArenas::new(); diff --git a/src/test/run-make/issue-19371/foo.rs b/src/test/run-make/issue-19371/foo.rs index 80c06ca3274..41d250eadec 100644 --- a/src/test/run-make/issue-19371/foo.rs +++ b/src/test/run-make/issue-19371/foo.rs @@ -16,6 +16,7 @@ extern crate rustc_lint; extern crate rustc_metadata; extern crate syntax; +use rustc::dep_graph::DepGraph; use rustc::session::{build_session, Session}; use rustc::session::config::{basic_options, build_configuration, Input, OutputType}; use rustc_driver::driver::{compile_input, CompileController, anon_src}; @@ -54,8 +55,9 @@ fn basic_sess(sysroot: PathBuf) -> (Session, Rc) { opts.maybe_sysroot = Some(sysroot); let descriptions = Registry::new(&rustc::DIAGNOSTICS); - let cstore = Rc::new(CStore::new(token::get_ident_interner())); - let sess = build_session(opts, None, descriptions, cstore.clone()); + let dep_graph = DepGraph::new(opts.build_dep_graph()); + let cstore = Rc::new(CStore::new(&dep_graph, token::get_ident_interner())); + let sess = build_session(opts, &dep_graph, None, descriptions, cstore.clone()); rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess)); (sess, cstore) }