@@ -13,6 +13,7 @@ use crate::{
13
13
} ;
14
14
use rustc_driver:: { Callbacks , Compilation , RunCompiler } ;
15
15
use rustc_interface:: { interface, Queries } ;
16
+ use rustc_middle:: mir:: interpret:: AllocId ;
16
17
use rustc_middle:: ty:: TyCtxt ;
17
18
use rustc_session:: EarlyErrorHandler ;
18
19
pub use rustc_span:: def_id:: { CrateNum , DefId } ;
@@ -133,6 +134,10 @@ impl<'tcx> Tables<'tcx> {
133
134
stable_mir:: ty:: ImplDef ( self . create_def_id ( did) )
134
135
}
135
136
137
+ pub fn prov ( & mut self , aid : AllocId ) -> stable_mir:: ty:: Prov {
138
+ stable_mir:: ty:: Prov ( self . create_alloc_id ( aid) )
139
+ }
140
+
136
141
fn create_def_id ( & mut self , did : DefId ) -> stable_mir:: DefId {
137
142
// FIXME: this becomes inefficient when we have too many ids
138
143
for ( i, & d) in self . def_ids . iter ( ) . enumerate ( ) {
@@ -144,14 +149,24 @@ impl<'tcx> Tables<'tcx> {
144
149
self . def_ids . push ( did) ;
145
150
stable_mir:: DefId ( id)
146
151
}
152
+
153
+ fn create_alloc_id ( & mut self , aid : AllocId ) -> stable_mir:: AllocId {
154
+ // FIXME: this becomes inefficient when we have too many ids
155
+ if let Some ( i) = self . alloc_ids . iter ( ) . position ( |a| * a == aid) {
156
+ return stable_mir:: AllocId ( i) ;
157
+ } ;
158
+ let id = self . def_ids . len ( ) ;
159
+ self . alloc_ids . push ( aid) ;
160
+ stable_mir:: AllocId ( id)
161
+ }
147
162
}
148
163
149
164
pub fn crate_num ( item : & stable_mir:: Crate ) -> CrateNum {
150
165
item. id . into ( )
151
166
}
152
167
153
168
pub fn run ( tcx : TyCtxt < ' _ > , f : impl FnOnce ( ) ) {
154
- crate :: stable_mir:: run ( Tables { tcx, def_ids : vec ! [ ] , types : vec ! [ ] } , f) ;
169
+ crate :: stable_mir:: run ( Tables { tcx, def_ids : vec ! [ ] , alloc_ids : vec ! [ ] , types : vec ! [ ] } , f) ;
155
170
}
156
171
157
172
/// A type that provides internal information but that can still be used for debug purpose.
0 commit comments