@@ -100,7 +100,7 @@ use rustc_data_structures::fx::FxHasher;
100
100
use rustc_data_structures:: graph:: dominators:: Dominators ;
101
101
use rustc_hir:: def:: DefKind ;
102
102
use rustc_index:: bit_set:: DenseBitSet ;
103
- use rustc_index:: { Idx , IndexVec , newtype_index} ;
103
+ use rustc_index:: { IndexVec , newtype_index} ;
104
104
use rustc_middle:: bug;
105
105
use rustc_middle:: mir:: interpret:: GlobalAlloc ;
106
106
use rustc_middle:: mir:: visit:: * ;
@@ -158,11 +158,16 @@ newtype_index! {
158
158
struct VnIndex { }
159
159
}
160
160
161
- newtype_index ! {
162
- /// Counter type to ensure that all unique values are created using `insert_unique`.
163
- #[ debug_format = "_o{}" ]
164
- struct VnOpaque {
165
- const DETERMINISTIC = 0 ;
161
+ #[ derive( Copy , Clone , Debug , Eq ) ]
162
+ struct VnOpaque ;
163
+ impl PartialEq for VnOpaque {
164
+ fn eq ( & self , _: & VnOpaque ) -> bool {
165
+ unreachable ! ( )
166
+ }
167
+ }
168
+ impl Hash for VnOpaque {
169
+ fn hash < T : Hasher > ( & self , _: & mut T ) {
170
+ unreachable ! ( )
166
171
}
167
172
}
168
173
@@ -183,8 +188,8 @@ enum Value<'tcx> {
183
188
value : Const < ' tcx > ,
184
189
/// Some constants do not have a deterministic value. To avoid merging two instances of the
185
190
/// same `Const`, we assign them an additional integer index.
186
- // `disambiguator` is `DETERMINISTIC ` iff the constant is deterministic.
187
- disambiguator : VnOpaque ,
191
+ // `disambiguator` is `None ` iff the constant is deterministic.
192
+ disambiguator : Option < VnOpaque > ,
188
193
} ,
189
194
/// An aggregate value, either tuple/closure/struct/enum.
190
195
/// This does not contain unions, as we cannot reason with the value.
@@ -234,8 +239,6 @@ struct ValueSet<'tcx> {
234
239
hashes : IndexVec < VnIndex , u64 > ,
235
240
values : IndexVec < VnIndex , Value < ' tcx > > ,
236
241
types : IndexVec < VnIndex , Ty < ' tcx > > ,
237
- /// Counter to generate different values.
238
- next_opaque : VnOpaque ,
239
242
}
240
243
241
244
impl < ' tcx > ValueSet < ' tcx > {
@@ -245,8 +248,6 @@ impl<'tcx> ValueSet<'tcx> {
245
248
hashes : IndexVec :: with_capacity ( num_values) ,
246
249
values : IndexVec :: with_capacity ( num_values) ,
247
250
types : IndexVec :: with_capacity ( num_values) ,
248
- // The first opaque is 1, as 0 means deterministic constant.
249
- next_opaque : VnOpaque :: from_u32 ( 1 ) ,
250
251
}
251
252
}
252
253
@@ -257,12 +258,11 @@ impl<'tcx> ValueSet<'tcx> {
257
258
ty : Ty < ' tcx > ,
258
259
value : impl FnOnce ( VnOpaque ) -> Value < ' tcx > ,
259
260
) -> VnIndex {
260
- let value = value ( self . next_opaque ) ;
261
- self . next_opaque . increment_by ( 1 ) ;
261
+ let value = value ( VnOpaque ) ;
262
262
263
263
debug_assert ! ( match value {
264
264
Value :: Opaque ( _) | Value :: Address { .. } => true ,
265
- Value :: Constant { disambiguator, .. } => disambiguator != DETERMINISTIC ,
265
+ Value :: Constant { disambiguator, .. } => disambiguator. is_some ( ) ,
266
266
_ => false ,
267
267
} ) ;
268
268
@@ -280,7 +280,7 @@ impl<'tcx> ValueSet<'tcx> {
280
280
fn insert ( & mut self , ty : Ty < ' tcx > , value : Value < ' tcx > ) -> ( VnIndex , bool ) {
281
281
debug_assert ! ( match value {
282
282
Value :: Opaque ( _) | Value :: Address { .. } => false ,
283
- Value :: Constant { disambiguator, .. } => disambiguator == DETERMINISTIC ,
283
+ Value :: Constant { disambiguator, .. } => disambiguator. is_none ( ) ,
284
284
_ => true ,
285
285
} ) ;
286
286
@@ -325,8 +325,7 @@ impl<'tcx> ValueSet<'tcx> {
325
325
/// Replace the value associated with `index` with an opaque value.
326
326
#[ inline]
327
327
fn forget ( & mut self , index : VnIndex ) {
328
- self . values [ index] = Value :: Opaque ( self . next_opaque ) ;
329
- self . next_opaque . increment_by ( 1 ) ;
328
+ self . values [ index] = Value :: Opaque ( VnOpaque ) ;
330
329
}
331
330
}
332
331
@@ -436,14 +435,14 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
436
435
fn insert_constant ( & mut self , value : Const < ' tcx > ) -> VnIndex {
437
436
let ( index, new) = if value. is_deterministic ( ) {
438
437
// The constant is deterministic, no need to disambiguate.
439
- let constant = Value :: Constant { value, disambiguator : DETERMINISTIC } ;
438
+ let constant = Value :: Constant { value, disambiguator : None } ;
440
439
self . values . insert ( value. ty ( ) , constant)
441
440
} else {
442
441
// Multiple mentions of this constant will yield different values,
443
442
// so assign a different `disambiguator` to ensure they do not get the same `VnIndex`.
444
- let index = self . values . insert_unique ( value. ty ( ) , |disambiguator| {
445
- debug_assert_ne ! ( disambiguator , DETERMINISTIC ) ;
446
- Value :: Constant { value , disambiguator }
443
+ let index = self . values . insert_unique ( value. ty ( ) , |disambiguator| Value :: Constant {
444
+ value ,
445
+ disambiguator : Some ( disambiguator) ,
447
446
} ) ;
448
447
( index, true )
449
448
} ;
@@ -479,14 +478,14 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
479
478
// Booleans are deterministic.
480
479
let value = Const :: from_bool ( self . tcx , flag) ;
481
480
debug_assert ! ( value. is_deterministic( ) ) ;
482
- self . insert ( self . tcx . types . bool , Value :: Constant { value, disambiguator : DETERMINISTIC } )
481
+ self . insert ( self . tcx . types . bool , Value :: Constant { value, disambiguator : None } )
483
482
}
484
483
485
484
fn insert_scalar ( & mut self , ty : Ty < ' tcx > , scalar : Scalar ) -> VnIndex {
486
485
// Scalars are deterministic.
487
486
let value = Const :: from_scalar ( self . tcx , scalar, ty) ;
488
487
debug_assert ! ( value. is_deterministic( ) ) ;
489
- self . insert ( ty, Value :: Constant { value, disambiguator : DETERMINISTIC } )
488
+ self . insert ( ty, Value :: Constant { value, disambiguator : None } )
490
489
}
491
490
492
491
fn insert_tuple ( & mut self , ty : Ty < ' tcx > , values : Vec < VnIndex > ) -> VnIndex {
@@ -1731,7 +1730,7 @@ impl<'tcx> VnState<'_, 'tcx> {
1731
1730
// This was already constant in MIR, do not change it. If the constant is not
1732
1731
// deterministic, adding an additional mention of it in MIR will not give the same value as
1733
1732
// the former mention.
1734
- if let Value :: Constant { value, disambiguator : DETERMINISTIC } = * self . get ( index) {
1733
+ if let Value :: Constant { value, disambiguator : None } = * self . get ( index) {
1735
1734
debug_assert ! ( value. is_deterministic( ) ) ;
1736
1735
return Some ( ConstOperand { span : DUMMY_SP , user_ty : None , const_ : value } ) ;
1737
1736
}
0 commit comments