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