thread the DepGraph to session/crate-store
This is a [breaking-change] for plugin authors. You must now create a dep-graph earlier.
This commit is contained in:
parent
2237e89908
commit
b711734a5f
@ -32,12 +32,6 @@ pub enum DepNode<D: Clone + Debug> {
|
||||
// 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,
|
||||
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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<String> {
|
||||
}
|
||||
|
||||
pub fn build_session(sopts: config::Options,
|
||||
dep_graph: &DepGraph,
|
||||
local_crate_source_file: Option<PathBuf>,
|
||||
registry: diagnostics::registry::Registry,
|
||||
cstore: Rc<for<'a> 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<PathBuf>,
|
||||
registry: diagnostics::registry::Registry,
|
||||
cstore: Rc<for<'a> 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<PathBuf>,
|
||||
span_diagnostic: errors::Handler,
|
||||
codemap: Rc<codemap::CodeMap>,
|
||||
@ -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,
|
||||
|
@ -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| {
|
||||
|
@ -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 {
|
||||
|
@ -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;
|
||||
|
@ -104,8 +104,10 @@ fn test_env<F>(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<F>(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();
|
||||
|
@ -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<FnvHashMap<ast::CrateNum, Rc<crate_metadata>>>,
|
||||
/// Map from NodeId's of local extern crate statements to crate numbers
|
||||
extern_mod_crate_map: RefCell<NodeMap<ast::CrateNum>>,
|
||||
@ -98,8 +100,10 @@ pub struct CStore {
|
||||
}
|
||||
|
||||
impl CStore {
|
||||
pub fn new(intr: Rc<IdentInterner>) -> CStore {
|
||||
pub fn new(dep_graph: &DepGraph,
|
||||
intr: Rc<IdentInterner>) -> 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()),
|
||||
|
@ -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
|
||||
|
@ -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<String>, 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,
|
||||
|
@ -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();
|
||||
|
@ -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<CStore>) {
|
||||
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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user