@@ -34,7 +34,7 @@ use rustc_data_structures::profiling::{SelfProfiler, SelfProfilerRef};
34
34
use rustc_target:: spec:: { PanicStrategy , RelroLevel , Target , TargetTriple } ;
35
35
36
36
use std;
37
- use std:: cell:: { self , RefCell } ;
37
+ use std:: cell:: RefCell ;
38
38
use std:: env;
39
39
use std:: fmt;
40
40
use std:: io:: Write ;
@@ -94,7 +94,7 @@ pub struct Session {
94
94
/// macro name and definition span in the source crate.
95
95
pub imported_macro_spans : OneThread < RefCell < FxHashMap < Span , ( String , Span ) > > > ,
96
96
97
- incr_comp_session : OneThread < RefCell < IncrCompSession > > ,
97
+ incr_comp_session : Lock < IncrCompSession > ,
98
98
/// Used for incremental compilation tests. Will only be populated if
99
99
/// `-Zquery-dep-graph` is specified.
100
100
pub cgu_reuse_tracker : CguReuseTracker ,
@@ -599,53 +599,41 @@ impl Session {
599
599
)
600
600
}
601
601
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
-
618
602
pub fn init_incr_comp_session (
619
603
& self ,
620
604
session_dir : PathBuf ,
621
605
lock_file : flock:: Lock ,
622
606
load_dep_graph : bool ,
623
607
) {
624
- let mut incr_comp_session = self . incr_comp_session . borrow_mut ( ) ;
608
+ let mut incr_comp_session = self . incr_comp_session . lock ( ) ;
625
609
626
610
if let IncrCompSession :: NotInitialized = * incr_comp_session {
627
611
} else {
628
612
panic ! ( "Trying to initialize IncrCompSession `{:?}`" , * incr_comp_session)
629
613
}
630
614
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
+ } ;
633
620
}
634
621
635
622
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 ( ) ;
637
624
638
625
if let IncrCompSession :: Active { .. } = * incr_comp_session {
639
626
} else {
640
627
panic ! ( "trying to finalize `IncrCompSession` `{:?}`" , * incr_comp_session) ;
641
628
}
642
629
643
630
// 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) } ;
645
633
}
646
634
647
635
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 ( ) ;
649
637
650
638
let session_directory = match * incr_comp_session {
651
639
IncrCompSession :: Active { ref session_directory, .. } => session_directory. clone ( ) ,
@@ -657,22 +645,21 @@ impl Session {
657
645
* incr_comp_session = IncrCompSession :: InvalidBecauseOfErrors { session_directory } ;
658
646
}
659
647
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
+ }
667
654
IncrCompSession :: Active { ref session_directory, .. }
668
655
| IncrCompSession :: Finalized { ref session_directory }
669
656
| IncrCompSession :: InvalidBecauseOfErrors { ref session_directory } => {
670
- session_directory
657
+ session_directory. clone ( )
671
658
}
672
- } )
659
+ }
673
660
}
674
661
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 > > {
676
663
self . opts . incremental . as_ref ( ) . map ( |_| self . incr_comp_session_dir ( ) )
677
664
}
678
665
@@ -1050,7 +1037,7 @@ fn build_session_(
1050
1037
recursion_limit : Once :: new ( ) ,
1051
1038
type_length_limit : Once :: new ( ) ,
1052
1039
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 ) ,
1054
1041
cgu_reuse_tracker,
1055
1042
prof,
1056
1043
perf_stats : PerfStats {
@@ -1188,14 +1175,14 @@ pub enum IncrCompSession {
1188
1175
NotInitialized ,
1189
1176
/// This is the state during which the session directory is private and can
1190
1177
/// 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 } ,
1192
1179
/// This is the state after the session directory has been finalized. In this
1193
1180
/// state, the contents of the directory must not be modified any more.
1194
- Finalized { session_directory : PathBuf } ,
1181
+ Finalized { session_directory : Arc < PathBuf > } ,
1195
1182
/// This is an error state that is reached when some compilation error has
1196
1183
/// occurred. It indicates that the contents of the session directory must
1197
1184
/// not be used, since they might be invalid.
1198
- InvalidBecauseOfErrors { session_directory : PathBuf } ,
1185
+ InvalidBecauseOfErrors { session_directory : Arc < PathBuf > } ,
1199
1186
}
1200
1187
1201
1188
pub fn early_error ( output : config:: ErrorOutputType , msg : & str ) -> ! {
0 commit comments