@@ -4,6 +4,8 @@ use crate::dep_graph::TaskDepsRef;
44use  crate :: ty:: query; 
55use  rustc_data_structures:: sync:: { self ,  Lock } ; 
66use  rustc_errors:: Diagnostic ; 
7+ #[ cfg( not( parallel_compiler) ) ]  
8+ use  std:: cell:: Cell ; 
79use  std:: mem; 
810use  std:: ptr; 
911use  thin_vec:: ThinVec ; 
@@ -47,52 +49,15 @@ impl<'a, 'tcx> ImplicitCtxt<'a, 'tcx> {
4749    } 
4850} 
4951
52+ // Import the thread-local variable from Rayon, which is preserved for Rayon jobs. 
5053#[ cfg( parallel_compiler) ]  
51- mod  tlv { 
52-     use  rustc_rayon_core as  rayon_core; 
53-     use  std:: ptr; 
54- 
55-     /// Gets Rayon's thread-local variable, which is preserved for Rayon jobs. 
56- /// This is used to get the pointer to the current `ImplicitCtxt`. 
57- #[ inline]  
58-     pub ( super )  fn  get_tlv ( )  -> * const  ( )  { 
59-         ptr:: from_exposed_addr ( rayon_core:: tlv:: get ( ) ) 
60-     } 
61- 
62-     /// Sets Rayon's thread-local variable, which is preserved for Rayon jobs 
63- /// to `value` during the call to `f`. It is restored to its previous value after. 
64- /// This is used to set the pointer to the new `ImplicitCtxt`. 
65- #[ inline]  
66-     pub ( super )  fn  with_tlv < F :  FnOnce ( )  -> R ,  R > ( value :  * const  ( ) ,  f :  F )  -> R  { 
67-         rayon_core:: tlv:: with ( value. expose_addr ( ) ,  f) 
68-     } 
69- } 
54+ use  rayon_core:: tlv:: TLV ; 
7055
56+ // Otherwise define our own 
7157#[ cfg( not( parallel_compiler) ) ]  
72- mod  tlv { 
73-     use  std:: cell:: Cell ; 
74-     use  std:: ptr; 
75- 
76-     thread_local !  { 
77-         /// A thread local variable that stores a pointer to the current `ImplicitCtxt`. 
78- static  TLV :  Cell <* const  ( ) > = const  {  Cell :: new( ptr:: null( ) )  } ; 
79-     } 
80- 
81-     /// Gets the pointer to the current `ImplicitCtxt`. 
82- #[ inline]  
83-     pub ( super )  fn  get_tlv ( )  -> * const  ( )  { 
84-         TLV . with ( |tlv| tlv. get ( ) ) 
85-     } 
86- 
87-     /// Sets TLV to `value` during the call to `f`. 
88- /// It is restored to its previous value after. 
89- /// This is used to set the pointer to the new `ImplicitCtxt`. 
90- #[ inline]  
91-     pub ( super )  fn  with_tlv < F :  FnOnce ( )  -> R ,  R > ( value :  * const  ( ) ,  f :  F )  -> R  { 
92-         let  old = TLV . replace ( value) ; 
93-         let  _reset = rustc_data_structures:: OnDrop ( move  || TLV . set ( old) ) ; 
94-         f ( ) 
95-     } 
58+ thread_local !  { 
59+     /// A thread local variable that stores a pointer to the current `ImplicitCtxt`. 
60+ static  TLV :  Cell <* const  ( ) > = const  {  Cell :: new( ptr:: null( ) )  } ; 
9661} 
9762
9863#[ inline]  
@@ -111,7 +76,11 @@ pub fn enter_context<'a, 'tcx, F, R>(context: &ImplicitCtxt<'a, 'tcx>, f: F) ->
11176where 
11277    F :  FnOnce ( )  -> R , 
11378{ 
114-     tlv:: with_tlv ( erase ( context) ,  f) 
79+     TLV . with ( |tlv| { 
80+         let  old = tlv. replace ( erase ( context) ) ; 
81+         let  _reset = rustc_data_structures:: OnDrop ( move  || tlv. set ( old) ) ; 
82+         f ( ) 
83+     } ) 
11584} 
11685
11786/// Allows access to the current `ImplicitCtxt` in a closure if one is available. 
@@ -120,7 +89,7 @@ pub fn with_context_opt<F, R>(f: F) -> R
12089where 
12190    F :  for <' a ,  ' tcx > FnOnce ( Option < & ImplicitCtxt < ' a ,  ' tcx > > )  -> R , 
12291{ 
123-     let  context = tlv :: get_tlv ( ) ; 
92+     let  context = TLV . get ( ) ; 
12493    if  context. is_null ( )  { 
12594        f ( None ) 
12695    }  else  { 
0 commit comments