@@ -14,6 +14,7 @@ use crate::{
1414} ;
1515use rustc_driver:: { Callbacks , Compilation , RunCompiler } ;
1616use rustc_interface:: { interface, Queries } ;
17+ use rustc_middle:: mir:: interpret:: AllocId ;
1718use rustc_middle:: ty:: TyCtxt ;
1819use rustc_session:: EarlyErrorHandler ;
1920pub use rustc_span:: def_id:: { CrateNum , DefId } ;
@@ -134,6 +135,10 @@ impl<'tcx> Tables<'tcx> {
134135 stable_mir:: ty:: ImplDef ( self . create_def_id ( did) )
135136 }
136137
138+ pub fn prov ( & mut self , aid : AllocId ) -> stable_mir:: ty:: Prov {
139+ stable_mir:: ty:: Prov ( self . create_alloc_id ( aid) )
140+ }
141+
137142 fn create_def_id ( & mut self , did : DefId ) -> stable_mir:: DefId {
138143 // FIXME: this becomes inefficient when we have too many ids
139144 for ( i, & d) in self . def_ids . iter ( ) . enumerate ( ) {
@@ -145,14 +150,24 @@ impl<'tcx> Tables<'tcx> {
145150 self . def_ids . push ( did) ;
146151 stable_mir:: DefId ( id)
147152 }
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+ }
148163}
149164
150165pub fn crate_num ( item : & stable_mir:: Crate ) -> CrateNum {
151166 item. id . into ( )
152167}
153168
154169pub 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) ;
156171}
157172
158173/// A type that provides internal information but that can still be used for debug purpose.
0 commit comments