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