Skip to content

Commit b711734

Browse files
committed
thread the DepGraph to session/crate-store
This is a [breaking-change] for plugin authors. You must now create a dep-graph earlier.
1 parent 2237e89 commit b711734

File tree

14 files changed

+81
-50
lines changed

14 files changed

+81
-50
lines changed

src/librustc/dep_graph/dep_node.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,6 @@ pub enum DepNode<D: Clone + Debug> {
3232
// Represents the HIR node with the given node-id
3333
Hir(D),
3434

35-
// Represents the meta-data for a node. For local def-ids, this is
36-
// created by trans. For remote def-ids, we add a read of this
37-
// node each time we pull the information for an item out of the
38-
// crate store.
39-
MetaData(D),
40-
4135
// Represents different phases in the compiler.
4236
CrateReader,
4337
CollectLanguageItems,

src/librustc/hir/map/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,10 @@ pub struct Forest {
160160
}
161161

162162
impl Forest {
163-
pub fn new(krate: Crate, dep_graph: DepGraph) -> Forest {
163+
pub fn new(krate: Crate, dep_graph: &DepGraph) -> Forest {
164164
Forest {
165165
krate: krate,
166-
dep_graph: dep_graph,
166+
dep_graph: dep_graph.clone(),
167167
inlined_items: TypedArena::new()
168168
}
169169
}

src/librustc/middle/cstore.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ use session::Session;
3434
use session::config::PanicStrategy;
3535
use session::search_paths::PathKind;
3636
use util::nodemap::{FnvHashMap, NodeMap, NodeSet, DefIdMap};
37-
use std::any::Any;
3837
use std::cell::RefCell;
3938
use std::rc::Rc;
4039
use std::path::PathBuf;

src/librustc/session/config.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1420,6 +1420,7 @@ impl fmt::Display for CrateType {
14201420

14211421
#[cfg(test)]
14221422
mod tests {
1423+
use dep_graph::DepGraph;
14231424
use middle::cstore::DummyCrateStore;
14241425
use session::config::{build_configuration, build_session_options};
14251426
use session::build_session;
@@ -1439,14 +1440,15 @@ mod tests {
14391440
// When the user supplies --test we should implicitly supply --cfg test
14401441
#[test]
14411442
fn test_switch_implies_cfg_test() {
1443+
let dep_graph = DepGraph::new(false);
14421444
let matches =
14431445
&match getopts(&["--test".to_string()], &optgroups()) {
14441446
Ok(m) => m,
14451447
Err(f) => panic!("test_switch_implies_cfg_test: {}", f)
14461448
};
14471449
let registry = diagnostics::registry::Registry::new(&[]);
14481450
let sessopts = build_session_options(matches);
1449-
let sess = build_session(sessopts, None, registry, Rc::new(DummyCrateStore));
1451+
let sess = build_session(sessopts, &dep_graph, None, registry, Rc::new(DummyCrateStore));
14501452
let cfg = build_configuration(&sess);
14511453
assert!((attr::contains_name(&cfg[..], "test")));
14521454
}
@@ -1455,6 +1457,7 @@ mod tests {
14551457
// another --cfg test
14561458
#[test]
14571459
fn test_switch_implies_cfg_test_unless_cfg_test() {
1460+
let dep_graph = DepGraph::new(false);
14581461
let matches =
14591462
&match getopts(&["--test".to_string(), "--cfg=test".to_string()],
14601463
&optgroups()) {
@@ -1465,7 +1468,7 @@ mod tests {
14651468
};
14661469
let registry = diagnostics::registry::Registry::new(&[]);
14671470
let sessopts = build_session_options(matches);
1468-
let sess = build_session(sessopts, None, registry,
1471+
let sess = build_session(sessopts, &dep_graph, None, registry,
14691472
Rc::new(DummyCrateStore));
14701473
let cfg = build_configuration(&sess);
14711474
let mut test_items = cfg.iter().filter(|m| m.name() == "test");
@@ -1475,13 +1478,14 @@ mod tests {
14751478

14761479
#[test]
14771480
fn test_can_print_warnings() {
1481+
let dep_graph = DepGraph::new(false);
14781482
{
14791483
let matches = getopts(&[
14801484
"-Awarnings".to_string()
14811485
], &optgroups()).unwrap();
14821486
let registry = diagnostics::registry::Registry::new(&[]);
14831487
let sessopts = build_session_options(&matches);
1484-
let sess = build_session(sessopts, None, registry,
1488+
let sess = build_session(sessopts, &dep_graph, None, registry,
14851489
Rc::new(DummyCrateStore));
14861490
assert!(!sess.diagnostic().can_emit_warnings);
14871491
}
@@ -1493,7 +1497,7 @@ mod tests {
14931497
], &optgroups()).unwrap();
14941498
let registry = diagnostics::registry::Registry::new(&[]);
14951499
let sessopts = build_session_options(&matches);
1496-
let sess = build_session(sessopts, None, registry,
1500+
let sess = build_session(sessopts, &dep_graph, None, registry,
14971501
Rc::new(DummyCrateStore));
14981502
assert!(sess.diagnostic().can_emit_warnings);
14991503
}
@@ -1504,7 +1508,7 @@ mod tests {
15041508
], &optgroups()).unwrap();
15051509
let registry = diagnostics::registry::Registry::new(&[]);
15061510
let sessopts = build_session_options(&matches);
1507-
let sess = build_session(sessopts, None, registry,
1511+
let sess = build_session(sessopts, &dep_graph, None, registry,
15081512
Rc::new(DummyCrateStore));
15091513
assert!(sess.diagnostic().can_emit_warnings);
15101514
}

src/librustc/session/mod.rs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
use dep_graph::DepGraph;
1112
use lint;
1213
use middle::cstore::CrateStore;
1314
use middle::dependency_format;
@@ -49,6 +50,7 @@ pub mod search_paths;
4950
// Represents the data associated with a compilation
5051
// session for a single crate.
5152
pub struct Session {
53+
pub dep_graph: DepGraph,
5254
pub target: config::Config,
5355
pub host: Target,
5456
pub opts: config::Options,
@@ -408,18 +410,21 @@ fn split_msg_into_multilines(msg: &str) -> Option<String> {
408410
}
409411

410412
pub fn build_session(sopts: config::Options,
413+
dep_graph: &DepGraph,
411414
local_crate_source_file: Option<PathBuf>,
412415
registry: diagnostics::registry::Registry,
413416
cstore: Rc<for<'a> CrateStore<'a>>)
414417
-> Session {
415418
build_session_with_codemap(sopts,
416-
local_crate_source_file,
417-
registry,
418-
cstore,
419-
Rc::new(codemap::CodeMap::new()))
419+
dep_graph,
420+
local_crate_source_file,
421+
registry,
422+
cstore,
423+
Rc::new(codemap::CodeMap::new()))
420424
}
421425

422426
pub fn build_session_with_codemap(sopts: config::Options,
427+
dep_graph: &DepGraph,
423428
local_crate_source_file: Option<PathBuf>,
424429
registry: diagnostics::registry::Registry,
425430
cstore: Rc<for<'a> CrateStore<'a>>,
@@ -450,10 +455,16 @@ pub fn build_session_with_codemap(sopts: config::Options,
450455
treat_err_as_bug,
451456
emitter);
452457

453-
build_session_(sopts, local_crate_source_file, diagnostic_handler, codemap, cstore)
458+
build_session_(sopts,
459+
dep_graph,
460+
local_crate_source_file,
461+
diagnostic_handler,
462+
codemap,
463+
cstore)
454464
}
455465

456466
pub fn build_session_(sopts: config::Options,
467+
dep_graph: &DepGraph,
457468
local_crate_source_file: Option<PathBuf>,
458469
span_diagnostic: errors::Handler,
459470
codemap: Rc<codemap::CodeMap>,
@@ -482,6 +493,7 @@ pub fn build_session_(sopts: config::Options,
482493
);
483494

484495
let sess = Session {
496+
dep_graph: dep_graph.clone(),
485497
target: target_cfg,
486498
host: host,
487499
opts: sopts,

src/librustc_driver/driver.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,6 @@ pub fn compile_input(sess: &Session,
152152
Ok(()));
153153

154154
let expanded_crate = assign_node_ids(sess, expanded_crate);
155-
let dep_graph = DepGraph::new(sess.opts.build_dep_graph());
156155

157156
// Collect defintions for def ids.
158157
let mut defs = time(sess.time_passes(),
@@ -161,15 +160,15 @@ pub fn compile_input(sess: &Session,
161160

162161
time(sess.time_passes(),
163162
"external crate/lib resolution",
164-
|| read_local_crates(sess, &cstore, &defs, &expanded_crate, &id, &dep_graph));
163+
|| read_local_crates(sess, &cstore, &defs, &expanded_crate, &id, &sess.dep_graph));
165164

166165
time(sess.time_passes(),
167166
"early lint checks",
168167
|| lint::check_ast_crate(sess, &expanded_crate));
169168

170169
let (analysis, resolutions, mut hir_forest) = {
171-
lower_and_resolve(sess, &id, &mut defs, &expanded_crate, dep_graph,
172-
control.make_glob_map)
170+
lower_and_resolve(sess, &id, &mut defs, &expanded_crate,
171+
&sess.dep_graph, control.make_glob_map)
173172
};
174173

175174
// Discard MTWT tables that aren't required past lowering to HIR.
@@ -805,7 +804,7 @@ pub fn lower_and_resolve<'a>(sess: &Session,
805804
id: &'a str,
806805
defs: &mut hir_map::Definitions,
807806
krate: &ast::Crate,
808-
dep_graph: DepGraph,
807+
dep_graph: &DepGraph,
809808
make_glob_map: resolve::MakeGlobMap)
810809
-> (ty::CrateAnalysis<'a>, Resolutions, hir_map::Forest) {
811810
resolve::with_resolver(sess, defs, make_glob_map, |mut resolver| {

src/librustc_driver/lib.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ use pretty::{PpMode, UserIdentifiedItem};
6767
use rustc_resolve as resolve;
6868
use rustc_save_analysis as save;
6969
use rustc_trans::back::link;
70+
use rustc::dep_graph::DepGraph;
7071
use rustc::session::{self, config, Session, build_session, CompileResult};
7172
use rustc::session::config::{Input, PrintRequest, OutputType, ErrorOutputType};
7273
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],
196197
},
197198
};
198199

199-
let cstore = Rc::new(CStore::new(token::get_ident_interner()));
200+
let dep_graph = DepGraph::new(sopts.build_dep_graph());
201+
let cstore = Rc::new(CStore::new(&dep_graph, token::get_ident_interner()));
200202
let codemap = Rc::new(CodeMap::with_file_loader(loader));
201203
let sess = session::build_session_with_codemap(sopts,
204+
&dep_graph,
202205
input_file_path,
203206
descriptions,
204207
cstore.clone(),
@@ -425,9 +428,13 @@ impl<'a> CompilerCalls<'a> for RustcDefaultCalls {
425428
describe_lints(&ls, false);
426429
return None;
427430
}
428-
let cstore = Rc::new(CStore::new(token::get_ident_interner()));
429-
let sess = build_session(sopts.clone(), None, descriptions.clone(),
430-
cstore.clone());
431+
let dep_graph = DepGraph::new(sopts.build_dep_graph());
432+
let cstore = Rc::new(CStore::new(&dep_graph, token::get_ident_interner()));
433+
let sess = build_session(sopts.clone(),
434+
&dep_graph,
435+
None,
436+
descriptions.clone(),
437+
cstore.clone());
431438
rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess));
432439
let should_stop = RustcDefaultCalls::print_crate_info(&sess, None, odir, ofile);
433440
if should_stop == Compilation::Stop {

src/librustc_driver/pretty.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ use self::NodesMatchingUII::*;
1818
use abort_on_err;
1919
use driver::{self, Resolutions};
2020

21-
use rustc::dep_graph::DepGraph;
2221
use rustc::ty::{self, TyCtxt};
2322
use rustc::cfg;
2423
use rustc::cfg::graphviz::LabelledCFG;
24+
use rustc::dep_graph::DepGraph;
2525
use rustc::session::Session;
2626
use rustc::session::config::Input;
2727
use rustc_borrowck as borrowck;

src/librustc_driver/test.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,10 @@ fn test_env<F>(source_string: &str,
104104
options.unstable_features = UnstableFeatures::Allow;
105105
let diagnostic_handler = errors::Handler::with_emitter(true, false, emitter);
106106

107-
let cstore = Rc::new(CStore::new(token::get_ident_interner()));
108-
let sess = session::build_session_(options, None, diagnostic_handler,
107+
let dep_graph = DepGraph::new(false);
108+
let _ignore = dep_graph.in_ignore();
109+
let cstore = Rc::new(CStore::new(&dep_graph, token::get_ident_interner()));
110+
let sess = session::build_session_(options, &dep_graph, None, diagnostic_handler,
109111
Rc::new(CodeMap::new()), cstore.clone());
110112
rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess));
111113
let krate_config = Vec::new();
@@ -117,15 +119,14 @@ fn test_env<F>(source_string: &str,
117119
let krate = driver::phase_2_configure_and_expand(&sess, &cstore, krate, "test", None)
118120
.expect("phase 2 aborted");
119121

120-
let dep_graph = DepGraph::new(false);
121122
let krate = driver::assign_node_ids(&sess, krate);
122123
let mut defs = hir_map::collect_definitions(&krate);
123124
read_local_crates(&sess, &cstore, &defs, &krate, "test_crate", &dep_graph);
124125
let _ignore = dep_graph.in_ignore();
125126

126127
let (_, resolutions, mut hir_forest) = {
127-
driver::lower_and_resolve(&sess, "test-crate", &mut defs, &krate, dep_graph.clone(),
128-
MakeGlobMap::No)
128+
driver::lower_and_resolve(&sess, "test-crate", &mut defs, &krate,
129+
&sess.dep_graph, MakeGlobMap::No)
129130
};
130131

131132
let arenas = ty::CtxtArenas::new();

src/librustc_metadata/cstore.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use decoder;
2020
use index;
2121
use loader;
2222

23+
use rustc::dep_graph::DepGraph;
2324
use rustc::hir::def_id::DefId;
2425
use rustc::hir::svh::Svh;
2526
use rustc::middle::cstore::{ExternCrate};
@@ -86,6 +87,7 @@ pub struct crate_metadata {
8687
}
8788

8889
pub struct CStore {
90+
_dep_graph: DepGraph,
8991
metas: RefCell<FnvHashMap<ast::CrateNum, Rc<crate_metadata>>>,
9092
/// Map from NodeId's of local extern crate statements to crate numbers
9193
extern_mod_crate_map: RefCell<NodeMap<ast::CrateNum>>,
@@ -98,8 +100,10 @@ pub struct CStore {
98100
}
99101

100102
impl CStore {
101-
pub fn new(intr: Rc<IdentInterner>) -> CStore {
103+
pub fn new(dep_graph: &DepGraph,
104+
intr: Rc<IdentInterner>) -> CStore {
102105
CStore {
106+
_dep_graph: dep_graph.clone(),
103107
metas: RefCell::new(FnvHashMap()),
104108
extern_mod_crate_map: RefCell::new(FnvHashMap()),
105109
used_crate_sources: RefCell::new(Vec::new()),

0 commit comments

Comments
 (0)