@@ -18,15 +18,14 @@ use std::cell::RefCell;
18
18
use std:: fmt:: Debug ;
19
19
use std:: hash:: Hash ;
20
20
use std:: ops:: Index ;
21
- use std:: rc:: Rc ;
22
21
23
22
mod internal;
24
23
25
- pub unsafe fn stable < ' tcx , S : Stable < ' tcx > > ( item : & S ) -> S :: T {
24
+ pub fn stable < ' tcx , S : Stable < ' tcx > > ( item : & S ) -> S :: T {
26
25
with_tables ( |tables| item. stable ( tables) )
27
26
}
28
27
29
- pub unsafe fn internal < ' tcx , S : RustcInternal < ' tcx > > ( item : & S ) -> S :: T {
28
+ pub fn internal < ' tcx , S : RustcInternal < ' tcx > > ( item : & S ) -> S :: T {
30
29
with_tables ( |tables| item. internal ( tables) )
31
30
}
32
31
@@ -141,15 +140,12 @@ pub fn crate_num(item: &stable_mir::Crate) -> CrateNum {
141
140
// datastructures and stable MIR datastructures
142
141
scoped_thread_local ! ( static TLV : Cell <* const ( ) >) ;
143
142
144
- pub ( crate ) fn init < ' tcx > ( tables : TablesWrapper < ' tcx > , f : impl FnOnce ( ) ) {
143
+ pub ( crate ) fn init < ' tcx > ( tables : & TablesWrapper < ' tcx > , f : impl FnOnce ( ) ) {
145
144
assert ! ( !TLV . is_set( ) ) ;
146
- fn g < ' a , ' tcx > ( context : & ' a TablesWrapper < ' tcx > , f : impl FnOnce ( ) ) {
147
- let ptr: * const ( ) = & context as * const & _ as _ ;
148
- TLV . set ( & Cell :: new ( ptr) , || {
149
- f ( ) ;
150
- } ) ;
151
- }
152
- g ( & tables, f) ;
145
+ let ptr: * const ( ) = & tables as * const & _ as _ ;
146
+ TLV . set ( & Cell :: new ( ptr) , || {
147
+ f ( ) ;
148
+ } ) ;
153
149
}
154
150
155
151
/// Loads the current context and calls a function with it.
@@ -166,15 +162,15 @@ pub(crate) fn with_tables<'tcx, R>(f: impl FnOnce(&mut Tables<'tcx>) -> R) -> R
166
162
}
167
163
168
164
pub fn run ( tcx : TyCtxt < ' _ > , f : impl FnOnce ( ) ) {
169
- let tables = Rc :: new ( RefCell :: new ( Tables {
165
+ let tables = TablesWrapper ( RefCell :: new ( Tables {
170
166
tcx,
171
167
def_ids : IndexMap :: default ( ) ,
172
168
alloc_ids : IndexMap :: default ( ) ,
173
169
spans : IndexMap :: default ( ) ,
174
170
types : vec ! [ ] ,
175
171
instances : IndexMap :: default ( ) ,
176
172
} ) ) ;
177
- stable_mir:: run ( TablesWrapper ( Rc :: clone ( & tables) ) , || init ( TablesWrapper ( tables) , f) ) ;
173
+ stable_mir:: run ( & tables, || init ( & tables, f) ) ;
178
174
}
179
175
180
176
#[ macro_export]
0 commit comments