Skip to content

Commit 2d288a5

Browse files
committed
Auto merge of #44502 - alexcrichton:remove-session-dep-graph, r=michaelwoerister
rustc: Remove `Session::dep_graph` This commit removes the `dep_graph` field from the `Session` type according to issue #44390. Most of the fallout here was relatively straightforward and the `prepare_session_directory` function was rejiggered a bit to reuse the results in the later-called `load_dep_graph` function. Closes #44390
2 parents 5dfc84c + 1cf956f commit 2d288a5

File tree

16 files changed

+142
-113
lines changed

16 files changed

+142
-113
lines changed

src/librustc/hir/lowering.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
//! get confused if the spans from leaf AST nodes occur in multiple places
4141
//! in the HIR, especially for multiple identifiers.
4242
43+
use dep_graph::DepGraph;
4344
use hir;
4445
use hir::map::{Definitions, DefKey};
4546
use hir::def_id::{DefIndex, DefId, CRATE_DEF_INDEX};
@@ -122,13 +123,14 @@ pub trait Resolver {
122123

123124
pub fn lower_crate(sess: &Session,
124125
cstore: &CrateStore,
126+
dep_graph: &DepGraph,
125127
krate: &Crate,
126128
resolver: &mut Resolver)
127129
-> hir::Crate {
128130
// We're constructing the HIR here; we don't care what we will
129131
// read, since we haven't even constructed the *input* to
130132
// incr. comp. yet.
131-
let _ignore = sess.dep_graph.in_ignore();
133+
let _ignore = dep_graph.in_ignore();
132134

133135
LoweringContext {
134136
crate_root: std_inject::injected_crate_name(krate),

src/librustc/session/config.rs

+5-9
Original file line numberDiff line numberDiff line change
@@ -1949,7 +1949,6 @@ mod dep_tracking {
19491949

19501950
#[cfg(test)]
19511951
mod tests {
1952-
use dep_graph::DepGraph;
19531952
use errors;
19541953
use getopts;
19551954
use lint;
@@ -1982,15 +1981,14 @@ mod tests {
19821981
// When the user supplies --test we should implicitly supply --cfg test
19831982
#[test]
19841983
fn test_switch_implies_cfg_test() {
1985-
let dep_graph = DepGraph::new(false);
19861984
let matches =
19871985
&match optgroups().parse(&["--test".to_string()]) {
19881986
Ok(m) => m,
19891987
Err(f) => panic!("test_switch_implies_cfg_test: {}", f)
19901988
};
19911989
let registry = errors::registry::Registry::new(&[]);
19921990
let (sessopts, cfg) = build_session_options_and_crate_config(matches);
1993-
let sess = build_session(sessopts, &dep_graph, None, registry);
1991+
let sess = build_session(sessopts, None, registry);
19941992
let cfg = build_configuration(&sess, cfg);
19951993
assert!(cfg.contains(&(Symbol::intern("test"), None)));
19961994
}
@@ -1999,7 +1997,6 @@ mod tests {
19991997
// another --cfg test
20001998
#[test]
20011999
fn test_switch_implies_cfg_test_unless_cfg_test() {
2002-
let dep_graph = DepGraph::new(false);
20032000
let matches =
20042001
&match optgroups().parse(&["--test".to_string(), "--cfg=test".to_string()]) {
20052002
Ok(m) => m,
@@ -2009,7 +2006,7 @@ mod tests {
20092006
};
20102007
let registry = errors::registry::Registry::new(&[]);
20112008
let (sessopts, cfg) = build_session_options_and_crate_config(matches);
2012-
let sess = build_session(sessopts, &dep_graph, None, registry);
2009+
let sess = build_session(sessopts, None, registry);
20132010
let cfg = build_configuration(&sess, cfg);
20142011
let mut test_items = cfg.iter().filter(|&&(name, _)| name == "test");
20152012
assert!(test_items.next().is_some());
@@ -2018,14 +2015,13 @@ mod tests {
20182015

20192016
#[test]
20202017
fn test_can_print_warnings() {
2021-
let dep_graph = DepGraph::new(false);
20222018
{
20232019
let matches = optgroups().parse(&[
20242020
"-Awarnings".to_string()
20252021
]).unwrap();
20262022
let registry = errors::registry::Registry::new(&[]);
20272023
let (sessopts, _) = build_session_options_and_crate_config(&matches);
2028-
let sess = build_session(sessopts, &dep_graph, None, registry);
2024+
let sess = build_session(sessopts, None, registry);
20292025
assert!(!sess.diagnostic().can_emit_warnings);
20302026
}
20312027

@@ -2036,7 +2032,7 @@ mod tests {
20362032
]).unwrap();
20372033
let registry = errors::registry::Registry::new(&[]);
20382034
let (sessopts, _) = build_session_options_and_crate_config(&matches);
2039-
let sess = build_session(sessopts, &dep_graph, None, registry);
2035+
let sess = build_session(sessopts, None, registry);
20402036
assert!(sess.diagnostic().can_emit_warnings);
20412037
}
20422038

@@ -2046,7 +2042,7 @@ mod tests {
20462042
]).unwrap();
20472043
let registry = errors::registry::Registry::new(&[]);
20482044
let (sessopts, _) = build_session_options_and_crate_config(&matches);
2049-
let sess = build_session(sessopts, &dep_graph, None, registry);
2045+
let sess = build_session(sessopts, None, registry);
20502046
assert!(sess.diagnostic().can_emit_warnings);
20512047
}
20522048
}

src/librustc/session/mod.rs

+29-12
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
pub use self::code_stats::{CodeStats, DataTypeKind, FieldInfo};
1212
pub use self::code_stats::{SizeKind, TypeSizeInfo, VariantInfo};
1313

14-
use dep_graph::DepGraph;
1514
use hir::def_id::{CrateNum, DefIndex};
1615

1716
use lint;
@@ -58,7 +57,6 @@ pub mod search_paths;
5857
// Represents the data associated with a compilation
5958
// session for a single crate.
6059
pub struct Session {
61-
pub dep_graph: DepGraph,
6260
pub target: config::Config,
6361
pub host: Target,
6462
pub opts: config::Options,
@@ -91,7 +89,7 @@ pub struct Session {
9189
// forms a unique global identifier for the crate. It is used to allow
9290
// multiple crates with the same name to coexist. See the
9391
// trans::back::symbol_names module for more information.
94-
pub crate_disambiguator: RefCell<Symbol>,
92+
pub crate_disambiguator: RefCell<Option<Symbol>>,
9593
pub features: RefCell<feature_gate::Features>,
9694

9795
/// The maximum recursion limit for potentially infinitely recursive
@@ -169,7 +167,10 @@ enum DiagnosticBuilderMethod {
169167

170168
impl Session {
171169
pub fn local_crate_disambiguator(&self) -> Symbol {
172-
*self.crate_disambiguator.borrow()
170+
match *self.crate_disambiguator.borrow() {
171+
Some(sym) => sym,
172+
None => bug!("accessing disambiguator before initialization"),
173+
}
173174
}
174175
pub fn struct_span_warn<'a, S: Into<MultiSpan>>(&'a self,
175176
sp: S,
@@ -501,9 +502,29 @@ impl Session {
501502
kind)
502503
}
503504

505+
pub fn set_incr_session_load_dep_graph(&self, load: bool) {
506+
let mut incr_comp_session = self.incr_comp_session.borrow_mut();
507+
508+
match *incr_comp_session {
509+
IncrCompSession::Active { ref mut load_dep_graph, .. } => {
510+
*load_dep_graph = load;
511+
}
512+
_ => {}
513+
}
514+
}
515+
516+
pub fn incr_session_load_dep_graph(&self) -> bool {
517+
let incr_comp_session = self.incr_comp_session.borrow();
518+
match *incr_comp_session {
519+
IncrCompSession::Active { load_dep_graph, .. } => load_dep_graph,
520+
_ => false,
521+
}
522+
}
523+
504524
pub fn init_incr_comp_session(&self,
505525
session_dir: PathBuf,
506-
lock_file: flock::Lock) {
526+
lock_file: flock::Lock,
527+
load_dep_graph: bool) {
507528
let mut incr_comp_session = self.incr_comp_session.borrow_mut();
508529

509530
if let IncrCompSession::NotInitialized = *incr_comp_session { } else {
@@ -513,6 +534,7 @@ impl Session {
513534
*incr_comp_session = IncrCompSession::Active {
514535
session_directory: session_dir,
515536
lock_file,
537+
load_dep_graph,
516538
};
517539
}
518540

@@ -617,22 +639,19 @@ impl Session {
617639
}
618640

619641
pub fn build_session(sopts: config::Options,
620-
dep_graph: &DepGraph,
621642
local_crate_source_file: Option<PathBuf>,
622643
registry: errors::registry::Registry)
623644
-> Session {
624645
let file_path_mapping = sopts.file_path_mapping();
625646

626647
build_session_with_codemap(sopts,
627-
dep_graph,
628648
local_crate_source_file,
629649
registry,
630650
Rc::new(codemap::CodeMap::new(file_path_mapping)),
631651
None)
632652
}
633653

634654
pub fn build_session_with_codemap(sopts: config::Options,
635-
dep_graph: &DepGraph,
636655
local_crate_source_file: Option<PathBuf>,
637656
registry: errors::registry::Registry,
638657
codemap: Rc<codemap::CodeMap>,
@@ -672,14 +691,12 @@ pub fn build_session_with_codemap(sopts: config::Options,
672691
emitter);
673692

674693
build_session_(sopts,
675-
dep_graph,
676694
local_crate_source_file,
677695
diagnostic_handler,
678696
codemap)
679697
}
680698

681699
pub fn build_session_(sopts: config::Options,
682-
dep_graph: &DepGraph,
683700
local_crate_source_file: Option<PathBuf>,
684701
span_diagnostic: errors::Handler,
685702
codemap: Rc<codemap::CodeMap>)
@@ -715,7 +732,6 @@ pub fn build_session_(sopts: config::Options,
715732
let working_dir = file_path_mapping.map_prefix(working_dir);
716733

717734
let sess = Session {
718-
dep_graph: dep_graph.clone(),
719735
target: target_cfg,
720736
host,
721737
opts: sopts,
@@ -735,7 +751,7 @@ pub fn build_session_(sopts: config::Options,
735751
plugin_attributes: RefCell::new(Vec::new()),
736752
crate_types: RefCell::new(Vec::new()),
737753
dependency_formats: RefCell::new(FxHashMap()),
738-
crate_disambiguator: RefCell::new(Symbol::intern("")),
754+
crate_disambiguator: RefCell::new(None),
739755
features: RefCell::new(feature_gate::Features::new()),
740756
recursion_limit: Cell::new(64),
741757
type_length_limit: Cell::new(1048576),
@@ -793,6 +809,7 @@ pub enum IncrCompSession {
793809
Active {
794810
session_directory: PathBuf,
795811
lock_file: flock::Lock,
812+
load_dep_graph: bool,
796813
},
797814
// This is the state after the session directory has been finalized. In this
798815
// state, the contents of the directory must not be modified any more.

src/librustc_driver/driver.rs

+26-10
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#![cfg_attr(not(feature="llvm"), allow(dead_code))]
1212

13+
use rustc::dep_graph::DepGraph;
1314
use rustc::hir::{self, map as hir_map};
1415
use rustc::hir::lowering::lower_crate;
1516
use rustc::ich::Fingerprint;
@@ -115,7 +116,7 @@ pub fn compile_input(sess: &Session,
115116
// We need nested scopes here, because the intermediate results can keep
116117
// large chunks of memory alive and we want to free them as soon as
117118
// possible to keep the peak memory usage low
118-
let (outputs, trans): (OutputFilenames, OngoingCrateTranslation) = {
119+
let (outputs, trans, dep_graph): (OutputFilenames, OngoingCrateTranslation, DepGraph) = {
119120
let krate = match phase_1_parse_input(control, sess, input) {
120121
Ok(krate) => krate,
121122
Err(mut parse_error) => {
@@ -144,7 +145,13 @@ pub fn compile_input(sess: &Session,
144145
::rustc_trans_utils::link::find_crate_name(Some(sess), &krate.attrs, input);
145146
let ExpansionResult { expanded_crate, defs, analysis, resolutions, mut hir_forest } = {
146147
phase_2_configure_and_expand(
147-
sess, &cstore, krate, registry, &crate_name, addl_plugins, control.make_glob_map,
148+
sess,
149+
&cstore,
150+
krate,
151+
registry,
152+
&crate_name,
153+
addl_plugins,
154+
control.make_glob_map,
148155
|expanded_crate| {
149156
let mut state = CompileState::state_after_expand(
150157
input, sess, outdir, output, &cstore, expanded_crate, &crate_name,
@@ -251,7 +258,7 @@ pub fn compile_input(sess: &Session,
251258
}
252259
}
253260

254-
Ok((outputs, trans))
261+
Ok((outputs, trans, tcx.dep_graph.clone()))
255262
})??
256263
};
257264

@@ -266,7 +273,7 @@ pub fn compile_input(sess: &Session,
266273
sess.code_stats.borrow().print_type_sizes();
267274
}
268275

269-
let (phase5_result, trans) = phase_5_run_llvm_passes(sess, trans);
276+
let (phase5_result, trans) = phase_5_run_llvm_passes(sess, &dep_graph, trans);
270277

271278
controller_entry_point!(after_llvm,
272279
sess,
@@ -624,7 +631,15 @@ pub fn phase_2_configure_and_expand<F>(sess: &Session,
624631
*sess.features.borrow_mut() = features;
625632

626633
*sess.crate_types.borrow_mut() = collect_crate_types(sess, &krate.attrs);
627-
*sess.crate_disambiguator.borrow_mut() = Symbol::intern(&compute_crate_disambiguator(sess));
634+
635+
let disambiguator = Symbol::intern(&compute_crate_disambiguator(sess));
636+
*sess.crate_disambiguator.borrow_mut() = Some(disambiguator);
637+
rustc_incremental::prepare_session_directory(
638+
sess,
639+
&crate_name,
640+
&disambiguator.as_str(),
641+
);
642+
let dep_graph = DepGraph::new(sess.opts.build_dep_graph());
628643

629644
time(time_passes, "recursion limit", || {
630645
middle::recursion_limit::update_limits(sess, &krate);
@@ -694,7 +709,7 @@ pub fn phase_2_configure_and_expand<F>(sess: &Session,
694709
// item, much like we do for macro expansion. In other words, the hash reflects not just
695710
// its contents but the results of name resolution on those contents. Hopefully we'll push
696711
// this back at some point.
697-
let _ignore = sess.dep_graph.in_ignore();
712+
let _ignore = dep_graph.in_ignore();
698713
let mut crate_loader = CrateLoader::new(sess, &cstore, crate_name);
699714
let resolver_arenas = Resolver::arenas();
700715
let mut resolver = Resolver::new(sess,
@@ -847,13 +862,13 @@ pub fn phase_2_configure_and_expand<F>(sess: &Session,
847862

848863
// Lower ast -> hir.
849864
let hir_forest = time(time_passes, "lowering ast -> hir", || {
850-
let hir_crate = lower_crate(sess, cstore, &krate, &mut resolver);
865+
let hir_crate = lower_crate(sess, cstore, &dep_graph, &krate, &mut resolver);
851866

852867
if sess.opts.debugging_opts.hir_stats {
853868
hir_stats::print_hir_stats(&hir_crate);
854869
}
855870

856-
hir_map::Forest::new(hir_crate, &sess.dep_graph)
871+
hir_map::Forest::new(hir_crate, &dep_graph)
857872
});
858873

859874
time(time_passes,
@@ -1134,17 +1149,18 @@ pub fn phase_4_translate_to_llvm<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
11341149
/// as a side effect.
11351150
#[cfg(feature="llvm")]
11361151
pub fn phase_5_run_llvm_passes(sess: &Session,
1152+
dep_graph: &DepGraph,
11371153
trans: write::OngoingCrateTranslation)
11381154
-> (CompileResult, trans::CrateTranslation) {
1139-
let trans = trans.join(sess);
1155+
let trans = trans.join(sess, dep_graph);
11401156

11411157
if sess.opts.debugging_opts.incremental_info {
11421158
write::dump_incremental_data(&trans);
11431159
}
11441160

11451161
time(sess.time_passes(),
11461162
"serialize work products",
1147-
move || rustc_incremental::save_work_products(sess));
1163+
move || rustc_incremental::save_work_products(sess, dep_graph));
11481164

11491165
(sess.compile_status(), trans)
11501166
}

src/librustc_driver/lib.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ use pretty::{PpMode, UserIdentifiedItem};
6464
use rustc_resolve as resolve;
6565
use rustc_save_analysis as save;
6666
use rustc_save_analysis::DumpHandler;
67-
use rustc::dep_graph::DepGraph;
6867
use rustc::session::{self, config, Session, build_session, CompileResult};
6968
use rustc::session::CompileIncomplete;
7069
use rustc::session::config::{Input, PrintRequest, OutputType, ErrorOutputType};
@@ -294,13 +293,12 @@ pub fn run_compiler<'a>(args: &[String],
294293
},
295294
};
296295

297-
let dep_graph = DepGraph::new(sopts.build_dep_graph());
298296
let cstore = Rc::new(CStore::new(box ::MetadataLoader));
299297

300298
let loader = file_loader.unwrap_or(box RealFileLoader);
301299
let codemap = Rc::new(CodeMap::with_file_loader(loader, sopts.file_path_mapping()));
302300
let mut sess = session::build_session_with_codemap(
303-
sopts, &dep_graph, input_file_path, descriptions, codemap, emitter_dest,
301+
sopts, input_file_path, descriptions, codemap, emitter_dest,
304302
);
305303
rustc_trans::init(&sess);
306304
rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess));
@@ -318,7 +316,13 @@ pub fn run_compiler<'a>(args: &[String],
318316

319317
let plugins = sess.opts.debugging_opts.extra_plugins.clone();
320318
let control = callbacks.build_controller(&sess, &matches);
321-
(driver::compile_input(&sess, &cstore, &input, &odir, &ofile, Some(plugins), &control),
319+
(driver::compile_input(&sess,
320+
&cstore,
321+
&input,
322+
&odir,
323+
&ofile,
324+
Some(plugins),
325+
&control),
322326
Some(sess))
323327
}
324328

@@ -580,9 +584,7 @@ impl<'a> CompilerCalls<'a> for RustcDefaultCalls {
580584
describe_lints(&ls, false);
581585
return None;
582586
}
583-
let dep_graph = DepGraph::new(sopts.build_dep_graph());
584587
let mut sess = build_session(sopts.clone(),
585-
&dep_graph,
586588
None,
587589
descriptions.clone());
588590
rustc_trans::init(&sess);

0 commit comments

Comments
 (0)