Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 2d288a5

Browse files
committedSep 14, 2017
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

Lines changed: 3 additions & 1 deletion
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

Lines changed: 5 additions & 9 deletions
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

Lines changed: 29 additions & 12 deletions
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

Lines changed: 26 additions & 10 deletions
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

Lines changed: 8 additions & 6 deletions
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);

‎src/librustc_driver/test.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
//! # Standalone Tests for the Inference Module
1212
1313
use driver;
14-
use rustc::dep_graph::DepGraph;
1514
use rustc_lint;
1615
use rustc_resolve::MakeGlobMap;
1716
use rustc_trans;
@@ -102,11 +101,8 @@ fn test_env<F>(source_string: &str,
102101
options.unstable_features = UnstableFeatures::Allow;
103102
let diagnostic_handler = errors::Handler::with_emitter(true, false, emitter);
104103

105-
let dep_graph = DepGraph::new(false);
106-
let _ignore = dep_graph.in_ignore();
107104
let cstore = Rc::new(CStore::new(box ::MetadataLoader));
108105
let sess = session::build_session_(options,
109-
&dep_graph,
110106
None,
111107
diagnostic_handler,
112108
Rc::new(CodeMap::new(FilePathMapping::empty())));
@@ -130,7 +126,6 @@ fn test_env<F>(source_string: &str,
130126
|_| Ok(()))
131127
.expect("phase 2 aborted")
132128
};
133-
let _ignore = dep_graph.in_ignore();
134129

135130
let arena = DroplessArena::new();
136131
let arenas = ty::GlobalArenas::new();

‎src/librustc_incremental/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,5 @@ pub use persist::save_dep_graph;
4040
pub use persist::save_trans_partition;
4141
pub use persist::save_work_products;
4242
pub use persist::in_incr_comp_dir;
43+
pub use persist::prepare_session_directory;
4344
pub use persist::finalize_session_directory;

