66use crate :: rustc_internal;
77use crate :: rustc_smir:: Tables ;
88use rustc_data_structures:: fx;
9+ use rustc_data_structures:: fx:: FxIndexMap ;
910use rustc_driver:: { Callbacks , Compilation , RunCompiler } ;
1011use rustc_interface:: { interface, Queries } ;
1112use rustc_middle:: mir:: interpret:: AllocId ;
13+ use rustc_middle:: ty;
1214use rustc_middle:: ty:: TyCtxt ;
1315use rustc_span:: def_id:: { CrateNum , DefId } ;
1416use rustc_span:: Span ;
@@ -97,7 +99,7 @@ impl<'tcx> Tables<'tcx> {
9799 stable_mir:: ty:: Prov ( self . create_alloc_id ( aid) )
98100 }
99101
100- fn create_def_id ( & mut self , did : DefId ) -> stable_mir:: DefId {
102+ pub ( crate ) fn create_def_id ( & mut self , did : DefId ) -> stable_mir:: DefId {
101103 self . def_ids . create_or_fetch ( did)
102104 }
103105
@@ -108,6 +110,17 @@ impl<'tcx> Tables<'tcx> {
108110 pub ( crate ) fn create_span ( & mut self , span : Span ) -> stable_mir:: ty:: Span {
109111 self . spans . create_or_fetch ( span)
110112 }
113+
114+ pub ( crate ) fn instance_def (
115+ & mut self ,
116+ instance : ty:: Instance < ' tcx > ,
117+ ) -> stable_mir:: mir:: mono:: InstanceDef {
118+ self . instances . create_or_fetch ( instance)
119+ }
120+
121+ pub ( crate ) fn static_def ( & mut self , did : DefId ) -> stable_mir:: mir:: mono:: StaticDef {
122+ stable_mir:: mir:: mono:: StaticDef ( self . create_def_id ( did) )
123+ }
111124}
112125
113126pub fn crate_num ( item : & stable_mir:: Crate ) -> CrateNum {
@@ -118,10 +131,11 @@ pub fn run(tcx: TyCtxt<'_>, f: impl FnOnce()) {
118131 stable_mir:: run (
119132 Tables {
120133 tcx,
121- def_ids : rustc_internal :: IndexMap { index_map : fx :: FxIndexMap :: default ( ) } ,
122- alloc_ids : rustc_internal :: IndexMap { index_map : fx :: FxIndexMap :: default ( ) } ,
123- spans : rustc_internal :: IndexMap { index_map : fx :: FxIndexMap :: default ( ) } ,
134+ def_ids : IndexMap :: default ( ) ,
135+ alloc_ids : IndexMap :: default ( ) ,
136+ spans : IndexMap :: default ( ) ,
124137 types : vec ! [ ] ,
138+ instances : IndexMap :: default ( ) ,
125139 } ,
126140 f,
127141 ) ;
@@ -192,6 +206,12 @@ pub struct IndexMap<K, V> {
192206 index_map : fx:: FxIndexMap < K , V > ,
193207}
194208
209+ impl < K , V > Default for IndexMap < K , V > {
210+ fn default ( ) -> Self {
211+ Self { index_map : FxIndexMap :: default ( ) }
212+ }
213+ }
214+
195215impl < K : PartialEq + Hash + Eq , V : Copy + Debug + PartialEq + IndexedVal > IndexMap < K , V > {
196216 pub fn create_or_fetch ( & mut self , key : K ) -> V {
197217 let len = self . index_map . len ( ) ;
0 commit comments