@@ -12,7 +12,7 @@ use rustc_middle::mir::interpret::AllocId;
12
12
use rustc_middle:: ty:: TyCtxt ;
13
13
use rustc_span:: def_id:: { CrateNum , DefId } ;
14
14
use rustc_span:: Span ;
15
- use stable_mir:: ty:: IndexToVal ;
15
+ use stable_mir:: ty:: IndexedVal ;
16
16
use stable_mir:: CompilerError ;
17
17
use std:: fmt:: Debug ;
18
18
use std:: hash:: Hash ;
@@ -23,7 +23,7 @@ impl<'tcx> Index<stable_mir::DefId> for Tables<'tcx> {
23
23
24
24
#[ inline( always) ]
25
25
fn index ( & self , index : stable_mir:: DefId ) -> & Self :: Output {
26
- & self . def_ids . get_index_and_assert ( index. 0 , index )
26
+ & self . def_ids [ index]
27
27
}
28
28
}
29
29
@@ -32,7 +32,7 @@ impl<'tcx> Index<stable_mir::ty::Span> for Tables<'tcx> {
32
32
33
33
#[ inline( always) ]
34
34
fn index ( & self , index : stable_mir:: ty:: Span ) -> & Self :: Output {
35
- & self . spans . get_index_and_assert ( index. 0 , index )
35
+ & self . spans [ index]
36
36
}
37
37
}
38
38
@@ -98,15 +98,15 @@ impl<'tcx> Tables<'tcx> {
98
98
}
99
99
100
100
fn create_def_id ( & mut self , did : DefId ) -> stable_mir:: DefId {
101
- self . def_ids . entry ( did)
101
+ self . def_ids . create_or_fetch ( did)
102
102
}
103
103
104
104
fn create_alloc_id ( & mut self , aid : AllocId ) -> stable_mir:: AllocId {
105
- self . alloc_ids . entry ( aid)
105
+ self . alloc_ids . create_or_fetch ( aid)
106
106
}
107
107
108
108
pub ( crate ) fn create_span ( & mut self , span : Span ) -> stable_mir:: ty:: Span {
109
- self . spans . entry ( span)
109
+ self . spans . create_or_fetch ( span)
110
110
}
111
111
}
112
112
@@ -192,19 +192,22 @@ pub struct IndexMap<K, V> {
192
192
index_map : fx:: FxIndexMap < K , V > ,
193
193
}
194
194
195
- impl < K : PartialEq + Hash + Eq , V : Copy + Debug + PartialEq + IndexToVal > IndexMap < K , V > {
196
- /// Because we are using values as indexes, this first get's the
197
- /// key using index of the value provided, then asserts that value
198
- /// we got from IndexMap is equal to one we provided.
199
- pub fn get_index_and_assert ( & self , index : usize , value : V ) -> & K {
200
- let ( k, v) = self . index_map . get_index ( index) . unwrap ( ) ;
201
- assert_eq ! ( * v, value, "Provided value doesn't match with indexed value" ) ;
202
- k
203
- }
204
-
205
- pub fn entry ( & mut self , key : K ) -> V {
195
+ impl < K : PartialEq + Hash + Eq , V : Copy + Debug + PartialEq + IndexedVal > IndexMap < K , V > {
196
+ pub fn create_or_fetch ( & mut self , key : K ) -> V {
206
197
let len = self . index_map . len ( ) ;
207
198
let v = self . index_map . entry ( key) . or_insert ( V :: to_val ( len) ) ;
208
199
* v
209
200
}
210
201
}
202
+
203
+ impl < K : PartialEq + Hash + Eq , V : Copy + Debug + PartialEq + IndexedVal > Index < V >
204
+ for IndexMap < K , V >
205
+ {
206
+ type Output = K ;
207
+
208
+ fn index ( & self , index : V ) -> & Self :: Output {
209
+ let ( k, v) = self . index_map . get_index ( index. to_index ( ) ) . unwrap ( ) ;
210
+ assert_eq ! ( * v, index, "Provided value doesn't match with indexed value" ) ;
211
+ k
212
+ }
213
+ }
0 commit comments