6
6
use crate :: rustc_internal;
7
7
use crate :: rustc_smir:: Tables ;
8
8
use rustc_data_structures:: fx;
9
+ use rustc_data_structures:: fx:: FxIndexMap ;
9
10
use rustc_driver:: { Callbacks , Compilation , RunCompiler } ;
10
11
use rustc_interface:: { interface, Queries } ;
11
12
use rustc_middle:: mir:: interpret:: AllocId ;
13
+ use rustc_middle:: ty;
12
14
use rustc_middle:: ty:: TyCtxt ;
13
15
use rustc_span:: def_id:: { CrateNum , DefId } ;
14
16
use rustc_span:: Span ;
@@ -97,7 +99,7 @@ impl<'tcx> Tables<'tcx> {
97
99
stable_mir:: ty:: Prov ( self . create_alloc_id ( aid) )
98
100
}
99
101
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 {
101
103
self . def_ids . create_or_fetch ( did)
102
104
}
103
105
@@ -108,6 +110,17 @@ impl<'tcx> Tables<'tcx> {
108
110
pub ( crate ) fn create_span ( & mut self , span : Span ) -> stable_mir:: ty:: Span {
109
111
self . spans . create_or_fetch ( span)
110
112
}
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
+ }
111
124
}
112
125
113
126
pub fn crate_num ( item : & stable_mir:: Crate ) -> CrateNum {
@@ -118,10 +131,11 @@ pub fn run(tcx: TyCtxt<'_>, f: impl FnOnce()) {
118
131
stable_mir:: run (
119
132
Tables {
120
133
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 ( ) ,
124
137
types : vec ! [ ] ,
138
+ instances : IndexMap :: default ( ) ,
125
139
} ,
126
140
f,
127
141
) ;
@@ -192,6 +206,12 @@ pub struct IndexMap<K, V> {
192
206
index_map : fx:: FxIndexMap < K , V > ,
193
207
}
194
208
209
+ impl < K , V > Default for IndexMap < K , V > {
210
+ fn default ( ) -> Self {
211
+ Self { index_map : FxIndexMap :: default ( ) }
212
+ }
213
+ }
214
+
195
215
impl < K : PartialEq + Hash + Eq , V : Copy + Debug + PartialEq + IndexedVal > IndexMap < K , V > {
196
216
pub fn create_or_fetch ( & mut self , key : K ) -> V {
197
217
let len = self . index_map . len ( ) ;
0 commit comments