1010
1111#![ cfg_attr( not( feature="llvm" ) , allow( dead_code) ) ]
1212
13+ use rustc:: dep_graph:: DepGraph ;
1314use rustc:: hir:: { self , map as hir_map} ;
1415use rustc:: hir:: lowering:: lower_crate;
1516use 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" ) ]
11361151pub 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}
0 commit comments