File tree Expand file tree Collapse file tree
compiler/rustc_data_structures/src Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ use std:: cell:: Cell ;
12use std:: hint:: { likely, unlikely} ;
23use std:: io:: { self , Write } ;
3- use std:: sync:: atomic:: { AtomicU16 , Ordering } ;
44
55use backtrace:: { Backtrace , BacktraceFrame } ;
66
@@ -18,7 +18,7 @@ const STACK_PER_RECURSION: usize = 1024 * 1024; // 1MB
1818const STACK_PER_RECURSION : usize = 16 * 1024 * 1024 ; // 16MB
1919
2020thread_local ! {
21- static TIMES_GROWN : AtomicU16 = const { AtomicU16 :: new( 0 ) } ;
21+ static TIMES_GROWN : Cell < u16 > = const { Cell :: new( 0 ) } ;
2222}
2323
2424// Give up if we expand the stack this many times and are still trying to recurse deeper.
@@ -39,12 +39,13 @@ pub fn ensure_sufficient_stack<R>(f: impl FnOnce() -> R) -> R {
3939 if likely ( enough_space) {
4040 f ( )
4141 } else {
42- let times = TIMES_GROWN . with ( |times| times . fetch_add ( 1 , Ordering :: Relaxed ) ) ;
42+ let times = TIMES_GROWN . get ( ) ;
4343 if unlikely ( times > MAX_STACK_GROWTH ) {
4444 too_much_stack ( ) ;
4545 }
46+ TIMES_GROWN . set ( times + 1 ) ;
4647 let out = stacker:: grow ( STACK_PER_RECURSION , f) ;
47- TIMES_GROWN . with ( | times| times . fetch_sub ( 1 , Ordering :: Relaxed ) ) ;
48+ TIMES_GROWN . set ( times) ;
4849 out
4950 }
5051}
You can’t perform that action at this time.
0 commit comments