Skip to content

Commit d9992bd

Browse files
committed
Simplify constant creation.
1 parent 8a6fce2 commit d9992bd

File tree

1 file changed

+10
-5
lines changed
  • compiler/rustc_mir_transform/src

1 file changed

+10
-5
lines changed

compiler/rustc_mir_transform/src/gvn.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -359,20 +359,25 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
359359
let next_opaque = self.next_opaque.as_mut()?;
360360
let disambiguator = *next_opaque;
361361
*next_opaque += 1;
362-
assert_ne!(disambiguator, 0);
362+
// `disambiguator: 0` means deterministic.
363+
debug_assert_ne!(disambiguator, 0);
363364
disambiguator
364365
};
365366
Some(self.insert(Value::Constant { value, disambiguator }))
366367
}
367368

368369
fn insert_bool(&mut self, flag: bool) -> VnIndex {
369370
// Booleans are deterministic.
370-
self.insert(Value::Constant { value: Const::from_bool(self.tcx, flag), disambiguator: 0 })
371+
let value = Const::from_bool(self.tcx, flag);
372+
debug_assert!(value.is_deterministic());
373+
self.insert(Value::Constant { value, disambiguator: 0 })
371374
}
372375

373376
fn insert_scalar(&mut self, scalar: Scalar, ty: Ty<'tcx>) -> VnIndex {
374-
self.insert_constant(Const::from_scalar(self.tcx, scalar, ty))
375-
.expect("scalars are deterministic")
377+
// Scalars are deterministic.
378+
let value = Const::from_scalar(self.tcx, scalar, ty);
379+
debug_assert!(value.is_deterministic());
380+
self.insert(Value::Constant { value, disambiguator: 0 })
376381
}
377382

378383
fn insert_tuple(&mut self, values: Vec<VnIndex>) -> VnIndex {
@@ -1391,7 +1396,7 @@ impl<'tcx> VnState<'_, 'tcx> {
13911396
// deterministic, adding an additional mention of it in MIR will not give the same value as
13921397
// the former mention.
13931398
if let Value::Constant { value, disambiguator: 0 } = *self.get(index) {
1394-
assert!(value.is_deterministic());
1399+
debug_assert!(value.is_deterministic());
13951400
return Some(ConstOperand { span: DUMMY_SP, user_ty: None, const_: value });
13961401
}
13971402

0 commit comments

Comments
 (0)