Skip to content

Commit 98c1ea8

Browse files
committed
Simplify constant creation.
1 parent 61ef044 commit 98c1ea8

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

+10-5
Original file line numberDiff line numberDiff line change
@@ -361,20 +361,25 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
361361
let next_opaque = self.next_opaque.as_mut()?;
362362
let disambiguator = *next_opaque;
363363
*next_opaque += 1;
364-
assert_ne!(disambiguator, 0);
364+
// `disambiguator: 0` means deterministic.
365+
debug_assert_ne!(disambiguator, 0);
365366
disambiguator
366367
};
367368
Some(self.insert(Value::Constant { value, disambiguator }))
368369
}
369370

370371
fn insert_bool(&mut self, flag: bool) -> VnIndex {
371372
// Booleans are deterministic.
372-
self.insert(Value::Constant { value: Const::from_bool(self.tcx, flag), disambiguator: 0 })
373+
let value = Const::from_bool(self.tcx, flag);
374+
debug_assert!(value.is_deterministic());
375+
self.insert(Value::Constant { value, disambiguator: 0 })
373376
}
374377

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

380385
fn insert_tuple(&mut self, values: Vec<VnIndex>) -> VnIndex {
@@ -1453,7 +1458,7 @@ impl<'tcx> VnState<'_, 'tcx> {
14531458
// deterministic, adding an additional mention of it in MIR will not give the same value as
14541459
// the former mention.
14551460
if let Value::Constant { value, disambiguator: 0 } = *self.get(index) {
1456-
assert!(value.is_deterministic());
1461+
debug_assert!(value.is_deterministic());
14571462
return Some(ConstOperand { span: DUMMY_SP, user_ty: None, const_: value });
14581463
}
14591464

0 commit comments

Comments
 (0)