Skip to content

Commit 4b94235

Browse files
Rollup merge of #150223 - dianqk:gvn-insert_unique, r=cjgillot
GVN: Adds the `insert_unique` method The new `insert_unique` method is used to handle `IndexVec<VnIndex, T>` such as `evaluated` and `rev_locals`.
2 parents e0dba51 + 37af3f6 commit 4b94235

File tree

1 file changed

+20
-23
lines changed
  • compiler/rustc_mir_transform/src

1 file changed

+20
-23
lines changed

compiler/rustc_mir_transform/src/gvn.rs

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,19 @@ impl<'body, 'a, 'tcx> VnState<'body, 'a, 'tcx> {
420420
self.ecx.typing_env()
421421
}
422422

423+
fn insert_unique(
424+
&mut self,
425+
ty: Ty<'tcx>,
426+
value: impl FnOnce(VnOpaque) -> Value<'a, 'tcx>,
427+
) -> VnIndex {
428+
let index = self.values.insert_unique(ty, value);
429+
let _index = self.evaluated.push(None);
430+
debug_assert_eq!(index, _index);
431+
let _index = self.rev_locals.push(SmallVec::new());
432+
debug_assert_eq!(index, _index);
433+
index
434+
}
435+
423436
#[instrument(level = "trace", skip(self), ret)]
424437
fn insert(&mut self, ty: Ty<'tcx>, value: Value<'a, 'tcx>) -> VnIndex {
425438
let (index, new) = self.values.insert(ty, value);
@@ -437,11 +450,8 @@ impl<'body, 'a, 'tcx> VnState<'body, 'a, 'tcx> {
437450
/// from all the others.
438451
#[instrument(level = "trace", skip(self), ret)]
439452
fn new_opaque(&mut self, ty: Ty<'tcx>) -> VnIndex {
440-
let index = self.values.insert_unique(ty, Value::Opaque);
441-
let _index = self.evaluated.push(Some(None));
442-
debug_assert_eq!(index, _index);
443-
let _index = self.rev_locals.push(SmallVec::new());
444-
debug_assert_eq!(index, _index);
453+
let index = self.insert_unique(ty, Value::Opaque);
454+
self.evaluated[index] = Some(None);
445455
index
446456
}
447457

@@ -470,42 +480,29 @@ impl<'body, 'a, 'tcx> VnState<'body, 'a, 'tcx> {
470480
projection.map(|proj| proj.try_map(|index| self.locals[index], |ty| ty).ok_or(()));
471481
let projection = self.arena.try_alloc_from_iter(projection).ok()?;
472482

473-
let index = self.values.insert_unique(ty, |provenance| Value::Address {
483+
let index = self.insert_unique(ty, |provenance| Value::Address {
474484
base,
475485
projection,
476486
kind,
477487
provenance,
478488
});
479-
let _index = self.evaluated.push(None);
480-
debug_assert_eq!(index, _index);
481-
let _index = self.rev_locals.push(SmallVec::new());
482-
debug_assert_eq!(index, _index);
483-
484489
Some(index)
485490
}
486491

487492
#[instrument(level = "trace", skip(self), ret)]
488493
fn insert_constant(&mut self, value: Const<'tcx>) -> VnIndex {
489-
let (index, new) = if value.is_deterministic() {
494+
if value.is_deterministic() {
490495
// The constant is deterministic, no need to disambiguate.
491496
let constant = Value::Constant { value, disambiguator: None };
492-
self.values.insert(value.ty(), constant)
497+
self.insert(value.ty(), constant)
493498
} else {
494499
// Multiple mentions of this constant will yield different values,
495500
// so assign a different `disambiguator` to ensure they do not get the same `VnIndex`.
496-
let index = self.values.insert_unique(value.ty(), |disambiguator| Value::Constant {
501+
self.insert_unique(value.ty(), |disambiguator| Value::Constant {
497502
value,
498503
disambiguator: Some(disambiguator),
499-
});
500-
(index, true)
501-
};
502-
if new {
503-
let _index = self.evaluated.push(None);
504-
debug_assert_eq!(index, _index);
505-
let _index = self.rev_locals.push(SmallVec::new());
506-
debug_assert_eq!(index, _index);
504+
})
507505
}
508-
index
509506
}
510507

511508
#[inline]

0 commit comments

Comments
 (0)