Skip to content

Commit 8a6fce2

Browse files
committed
Encode constant determinism in disambiguator.
1 parent 70940ca commit 8a6fce2

File tree

1 file changed

+8
-7
lines changed
  • compiler/rustc_mir_transform/src

1 file changed

+8
-7
lines changed

compiler/rustc_mir_transform/src/gvn.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ enum Value<'tcx> {
202202
value: Const<'tcx>,
203203
/// Some constants do not have a deterministic value. To avoid merging two instances of the
204204
/// same `Const`, we assign them an additional integer index.
205+
// `disambiguator` is 0 iff the constant is deterministic.
205206
disambiguator: usize,
206207
},
207208
/// An aggregate value, either tuple/closure/struct/enum.
@@ -286,7 +287,7 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
286287
rev_locals: IndexVec::with_capacity(num_values),
287288
values: FxIndexSet::with_capacity_and_hasher(num_values, Default::default()),
288289
evaluated: IndexVec::with_capacity(num_values),
289-
next_opaque: Some(0),
290+
next_opaque: Some(1),
290291
feature_unsized_locals: tcx.features().unsized_locals,
291292
ssa,
292293
dominators,
@@ -358,6 +359,7 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
358359
let next_opaque = self.next_opaque.as_mut()?;
359360
let disambiguator = *next_opaque;
360361
*next_opaque += 1;
362+
assert_ne!(disambiguator, 0);
361363
disambiguator
362364
};
363365
Some(self.insert(Value::Constant { value, disambiguator }))
@@ -1385,12 +1387,11 @@ impl<'tcx> VnState<'_, 'tcx> {
13851387

13861388
/// If `index` is a `Value::Constant`, return the `Constant` to be put in the MIR.
13871389
fn try_as_constant(&mut self, index: VnIndex) -> Option<ConstOperand<'tcx>> {
1388-
// This was already constant in MIR, do not change it.
1389-
if let Value::Constant { value, disambiguator: _ } = *self.get(index)
1390-
// If the constant is not deterministic, adding an additional mention of it in MIR will
1391-
// not give the same value as the former mention.
1392-
&& value.is_deterministic()
1393-
{
1390+
// This was already constant in MIR, do not change it. If the constant is not
1391+
// deterministic, adding an additional mention of it in MIR will not give the same value as
1392+
// the former mention.
1393+
if let Value::Constant { value, disambiguator: 0 } = *self.get(index) {
1394+
assert!(value.is_deterministic());
13941395
return Some(ConstOperand { span: DUMMY_SP, user_ty: None, const_: value });
13951396
}
13961397

0 commit comments

Comments
 (0)