@@ -17,7 +17,7 @@ use util::common::ProfileQueriesMsg;
17
17
18
18
use rustc_data_structures:: base_n;
19
19
use rustc_data_structures:: sync:: {
20
- self , Lrc , Lock , OneThread , Once , RwLock , AtomicU64 , AtomicUsize , AtomicBool , Ordering ,
20
+ self , Lrc , Lock , OneThread , Once , RwLock , AtomicU64 , AtomicUsize , Ordering ,
21
21
Ordering :: SeqCst ,
22
22
} ;
23
23
@@ -50,6 +50,13 @@ pub mod config;
50
50
pub mod filesearch;
51
51
pub mod search_paths;
52
52
53
+ pub struct OptimizationFuel {
54
+ /// If -zfuel=crate=n is specified, initially set to n. Otherwise 0.
55
+ remaining : u64 ,
56
+ /// We're rejecting all further optimizations.
57
+ out_of_fuel : bool ,
58
+ }
59
+
53
60
/// Represents the data associated with a compilation
54
61
/// session for a single crate.
55
62
pub struct Session {
@@ -139,10 +146,9 @@ pub struct Session {
139
146
140
147
/// If -zfuel=crate=n is specified, Some(crate).
141
148
optimization_fuel_crate : Option < String > ,
142
- /// If -zfuel=crate=n is specified, initially set to n. Otherwise 0.
143
- optimization_fuel_limit : AtomicU64 ,
144
- /// We're rejecting all further optimizations.
145
- out_of_fuel : AtomicBool ,
149
+
150
+ /// Tracks fuel info if If -zfuel=crate=n is specified
151
+ optimization_fuel : Lock < OptimizationFuel > ,
146
152
147
153
// The next two are public because the driver needs to read them.
148
154
/// If -zprint-fuel=crate, Some(crate).
@@ -859,43 +865,32 @@ impl Session {
859
865
self . perf_stats. normalize_projection_ty. load( Ordering :: Relaxed ) ) ;
860
866
}
861
867
862
- # [ inline ( never ) ]
863
- # [ cold ]
864
- pub fn consider_optimizing_cold < T : Fn ( ) -> String > ( & self , crate_name : & str , msg : T ) -> bool {
868
+ /// We want to know if we're allowed to do an optimization for crate foo from -z fuel=foo=n.
869
+ /// This expends fuel if applicable, and records fuel if applicable.
870
+ pub fn consider_optimizing < T : Fn ( ) -> String > ( & self , crate_name : & str , msg : T ) -> bool {
865
871
let mut ret = true ;
866
872
if let Some ( ref c) = self . optimization_fuel_crate {
867
873
if c == crate_name {
868
874
assert_eq ! ( self . query_threads( ) , 1 ) ;
869
- let fuel = self . optimization_fuel_limit . load ( SeqCst ) ;
870
- ret = fuel != 0 ;
871
- if fuel == 0 && !self . out_of_fuel . load ( SeqCst ) {
875
+ let mut fuel = self . optimization_fuel . lock ( ) ;
876
+ ret = fuel. remaining != 0 ;
877
+ if fuel. remaining == 0 && !fuel . out_of_fuel {
872
878
eprintln ! ( "optimization-fuel-exhausted: {}" , msg( ) ) ;
873
- self . out_of_fuel . store ( true , SeqCst ) ;
874
- } else if fuel > 0 {
875
- self . optimization_fuel_limit . store ( fuel - 1 , SeqCst ) ;
879
+ fuel . out_of_fuel = true ;
880
+ } else if fuel. remaining > 0 {
881
+ fuel. remaining -= 1 ;
876
882
}
877
883
}
878
884
}
879
885
if let Some ( ref c) = self . print_fuel_crate {
880
886
if c == crate_name {
881
887
assert_eq ! ( self . query_threads( ) , 1 ) ;
882
- self . print_fuel . store ( self . print_fuel . load ( SeqCst ) + 1 , SeqCst ) ;
888
+ self . print_fuel . fetch_add ( 1 , SeqCst ) ;
883
889
}
884
890
}
885
891
ret
886
892
}
887
893
888
- /// We want to know if we're allowed to do an optimization for crate foo from -z fuel=foo=n.
889
- /// This expends fuel if applicable, and records fuel if applicable.
890
- #[ inline( always) ]
891
- pub fn consider_optimizing < T : Fn ( ) -> String > ( & self , crate_name : & str , msg : T ) -> bool {
892
- if likely ! ( self . optimization_fuel_crate. is_none( ) && self . print_fuel_crate. is_none( ) ) {
893
- true
894
- } else {
895
- self . consider_optimizing_cold ( crate_name, msg)
896
- }
897
- }
898
-
899
894
/// Returns the number of query threads that should be used for this
900
895
/// compilation
901
896
pub fn query_threads_from_opts ( opts : & config:: Options ) -> usize {
@@ -1140,8 +1135,10 @@ pub fn build_session_(
1140
1135
local_crate_source_file. map ( |path| file_path_mapping. map_prefix ( path) . 0 ) ;
1141
1136
1142
1137
let optimization_fuel_crate = sopts. debugging_opts . fuel . as_ref ( ) . map ( |i| i. 0 . clone ( ) ) ;
1143
- let optimization_fuel_limit =
1144
- AtomicU64 :: new ( sopts. debugging_opts . fuel . as_ref ( ) . map ( |i| i. 1 ) . unwrap_or ( 0 ) ) ;
1138
+ let optimization_fuel = Lock :: new ( OptimizationFuel {
1139
+ remaining : sopts. debugging_opts . fuel . as_ref ( ) . map ( |i| i. 1 ) . unwrap_or ( 0 ) ,
1140
+ out_of_fuel : false ,
1141
+ } ) ;
1145
1142
let print_fuel_crate = sopts. debugging_opts . print_fuel . clone ( ) ;
1146
1143
let print_fuel = AtomicU64 :: new ( 0 ) ;
1147
1144
@@ -1205,10 +1202,9 @@ pub fn build_session_(
1205
1202
} ,
1206
1203
code_stats : Default :: default ( ) ,
1207
1204
optimization_fuel_crate,
1208
- optimization_fuel_limit ,
1205
+ optimization_fuel ,
1209
1206
print_fuel_crate,
1210
1207
print_fuel,
1211
- out_of_fuel : AtomicBool :: new ( false ) ,
1212
1208
// Note that this is unsafe because it may misinterpret file descriptors
1213
1209
// on Unix as jobserver file descriptors. We hopefully execute this near
1214
1210
// the beginning of the process though to ensure we don't get false
0 commit comments