11use 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 ;
33use rustc_data_structures:: indexed_vec:: Idx ;
44use serialize;
55use std:: fmt;
@@ -99,17 +99,6 @@ impl serialize::UseSpecializedDecodable for CrateNum {}
9999/// A DefIndex is an index into the hir-map for a crate, identifying a
100100/// particular definition. It should really be considered an interned
101101/// 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-
113102#[ derive( Clone , PartialEq , Eq , PartialOrd , Ord , Hash , Copy ) ]
114103pub struct DefIndex ( u32 ) ;
115104
@@ -119,67 +108,49 @@ pub const CRATE_DEF_INDEX: DefIndex = DefIndex(0);
119108
120109impl fmt:: Debug for DefIndex {
121110 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( ) )
126112 }
127113}
128114
129115impl 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-
139116 /// Converts this DefIndex into a zero-based array index.
140- /// This index is the offset within the given DefIndexAddressSpace.
141117 #[ inline]
142118 pub fn as_array_index ( & self ) -> usize {
143- ( self . 0 >> 1 ) as usize
119+ self . 0 as usize
144120 }
145121
146122 #[ 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 )
149125 }
150126
151127 // Proc macros from a proc-macro crate have a kind of virtual DefIndex. This
152128 // function maps the index of the macro within the crate (which is also the
153129 // index of the macro in the CrateMetadata::proc_macros array) to the
154130 // corresponding DefIndex.
155131 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
158134 // for internal use.
159135 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`" ) ) ;
163138 assert ! ( def_index != CRATE_DEF_INDEX ) ;
164139 def_index
165140 }
166141
167142 // This function is the reverse of from_proc_macro_index() above.
168143 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 )
172145 . unwrap_or_else ( || {
173146 bug ! ( "using local index {:?} as proc-macro index" , self )
174147 } )
175148 }
176149
177- // Don't use this if you don't know about the DefIndex encoding.
178150 pub fn from_raw_u32 ( x : u32 ) -> DefIndex {
179151 DefIndex ( x)
180152 }
181153
182- // Don't use this if you don't know about the DefIndex encoding.
183154 pub fn as_raw_u32 ( & self ) -> u32 {
184155 self . 0
185156 }
@@ -188,19 +159,6 @@ impl DefIndex {
188159impl serialize:: UseSpecializedEncodable for DefIndex { }
189160impl serialize:: UseSpecializedDecodable for DefIndex { }
190161
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-
204162/// A `DefId` identifies a particular *definition*, by combining a crate
205163/// index and a def index.
206164#[ derive( Clone , PartialEq , Eq , PartialOrd , Ord , Hash , Copy ) ]
@@ -211,10 +169,7 @@ pub struct DefId {
211169
212170impl fmt:: Debug for DefId {
213171 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( ) ) ?;
218173
219174 ty:: tls:: with_opt ( |opt_tcx| {
220175 if let Some ( tcx) = opt_tcx {
0 commit comments