@@ -34,7 +34,7 @@ use rustc_data_structures::profiling::{SelfProfiler, SelfProfilerRef};
3434use rustc_target:: spec:: { PanicStrategy , RelroLevel , Target , TargetTriple } ;
3535
3636use std;
37- use std:: cell:: { self , RefCell } ;
37+ use std:: cell:: RefCell ;
3838use std:: env;
3939use std:: fmt;
4040use std:: io:: Write ;
@@ -94,7 +94,7 @@ pub struct Session {
9494 /// macro name and definition span in the source crate.
9595 pub imported_macro_spans : OneThread < RefCell < FxHashMap < Span , ( String , Span ) > > > ,
9696
97- incr_comp_session : OneThread < RefCell < IncrCompSession > > ,
97+ incr_comp_session : Lock < IncrCompSession > ,
9898 /// Used for incremental compilation tests. Will only be populated if
9999 /// `-Zquery-dep-graph` is specified.
100100 pub cgu_reuse_tracker : CguReuseTracker ,
@@ -599,53 +599,41 @@ impl Session {
599599 )
600600 }
601601
602- pub fn set_incr_session_load_dep_graph ( & self , load : bool ) {
603- let mut incr_comp_session = self . incr_comp_session . borrow_mut ( ) ;
604-
605- if let IncrCompSession :: Active { ref mut load_dep_graph, .. } = * incr_comp_session {
606- * load_dep_graph = load;
607- }
608- }
609-
610- pub fn incr_session_load_dep_graph ( & self ) -> bool {
611- let incr_comp_session = self . incr_comp_session . borrow ( ) ;
612- match * incr_comp_session {
613- IncrCompSession :: Active { load_dep_graph, .. } => load_dep_graph,
614- _ => false ,
615- }
616- }
617-
618602 pub fn init_incr_comp_session (
619603 & self ,
620604 session_dir : PathBuf ,
621605 lock_file : flock:: Lock ,
622606 load_dep_graph : bool ,
623607 ) {
624- let mut incr_comp_session = self . incr_comp_session . borrow_mut ( ) ;
608+ let mut incr_comp_session = self . incr_comp_session . lock ( ) ;
625609
626610 if let IncrCompSession :: NotInitialized = * incr_comp_session {
627611 } else {
628612 panic ! ( "Trying to initialize IncrCompSession `{:?}`" , * incr_comp_session)
629613 }
630614
631- * incr_comp_session =
632- IncrCompSession :: Active { session_directory : session_dir, lock_file, load_dep_graph } ;
615+ * incr_comp_session = IncrCompSession :: Active {
616+ session_directory : Arc :: new ( session_dir) ,
617+ lock_file,
618+ load_dep_graph,
619+ } ;
633620 }
634621
635622 pub fn finalize_incr_comp_session ( & self , new_directory_path : PathBuf ) {
636- let mut incr_comp_session = self . incr_comp_session . borrow_mut ( ) ;
623+ let mut incr_comp_session = self . incr_comp_session . lock ( ) ;
637624
638625 if let IncrCompSession :: Active { .. } = * incr_comp_session {
639626 } else {
640627 panic ! ( "trying to finalize `IncrCompSession` `{:?}`" , * incr_comp_session) ;
641628 }
642629
643630 // Note: this will also drop the lock file, thus unlocking the directory.
644- * incr_comp_session = IncrCompSession :: Finalized { session_directory : new_directory_path } ;
631+ * incr_comp_session =
632+ IncrCompSession :: Finalized { session_directory : Arc :: new ( new_directory_path) } ;
645633 }
646634
647635 pub fn mark_incr_comp_session_as_invalid ( & self ) {
648- let mut incr_comp_session = self . incr_comp_session . borrow_mut ( ) ;
636+ let mut incr_comp_session = self . incr_comp_session . lock ( ) ;
649637
650638 let session_directory = match * incr_comp_session {
651639 IncrCompSession :: Active { ref session_directory, .. } => session_directory. clone ( ) ,
@@ -657,22 +645,21 @@ impl Session {
657645 * incr_comp_session = IncrCompSession :: InvalidBecauseOfErrors { session_directory } ;
658646 }
659647
660- pub fn incr_comp_session_dir ( & self ) -> cell:: Ref < ' _ , PathBuf > {
661- let incr_comp_session = self . incr_comp_session . borrow ( ) ;
662- cell:: Ref :: map ( incr_comp_session, |incr_comp_session| match * incr_comp_session {
663- IncrCompSession :: NotInitialized => panic ! (
664- "trying to get session directory from `IncrCompSession`: {:?}" ,
665- * incr_comp_session,
666- ) ,
648+ pub fn incr_comp_session_dir ( & self ) -> Arc < PathBuf > {
649+ let session = self . incr_comp_session . lock ( ) ;
650+ match * session {
651+ IncrCompSession :: NotInitialized => {
652+ panic ! ( "trying to get session directory from `IncrCompSession`: {:?}" , * session)
653+ }
667654 IncrCompSession :: Active { ref session_directory, .. }
668655 | IncrCompSession :: Finalized { ref session_directory }
669656 | IncrCompSession :: InvalidBecauseOfErrors { ref session_directory } => {
670- session_directory
657+ session_directory. clone ( )
671658 }
672- } )
659+ }
673660 }
674661
675- pub fn incr_comp_session_dir_opt ( & self ) -> Option < cell :: Ref < ' _ , PathBuf > > {
662+ pub fn incr_comp_session_dir_opt ( & self ) -> Option < Arc < PathBuf > > {
676663 self . opts . incremental . as_ref ( ) . map ( |_| self . incr_comp_session_dir ( ) )
677664 }
678665
@@ -1050,7 +1037,7 @@ fn build_session_(
10501037 recursion_limit : Once :: new ( ) ,
10511038 type_length_limit : Once :: new ( ) ,
10521039 imported_macro_spans : OneThread :: new ( RefCell :: new ( FxHashMap :: default ( ) ) ) ,
1053- incr_comp_session : OneThread :: new ( RefCell :: new ( IncrCompSession :: NotInitialized ) ) ,
1040+ incr_comp_session : Lock :: new ( IncrCompSession :: NotInitialized ) ,
10541041 cgu_reuse_tracker,
10551042 prof,
10561043 perf_stats : PerfStats {
@@ -1188,14 +1175,14 @@ pub enum IncrCompSession {
11881175 NotInitialized ,
11891176 /// This is the state during which the session directory is private and can
11901177 /// be modified.
1191- Active { session_directory : PathBuf , lock_file : flock:: Lock , load_dep_graph : bool } ,
1178+ Active { session_directory : Arc < PathBuf > , lock_file : flock:: Lock , load_dep_graph : bool } ,
11921179 /// This is the state after the session directory has been finalized. In this
11931180 /// state, the contents of the directory must not be modified any more.
1194- Finalized { session_directory : PathBuf } ,
1181+ Finalized { session_directory : Arc < PathBuf > } ,
11951182 /// This is an error state that is reached when some compilation error has
11961183 /// occurred. It indicates that the contents of the session directory must
11971184 /// not be used, since they might be invalid.
1198- InvalidBecauseOfErrors { session_directory : PathBuf } ,
1185+ InvalidBecauseOfErrors { session_directory : Arc < PathBuf > } ,
11991186}
12001187
12011188pub fn early_error ( output : config:: ErrorOutputType , msg : & str ) -> ! {
0 commit comments