@@ -4,6 +4,8 @@ use crate::dep_graph::TaskDepsRef;
4
4
use crate :: ty:: query;
5
5
use rustc_data_structures:: sync:: { self , Lock } ;
6
6
use rustc_errors:: Diagnostic ;
7
+ #[ cfg( not( parallel_compiler) ) ]
8
+ use std:: cell:: Cell ;
7
9
use std:: mem;
8
10
use std:: ptr;
9
11
use thin_vec:: ThinVec ;
@@ -47,52 +49,15 @@ impl<'a, 'tcx> ImplicitCtxt<'a, 'tcx> {
47
49
}
48
50
}
49
51
52
+ // Import the thread-local variable from Rayon, which is preserved for Rayon jobs.
50
53
#[ 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 ;
70
55
56
+ // Otherwise define our own
71
57
#[ 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( ) ) } ;
96
61
}
97
62
98
63
#[ inline]
@@ -111,7 +76,11 @@ pub fn enter_context<'a, 'tcx, F, R>(context: &ImplicitCtxt<'a, 'tcx>, f: F) ->
111
76
where
112
77
F : FnOnce ( ) -> R ,
113
78
{
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
+ } )
115
84
}
116
85
117
86
/// 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
120
89
where
121
90
F : for <' a , ' tcx > FnOnce ( Option < & ImplicitCtxt < ' a , ' tcx > > ) -> R ,
122
91
{
123
- let context = tlv :: get_tlv ( ) ;
92
+ let context = TLV . get ( ) ;
124
93
if context. is_null ( ) {
125
94
f ( None )
126
95
} else {
0 commit comments