@@ -26,7 +26,10 @@ use util::common::{duration_to_secs_str, ErrorReported};
26
26
use util:: common:: ProfileQueriesMsg ;
27
27
28
28
use 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
+ } ;
30
33
31
34
use errors:: { self , DiagnosticBuilder , DiagnosticId , Applicability } ;
32
35
use errors:: emitter:: { Emitter , EmitterWriter } ;
@@ -51,7 +54,6 @@ use std::io::Write;
51
54
use std:: path:: { Path , PathBuf } ;
52
55
use std:: time:: Duration ;
53
56
use std:: sync:: mpsc;
54
- use std:: sync:: atomic:: { AtomicUsize , Ordering } ;
55
57
56
58
mod code_stats;
57
59
pub mod config;
@@ -142,15 +144,15 @@ pub struct Session {
142
144
/// If -zfuel=crate=n is specified, Some(crate).
143
145
optimization_fuel_crate : Option < String > ,
144
146
/// If -zfuel=crate=n is specified, initially set to n. Otherwise 0.
145
- optimization_fuel_limit : LockCell < u64 > ,
147
+ optimization_fuel_limit : AtomicU64 ,
146
148
/// We're rejecting all further optimizations.
147
- out_of_fuel : LockCell < bool > ,
149
+ out_of_fuel : AtomicBool ,
148
150
149
151
// The next two are public because the driver needs to read them.
150
152
/// If -zprint-fuel=crate, Some(crate).
151
153
pub print_fuel_crate : Option < String > ,
152
154
/// 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 ,
154
156
155
157
/// Loaded up early on in the initialization of this `Session` to avoid
156
158
/// false positives about a job server in our environment.
@@ -868,32 +870,43 @@ impl Session {
868
870
self . perf_stats. normalize_projection_ty. load( Ordering :: Relaxed ) ) ;
869
871
}
870
872
871
- /// We want to know if we're allowed to do an optimization for crate foo from -z fuel=foo=n.
872
- /// This expends fuel if applicable, and records fuel if applicable.
873
- pub fn consider_optimizing < T : Fn ( ) -> String > ( & self , crate_name : & str , msg : T ) -> bool {
873
+ # [ inline ( never ) ]
874
+ # [ cold ]
875
+ pub fn consider_optimizing_cold < T : Fn ( ) -> String > ( & self , crate_name : & str , msg : T ) -> bool {
874
876
let mut ret = true ;
875
877
if let Some ( ref c) = self . optimization_fuel_crate {
876
878
if c == crate_name {
877
879
assert_eq ! ( self . query_threads( ) , 1 ) ;
878
- let fuel = self . optimization_fuel_limit . get ( ) ;
880
+ let fuel = self . optimization_fuel_limit . load ( SeqCst ) ;
879
881
ret = fuel != 0 ;
880
- if fuel == 0 && !self . out_of_fuel . get ( ) {
882
+ if fuel == 0 && !self . out_of_fuel . load ( SeqCst ) {
881
883
eprintln ! ( "optimization-fuel-exhausted: {}" , msg( ) ) ;
882
- self . out_of_fuel . set ( true ) ;
884
+ self . out_of_fuel . store ( true , SeqCst ) ;
883
885
} else if fuel > 0 {
884
- self . optimization_fuel_limit . set ( fuel - 1 ) ;
886
+ self . optimization_fuel_limit . store ( fuel - 1 , SeqCst ) ;
885
887
}
886
888
}
887
889
}
888
890
if let Some ( ref c) = self . print_fuel_crate {
889
891
if c == crate_name {
890
892
assert_eq ! ( self . query_threads( ) , 1 ) ;
891
- self . print_fuel . set ( self . print_fuel . get ( ) + 1 ) ;
893
+ self . print_fuel . store ( self . print_fuel . load ( SeqCst ) + 1 , SeqCst ) ;
892
894
}
893
895
}
894
896
ret
895
897
}
896
898
899
+ /// We want to know if we're allowed to do an optimization for crate foo from -z fuel=foo=n.
900
+ /// This expends fuel if applicable, and records fuel if applicable.
901
+ #[ inline( always) ]
902
+ pub fn consider_optimizing < T : Fn ( ) -> String > ( & self , crate_name : & str , msg : T ) -> bool {
903
+ if likely ! ( self . optimization_fuel_crate. is_none( ) ) {
904
+ true
905
+ } else {
906
+ self . consider_optimizing_cold ( crate_name, msg)
907
+ }
908
+ }
909
+
897
910
/// Returns the number of query threads that should be used for this
898
911
/// compilation
899
912
pub fn query_threads_from_opts ( opts : & config:: Options ) -> usize {
@@ -1130,9 +1143,9 @@ pub fn build_session_(
1130
1143
1131
1144
let optimization_fuel_crate = sopts. debugging_opts . fuel . as_ref ( ) . map ( |i| i. 0 . clone ( ) ) ;
1132
1145
let optimization_fuel_limit =
1133
- LockCell :: new ( sopts. debugging_opts . fuel . as_ref ( ) . map ( |i| i. 1 ) . unwrap_or ( 0 ) ) ;
1146
+ AtomicU64 :: new ( sopts. debugging_opts . fuel . as_ref ( ) . map ( |i| i. 1 ) . unwrap_or ( 0 ) ) ;
1134
1147
let print_fuel_crate = sopts. debugging_opts . print_fuel . clone ( ) ;
1135
- let print_fuel = LockCell :: new ( 0 ) ;
1148
+ let print_fuel = AtomicU64 :: new ( 0 ) ;
1136
1149
1137
1150
let working_dir = env:: current_dir ( ) . unwrap_or_else ( |e|
1138
1151
p_s. span_diagnostic
@@ -1191,7 +1204,7 @@ pub fn build_session_(
1191
1204
optimization_fuel_limit,
1192
1205
print_fuel_crate,
1193
1206
print_fuel,
1194
- out_of_fuel : LockCell :: new ( false ) ,
1207
+ out_of_fuel : AtomicBool :: new ( false ) ,
1195
1208
// Note that this is unsafe because it may misinterpret file descriptors
1196
1209
// on Unix as jobserver file descriptors. We hopefully execute this near
1197
1210
// the beginning of the process though to ensure we don't get false
0 commit comments