@@ -26,7 +26,10 @@ use util::common::{duration_to_secs_str, ErrorReported};
2626use util:: common:: ProfileQueriesMsg ;
2727
2828use rustc_data_structures:: base_n;
29- use rustc_data_structures:: sync:: { self , Lrc , Lock , LockCell , OneThread , Once , RwLock } ;
29+ use rustc_data_structures:: sync:: {
30+ self , Lrc , Lock , OneThread , Once , RwLock , AtomicU64 , AtomicUsize , AtomicBool , Ordering ,
31+ Ordering :: SeqCst ,
32+ } ;
3033
3134use errors:: { self , DiagnosticBuilder , DiagnosticId , Applicability } ;
3235use errors:: emitter:: { Emitter , EmitterWriter } ;
@@ -51,7 +54,6 @@ use std::io::Write;
5154use std:: path:: { Path , PathBuf } ;
5255use std:: time:: Duration ;
5356use std:: sync:: mpsc;
54- use std:: sync:: atomic:: { AtomicUsize , Ordering } ;
5557
5658mod code_stats;
5759pub mod config;
@@ -142,15 +144,15 @@ pub struct Session {
142144 /// If -zfuel=crate=n is specified, Some(crate).
143145 optimization_fuel_crate : Option < String > ,
144146 /// If -zfuel=crate=n is specified, initially set to n. Otherwise 0.
145- optimization_fuel_limit : LockCell < u64 > ,
147+ optimization_fuel_limit : AtomicU64 ,
146148 /// We're rejecting all further optimizations.
147- out_of_fuel : LockCell < bool > ,
149+ out_of_fuel : AtomicBool ,
148150
149151 // The next two are public because the driver needs to read them.
150152 /// If -zprint-fuel=crate, Some(crate).
151153 pub print_fuel_crate : Option < String > ,
152154 /// Always set to zero and incremented so that we can print fuel expended by a crate.
153- pub print_fuel : LockCell < u64 > ,
155+ pub print_fuel : AtomicU64 ,
154156
155157 /// Loaded up early on in the initialization of this `Session` to avoid
156158 /// false positives about a job server in our environment.
@@ -859,32 +861,43 @@ impl Session {
859861 self . perf_stats. normalize_projection_ty. load( Ordering :: Relaxed ) ) ;
860862 }
861863
862- /// We want to know if we're allowed to do an optimization for crate foo from -z fuel=foo=n.
863- /// This expends fuel if applicable, and records fuel if applicable.
864- pub fn consider_optimizing < T : Fn ( ) -> String > ( & self , crate_name : & str , msg : T ) -> bool {
864+ # [ inline ( never ) ]
865+ # [ cold ]
866+ pub fn consider_optimizing_cold < T : Fn ( ) -> String > ( & self , crate_name : & str , msg : T ) -> bool {
865867 let mut ret = true ;
866868 if let Some ( ref c) = self . optimization_fuel_crate {
867869 if c == crate_name {
868870 assert_eq ! ( self . query_threads( ) , 1 ) ;
869- let fuel = self . optimization_fuel_limit . get ( ) ;
871+ let fuel = self . optimization_fuel_limit . load ( SeqCst ) ;
870872 ret = fuel != 0 ;
871- if fuel == 0 && !self . out_of_fuel . get ( ) {
873+ if fuel == 0 && !self . out_of_fuel . load ( SeqCst ) {
872874 eprintln ! ( "optimization-fuel-exhausted: {}" , msg( ) ) ;
873- self . out_of_fuel . set ( true ) ;
875+ self . out_of_fuel . store ( true , SeqCst ) ;
874876 } else if fuel > 0 {
875- self . optimization_fuel_limit . set ( fuel - 1 ) ;
877+ self . optimization_fuel_limit . store ( fuel - 1 , SeqCst ) ;
876878 }
877879 }
878880 }
879881 if let Some ( ref c) = self . print_fuel_crate {
880882 if c == crate_name {
881883 assert_eq ! ( self . query_threads( ) , 1 ) ;
882- self . print_fuel . set ( self . print_fuel . get ( ) + 1 ) ;
884+ self . print_fuel . store ( self . print_fuel . load ( SeqCst ) + 1 , SeqCst ) ;
883885 }
884886 }
885887 ret
886888 }
887889
890+ /// We want to know if we're allowed to do an optimization for crate foo from -z fuel=foo=n.
891+ /// This expends fuel if applicable, and records fuel if applicable.
892+ #[ inline( always) ]
893+ pub fn consider_optimizing < T : Fn ( ) -> String > ( & self , crate_name : & str , msg : T ) -> bool {
894+ if likely ! ( self . optimization_fuel_crate. is_none( ) && self . print_fuel_crate. is_none( ) ) {
895+ true
896+ } else {
897+ self . consider_optimizing_cold ( crate_name, msg)
898+ }
899+ }
900+
888901 /// Returns the number of query threads that should be used for this
889902 /// compilation
890903 pub fn query_threads_from_opts ( opts : & config:: Options ) -> usize {
@@ -1121,9 +1134,9 @@ pub fn build_session_(
11211134
11221135 let optimization_fuel_crate = sopts. debugging_opts . fuel . as_ref ( ) . map ( |i| i. 0 . clone ( ) ) ;
11231136 let optimization_fuel_limit =
1124- LockCell :: new ( sopts. debugging_opts . fuel . as_ref ( ) . map ( |i| i. 1 ) . unwrap_or ( 0 ) ) ;
1137+ AtomicU64 :: new ( sopts. debugging_opts . fuel . as_ref ( ) . map ( |i| i. 1 ) . unwrap_or ( 0 ) ) ;
11251138 let print_fuel_crate = sopts. debugging_opts . print_fuel . clone ( ) ;
1126- let print_fuel = LockCell :: new ( 0 ) ;
1139+ let print_fuel = AtomicU64 :: new ( 0 ) ;
11271140
11281141 let working_dir = env:: current_dir ( ) . unwrap_or_else ( |e|
11291142 p_s. span_diagnostic
@@ -1182,7 +1195,7 @@ pub fn build_session_(
11821195 optimization_fuel_limit,
11831196 print_fuel_crate,
11841197 print_fuel,
1185- out_of_fuel : LockCell :: new ( false ) ,
1198+ out_of_fuel : AtomicBool :: new ( false ) ,
11861199 // Note that this is unsafe because it may misinterpret file descriptors
11871200 // on Unix as jobserver file descriptors. We hopefully execute this near
11881201 // the beginning of the process though to ensure we don't get false
0 commit comments