‎src/librustc_incremental/persist/fs.rs

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@
114114
//! unsupported file system and emit a warning in that case. This is not yet
115115
//! implemented.
116116
117-
use rustc::hir::def_id::{CrateNum, LOCAL_CRATE};
117+
use rustc::hir::def_id::CrateNum;
118118
use rustc::hir::svh::Svh;
119119
use rustc::session::Session;
120120
use rustc::ty::TyCtxt;
@@ -193,13 +193,21 @@ pub fn in_incr_comp_dir(incr_comp_session_dir: &Path, file_name: &str) -> PathBu
193193
/// a dep-graph and work products from a previous session.
194194
/// If the call fails, the fn may leave behind an invalid session directory.
195195
/// The garbage collection will take care of it.
196-
pub fn prepare_session_directory(tcx: TyCtxt) -> Result<bool, ()> {
196+
pub fn prepare_session_directory(sess: &Session,
197+
crate_name: &str,
198+
crate_disambiguator: &str) {
199+
if sess.opts.incremental.is_none() {
200+
return
201+
}
202+
197203
debug!("prepare_session_directory");
198204

199205
// {incr-comp-dir}/{crate-name-and-disambiguator}
200-
let crate_dir = crate_path_tcx(tcx, LOCAL_CRATE);
206+
let crate_dir = crate_path(sess, crate_name, crate_disambiguator);
201207
debug!("crate-dir: {}", crate_dir.display());
202-
try!(create_dir(tcx.sess, &crate_dir, "crate"));
208+
if create_dir(sess, &crate_dir, "crate").is_err() {
209+
return
210+
}
203211

204212
// Hack: canonicalize the path *after creating the directory*
205213
// because, on windows, long paths can cause problems;
@@ -208,9 +216,9 @@ pub fn prepare_session_directory(tcx: TyCtxt) -> Result<bool, ()> {
208216
let crate_dir = match crate_dir.canonicalize() {
209217
Ok(v) => v,
210218
Err(err) => {
211-
tcx.sess.err(&format!("incremental compilation: error canonicalizing path `{}`: {}",
212-
crate_dir.display(), err));
213-
return Err(());
219+
sess.err(&format!("incremental compilation: error canonicalizing path `{}`: {}",
220+
crate_dir.display(), err));
221+
return
214222
}
215223
};
216224

@@ -225,11 +233,16 @@ pub fn prepare_session_directory(tcx: TyCtxt) -> Result<bool, ()> {
225233

226234
// Lock the new session directory. If this fails, return an
227235
// error without retrying
228-
let (directory_lock, lock_file_path) = try!(lock_directory(tcx.sess, &session_dir));
236+
let (directory_lock, lock_file_path) = match lock_directory(sess, &session_dir) {
237+
Ok(e) => e,
238+
Err(_) => return,
239+
};
229240

230241
// Now that we have the lock, we can actually create the session
231242
// directory
232-
try!(create_dir(tcx.sess, &session_dir, "session"));
243+
if create_dir(sess, &session_dir, "session").is_err() {
244+
return
245+
}
233246

234247
// Find a suitable source directory to copy from. Ignore those that we
235248
// have already tried before.
@@ -243,14 +256,14 @@ pub fn prepare_session_directory(tcx: TyCtxt) -> Result<bool, ()> {
243256
debug!("no source directory found. Continuing with empty session \
244257
directory.");
245258

246-
tcx.sess.init_incr_comp_session(session_dir, directory_lock);
247-
return Ok(false)
259+
sess.init_incr_comp_session(session_dir, directory_lock, false);
260+
return
248261
};
249262

250263
debug!("attempting to copy data from source: {}",
251264
source_directory.display());
252265

253-
let print_file_copy_stats = tcx.sess.opts.debugging_opts.incremental_info;
266+
let print_file_copy_stats = sess.opts.debugging_opts.incremental_info;
254267

255268
// Try copying over all files from the source directory
256269
if let Ok(allows_links) = copy_files(&session_dir, &source_directory,
@@ -259,7 +272,7 @@ pub fn prepare_session_directory(tcx: TyCtxt) -> Result<bool, ()> {
259272
source_directory.display());
260273

261274
if !allows_links {
262-
tcx.sess.warn(&format!("Hard linking files in the incremental \
275+
sess.warn(&format!("Hard linking files in the incremental \
263276
compilation cache failed. Copying files \
264277
instead. Consider moving the cache \
265278
directory to a file system which supports \
@@ -268,8 +281,8 @@ pub fn prepare_session_directory(tcx: TyCtxt) -> Result<bool, ()> {
268281
);
269282
}
270283

271-
tcx.sess.init_incr_comp_session(session_dir, directory_lock);
272-
return Ok(true)
284+
sess.init_incr_comp_session(session_dir, directory_lock, true);
285+
return
273286
} else {
274287
debug!("copying failed - trying next directory");
275288

@@ -280,13 +293,13 @@ pub fn prepare_session_directory(tcx: TyCtxt) -> Result<bool, ()> {
280293
// Try to remove the session directory we just allocated. We don't
281294
// know if there's any garbage in it from the failed copy action.
282295
if let Err(err) = safe_remove_dir_all(&session_dir) {
283-
tcx.sess.warn(&format!("Failed to delete partly initialized \
284-
session dir `{}`: {}",
285-
session_dir.display(),
286-
err));
296+
sess.warn(&format!("Failed to delete partly initialized \
297+
session dir `{}`: {}",
298+
session_dir.display(),
299+
err));
287300
}
288301

289-
delete_session_dir_lock_file(tcx.sess, &lock_file_path);
302+
delete_session_dir_lock_file(sess, &lock_file_path);
290303
mem::drop(directory_lock);
291304
}
292305
}

‎src/librustc_incremental/persist/load.rs

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -42,30 +42,10 @@ pub type DirtyNodes = FxHashMap<DepNodeIndex, DepNodeIndex>;
4242
/// more general overview.
4343
pub fn load_dep_graph<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
4444
incremental_hashes_map: &IncrementalHashesMap) {
45-
if tcx.sess.opts.incremental.is_none() {
46-
return;
45+
if tcx.sess.incr_session_load_dep_graph() {
46+
let _ignore = tcx.dep_graph.in_ignore();
47+
load_dep_graph_if_exists(tcx, incremental_hashes_map);
4748
}
48-
49-
match prepare_session_directory(tcx) {
50-
Ok(true) => {
51-
// We successfully allocated a session directory and there is
52-
// something in it to load, so continue
53-
}
54-
Ok(false) => {
55-
// We successfully allocated a session directory, but there is no
56-
// dep-graph data in it to load (because this is the first
57-
// compilation session with this incr. comp. dir.)
58-
return
59-
}
60-
Err(()) => {
61-
// Something went wrong while trying to allocate the session
62-
// directory. Don't try to use it any further.
63-
return
64-
}
65-
}
66-
67-
let _ignore = tcx.dep_graph.in_ignore();
68-
load_dep_graph_if_exists(tcx, incremental_hashes_map);
6949
}
7050

7151
fn load_dep_graph_if_exists<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,

‎src/librustc_incremental/persist/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ mod save;
2222
mod work_product;
2323
mod file_format;
2424

25+
pub use self::fs::prepare_session_directory;
2526
pub use self::fs::finalize_session_directory;
2627
pub use self::fs::in_incr_comp_dir;
2728
pub use self::load::load_dep_graph;

‎src/librustc_incremental/persist/save.rs

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

11-
use rustc::dep_graph::DepNode;
11+
use rustc::dep_graph::{DepGraph, DepNode};
1212
use rustc::hir::def_id::DefId;
1313
use rustc::hir::svh::Svh;
1414
use rustc::ich::Fingerprint;
@@ -79,21 +79,21 @@ pub fn save_dep_graph<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
7979
&current_metadata_hashes);
8080
}
8181

82-
pub fn save_work_products(sess: &Session) {
82+
pub fn save_work_products(sess: &Session, dep_graph: &DepGraph) {
8383
if sess.opts.incremental.is_none() {
8484
return;
8585
}
8686

8787
debug!("save_work_products()");
88-
let _ignore = sess.dep_graph.in_ignore();
88+
let _ignore = dep_graph.in_ignore();
8989
let path = work_products_path(sess);
90-
save_in(sess, path, |e| encode_work_products(sess, e));
90+
save_in(sess, path, |e| encode_work_products(dep_graph, e));
9191

9292
// We also need to clean out old work-products, as not all of them are
9393
// deleted during invalidation. Some object files don't change their
9494
// content, they are just not needed anymore.
95-
let new_work_products = sess.dep_graph.work_products();
96-
let previous_work_products = sess.dep_graph.previous_work_products();
95+
let new_work_products = dep_graph.work_products();
96+
let previous_work_products = dep_graph.previous_work_products();
9797

9898
for (id, wp) in previous_work_products.iter() {
9999
if !new_work_products.contains_key(id) {
@@ -309,8 +309,9 @@ pub fn encode_metadata_hashes(tcx: TyCtxt,
309309
Ok(())
310310
}
311311

312-
pub fn encode_work_products(sess: &Session, encoder: &mut Encoder) -> io::Result<()> {
313-
let work_products: Vec<_> = sess.dep_graph
312+
pub fn encode_work_products(dep_graph: &DepGraph,
313+
encoder: &mut Encoder) -> io::Result<()> {
314+
let work_products: Vec<_> = dep_graph
314315
.work_products()
315316
.iter()
316317
.map(|(id, work_product)| {

‎src/librustc_incremental/persist/work_product.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,15 @@
1111
//! This module contains files for saving intermediate work-products.
1212
1313
use persist::fs::*;
14-
use rustc::dep_graph::{WorkProduct, WorkProductId};
14+
use rustc::dep_graph::{WorkProduct, WorkProductId, DepGraph};
1515
use rustc::session::Session;
1616
use rustc::session::config::OutputType;
1717
use rustc::util::fs::link_or_copy;
1818
use std::path::PathBuf;
1919
use std::fs as std_fs;
2020

2121
pub fn save_trans_partition(sess: &Session,
22+
dep_graph: &DepGraph,
2223
cgu_name: &str,
2324
partition_hash: u64,
2425
files: &[(OutputType, PathBuf)]) {
@@ -60,7 +61,7 @@ pub fn save_trans_partition(sess: &Session,
6061
saved_files,
6162
};
6263

63-
sess.dep_graph.insert_work_product(&work_product_id, work_product);
64+
dep_graph.insert_work_product(&work_product_id, work_product);
6465
}
6566

6667
pub fn delete_workproduct_files(sess: &Session, work_product: &WorkProduct) {

‎src/librustc_trans/back/write.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use back::link::{self, get_linker, remove};
1313
use back::linker::LinkerInfo;
1414
use back::symbol_export::ExportedSymbols;
1515
use rustc_incremental::{save_trans_partition, in_incr_comp_dir};
16+
use rustc::dep_graph::DepGraph;
1617
use rustc::middle::cstore::{LinkMeta, EncodedMetadata};
1718
use rustc::session::config::{self, OutputFilenames, OutputType, OutputTypes, Passes, SomePasses,
1819
AllPasses, Sanitizer};
@@ -807,6 +808,7 @@ pub fn start_async_translation(sess: &Session,
807808
}
808809

809810
fn copy_module_artifacts_into_incr_comp_cache(sess: &Session,
811+
dep_graph: &DepGraph,
810812
compiled_modules: &CompiledModules,
811813
crate_output: &OutputFilenames) {
812814
if sess.opts.incremental.is_none() {
@@ -826,7 +828,11 @@ fn copy_module_artifacts_into_incr_comp_cache(sess: &Session,
826828
files.push((OutputType::Bitcode, path));
827829
}
828830

829-
save_trans_partition(sess, &module.name, module.symbol_name_hash, &files);
831+
save_trans_partition(sess,
832+
dep_graph,
833+
&module.name,
834+
module.symbol_name_hash,
835+
&files);
830836
}
831837
}
832838

@@ -1822,7 +1828,7 @@ pub struct OngoingCrateTranslation {
18221828
}
18231829

18241830
impl OngoingCrateTranslation {
1825-
pub fn join(self, sess: &Session) -> CrateTranslation {
1831+
pub fn join(self, sess: &Session, dep_graph: &DepGraph) -> CrateTranslation {
18261832
self.shared_emitter_main.check(sess, true);
18271833
let compiled_modules = match self.future.join() {
18281834
Ok(compiled_modules) => compiled_modules,
@@ -1838,6 +1844,7 @@ impl OngoingCrateTranslation {
18381844
}
18391845

18401846
copy_module_artifacts_into_incr_comp_cache(sess,
1847+
dep_graph,
18411848
&compiled_modules,
18421849
&self.output_filenames);
18431850
produce_final_output_artifacts(sess,

‎src/librustdoc/core.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
use rustc_lint;
1212
use rustc_driver::{driver, target_features, abort_on_err};
1313
use rustc_driver::pretty::ReplaceBodyWithLoop;
14-
use rustc::dep_graph::DepGraph;
1514
use rustc::session::{self, config};
1615
use rustc::hir::def_id::DefId;
1716
use rustc::hir::def::Def;
@@ -144,11 +143,9 @@ pub fn run_core(search_paths: SearchPaths,
144143
false,
145144
Some(codemap.clone()));
146145

147-
let dep_graph = DepGraph::new(false);
148-
let _ignore = dep_graph.in_ignore();
149146
let cstore = Rc::new(CStore::new(box rustc_trans::LlvmMetadataLoader));
150147
let mut sess = session::build_session_(
151-
sessopts, &dep_graph, cpath, diagnostic_handler, codemap
148+
sessopts, cpath, diagnostic_handler, codemap,
152149
);
153150
rustc_trans::init(&sess);
154151
rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess));

‎src/librustdoc/test.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ use std::sync::{Arc, Mutex};
2222

2323
use testing;
2424
use rustc_lint;
25-
use rustc::dep_graph::DepGraph;
2625
use rustc::hir;
2726
use rustc::hir::intravisit;
2827
use rustc::session::{self, CompileIncomplete, config};
@@ -83,11 +82,9 @@ pub fn run(input: &str,
8382
let handler =
8483
errors::Handler::with_tty_emitter(ColorConfig::Auto, true, false, Some(codemap.clone()));
8584

86-
let dep_graph = DepGraph::new(false);
87-
let _ignore = dep_graph.in_ignore();
8885
let cstore = Rc::new(CStore::new(box rustc_trans::LlvmMetadataLoader));
8986
let mut sess = session::build_session_(
90-
sessopts, &dep_graph, Some(input_path.clone()), handler, codemap.clone()
87+
sessopts, Some(input_path.clone()), handler, codemap.clone(),
9188
);
9289
rustc_trans::init(&sess);
9390
rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess));
@@ -100,7 +97,14 @@ pub fn run(input: &str,
10097
let krate = ReplaceBodyWithLoop::new().fold_crate(krate);
10198
let driver::ExpansionResult { defs, mut hir_forest, .. } = {
10299
phase_2_configure_and_expand(
103-
&sess, &cstore, krate, None, "rustdoc-test", None, MakeGlobMap::No, |_| Ok(())
100+
&sess,
101+
&cstore,
102+
krate,
103+
None,
104+
"rustdoc-test",
105+
None,
106+
MakeGlobMap::No,
107+
|_| Ok(()),
104108
).expect("phase_2_configure_and_expand aborted in rustdoc!")
105109
};
106110

@@ -120,8 +124,6 @@ pub fn run(input: &str,
120124
render_type);
121125

122126
{
123-
let dep_graph = DepGraph::new(false);
124-
let _ignore = dep_graph.in_ignore();
125127
let map = hir::map::map_crate(&mut hir_forest, defs);
126128
let krate = map.krate();
127129
let mut hir_collector = HirCollector {
@@ -237,10 +239,9 @@ fn run_test(test: &str, cratename: &str, filename: &str, cfgs: Vec<String>, libs
237239
// Compile the code
238240
let diagnostic_handler = errors::Handler::with_emitter(true, false, box emitter);
239241

240-
let dep_graph = DepGraph::new(false);
241242
let cstore = Rc::new(CStore::new(box rustc_trans::LlvmMetadataLoader));
242243
let mut sess = session::build_session_(
243-
sessopts, &dep_graph, None, diagnostic_handler, codemap
244+
sessopts, None, diagnostic_handler, codemap,
244245
);
245246
rustc_trans::init(&sess);
246247
rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess));

‎src/test/run-make/issue-19371/foo.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,8 @@ fn basic_sess(sysroot: PathBuf) -> (Session, Rc<CStore>) {
5858
opts.maybe_sysroot = Some(sysroot);
5959

6060
let descriptions = Registry::new(&rustc::DIAGNOSTICS);
61-
let dep_graph = DepGraph::new(opts.build_dep_graph());
6261
let cstore = Rc::new(CStore::new(Box::new(rustc_trans::LlvmMetadataLoader)));
63-
let sess = build_session(opts, &dep_graph, None, descriptions);
62+
let sess = build_session(opts, None, descriptions);
6463
rustc_trans::init(&sess);
6564
rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess));
6665
(sess, cstore)

0 commit comments

Comments
 (0)
Please sign in to comment.