@@ -12,7 +12,7 @@ use rustc_middle::mir::interpret::AllocId;
1212use rustc_middle:: ty:: TyCtxt ;
1313use rustc_span:: def_id:: { CrateNum , DefId } ;
1414use rustc_span:: Span ;
15- use stable_mir:: ty:: IndexToVal ;
15+ use stable_mir:: ty:: IndexedVal ;
1616use stable_mir:: CompilerError ;
1717use std:: fmt:: Debug ;
1818use std:: hash:: Hash ;
@@ -23,7 +23,7 @@ impl<'tcx> Index<stable_mir::DefId> for Tables<'tcx> {
2323
2424 #[ inline( always) ]
2525 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]
2727 }
2828}
2929
@@ -32,7 +32,7 @@ impl<'tcx> Index<stable_mir::ty::Span> for Tables<'tcx> {
3232
3333 #[ inline( always) ]
3434 fn index ( & self , index : stable_mir:: ty:: Span ) -> & Self :: Output {
35- & self . spans . get_index_and_assert ( index. 0 , index )
35+ & self . spans [ index]
3636 }
3737}
3838
@@ -98,15 +98,15 @@ impl<'tcx> Tables<'tcx> {
9898 }
9999
100100 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)
102102 }
103103
104104 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)
106106 }
107107
108108 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)
110110 }
111111}
112112
@@ -192,19 +192,22 @@ pub struct IndexMap<K, V> {
192192 index_map : fx:: FxIndexMap < K , V > ,
193193}
194194
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 {
206197 let len = self . index_map . len ( ) ;
207198 let v = self . index_map . entry ( key) . or_insert ( V :: to_val ( len) ) ;
208199 * v
209200 }
210201}
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