1
1
use crate :: ty:: { self , TyCtxt } ;
2
- use crate :: hir:: map:: definitions:: FIRST_FREE_HIGH_DEF_INDEX ;
2
+ use crate :: hir:: map:: definitions:: FIRST_FREE_DEF_INDEX ;
3
3
use rustc_data_structures:: indexed_vec:: Idx ;
4
4
use serialize;
5
5
use std:: fmt;
@@ -99,17 +99,6 @@ impl serialize::UseSpecializedDecodable for CrateNum {}
99
99
/// A DefIndex is an index into the hir-map for a crate, identifying a
100
100
/// particular definition. It should really be considered an interned
101
101
/// shorthand for a particular DefPath.
102
- ///
103
- /// At the moment we are allocating the numerical values of DefIndexes from two
104
- /// address spaces: DefIndexAddressSpace::Low and DefIndexAddressSpace::High.
105
- /// This allows us to allocate the DefIndexes of all item-likes
106
- /// (Items, TraitItems, and ImplItems) into one of these spaces and
107
- /// consequently use a simple array for lookup tables keyed by DefIndex and
108
- /// known to be densely populated. This is especially important for the HIR map.
109
- ///
110
- /// Since the DefIndex is mostly treated as an opaque ID, you probably
111
- /// don't have to care about these address spaces.
112
-
113
102
#[ derive( Clone , PartialEq , Eq , PartialOrd , Ord , Hash , Copy ) ]
114
103
pub struct DefIndex ( u32 ) ;
115
104
@@ -119,67 +108,49 @@ pub const CRATE_DEF_INDEX: DefIndex = DefIndex(0);
119
108
120
109
impl fmt:: Debug for DefIndex {
121
110
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
122
- write ! ( f,
123
- "DefIndex({}:{})" ,
124
- self . address_space( ) . index( ) ,
125
- self . as_array_index( ) )
111
+ write ! ( f, "DefIndex({})" , self . as_array_index( ) )
126
112
}
127
113
}
128
114
129
115
impl DefIndex {
130
- #[ inline]
131
- pub fn address_space ( & self ) -> DefIndexAddressSpace {
132
- match self . 0 & 1 {
133
- 0 => DefIndexAddressSpace :: Low ,
134
- 1 => DefIndexAddressSpace :: High ,
135
- _ => unreachable ! ( )
136
- }
137
- }
138
-
139
116
/// Converts this DefIndex into a zero-based array index.
140
- /// This index is the offset within the given DefIndexAddressSpace.
141
117
#[ inline]
142
118
pub fn as_array_index ( & self ) -> usize {
143
- ( self . 0 >> 1 ) as usize
119
+ self . 0 as usize
144
120
}
145
121
146
122
#[ inline]
147
- pub fn from_array_index ( i : usize , address_space : DefIndexAddressSpace ) -> DefIndex {
148
- DefIndex :: from_raw_u32 ( ( ( i << 1 ) | ( address_space as usize ) ) as u32 )
123
+ pub fn from_array_index ( i : usize ) -> DefIndex {
124
+ DefIndex ( i as u32 )
149
125
}
150
126
151
127
// Proc macros from a proc-macro crate have a kind of virtual DefIndex. This
152
128
// function maps the index of the macro within the crate (which is also the
153
129
// index of the macro in the CrateMetadata::proc_macros array) to the
154
130
// corresponding DefIndex.
155
131
pub fn from_proc_macro_index ( proc_macro_index : usize ) -> DefIndex {
156
- // DefIndex for proc macros start from FIRST_FREE_HIGH_DEF_INDEX ,
157
- // because the first FIRST_FREE_HIGH_DEF_INDEX indexes are reserved
132
+ // DefIndex for proc macros start from FIRST_FREE_DEF_INDEX ,
133
+ // because the first FIRST_FREE_DEF_INDEX indexes are reserved
158
134
// for internal use.
159
135
let def_index = DefIndex :: from_array_index (
160
- proc_macro_index. checked_add ( FIRST_FREE_HIGH_DEF_INDEX )
161
- . expect ( "integer overflow adding `proc_macro_index`" ) ,
162
- DefIndexAddressSpace :: High ) ;
136
+ proc_macro_index. checked_add ( FIRST_FREE_DEF_INDEX )
137
+ . expect ( "integer overflow adding `proc_macro_index`" ) ) ;
163
138
assert ! ( def_index != CRATE_DEF_INDEX ) ;
164
139
def_index
165
140
}
166
141
167
142
// This function is the reverse of from_proc_macro_index() above.
168
143
pub fn to_proc_macro_index ( self : DefIndex ) -> usize {
169
- assert_eq ! ( self . address_space( ) , DefIndexAddressSpace :: High ) ;
170
-
171
- self . as_array_index ( ) . checked_sub ( FIRST_FREE_HIGH_DEF_INDEX )
144
+ self . as_array_index ( ) . checked_sub ( FIRST_FREE_DEF_INDEX )
172
145
. unwrap_or_else ( || {
173
146
bug ! ( "using local index {:?} as proc-macro index" , self )
174
147
} )
175
148
}
176
149
177
- // Don't use this if you don't know about the DefIndex encoding.
178
150
pub fn from_raw_u32 ( x : u32 ) -> DefIndex {
179
151
DefIndex ( x)
180
152
}
181
153
182
- // Don't use this if you don't know about the DefIndex encoding.
183
154
pub fn as_raw_u32 ( & self ) -> u32 {
184
155
self . 0
185
156
}
@@ -188,19 +159,6 @@ impl DefIndex {
188
159
impl serialize:: UseSpecializedEncodable for DefIndex { }
189
160
impl serialize:: UseSpecializedDecodable for DefIndex { }
190
161
191
- #[ derive( Copy , Clone , Debug , PartialEq , Eq , Hash ) ]
192
- pub enum DefIndexAddressSpace {
193
- Low = 0 ,
194
- High = 1 ,
195
- }
196
-
197
- impl DefIndexAddressSpace {
198
- #[ inline]
199
- pub fn index ( & self ) -> usize {
200
- * self as usize
201
- }
202
- }
203
-
204
162
/// A `DefId` identifies a particular *definition*, by combining a crate
205
163
/// index and a def index.
206
164
#[ derive( Clone , PartialEq , Eq , PartialOrd , Ord , Hash , Copy ) ]
@@ -211,10 +169,7 @@ pub struct DefId {
211
169
212
170
impl fmt:: Debug for DefId {
213
171
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
214
- write ! ( f, "DefId({}/{}:{}" ,
215
- self . krate,
216
- self . index. address_space( ) . index( ) ,
217
- self . index. as_array_index( ) ) ?;
172
+ write ! ( f, "DefId({}:{}" , self . krate, self . index. as_array_index( ) ) ?;
218
173
219
174
ty:: tls:: with_opt ( |opt_tcx| {
220
175
if let Some ( tcx) = opt_tcx {
0 commit comments