Skip to content

Commit cdaef2c

Browse files
committed
Simplify duplicate checks for mir validator
1 parent 70db836 commit cdaef2c

File tree

1 file changed

+9
-14
lines changed

1 file changed

+9
-14
lines changed

compiler/rustc_const_eval/src/transform/validate.rs

+9-14
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ impl<'tcx> MirPass<'tcx> for Validator {
6767
unwind_edge_count: 0,
6868
reachable_blocks: traversal::reachable_as_bitset(body),
6969
storage_liveness,
70-
place_cache: Vec::new(),
71-
value_cache: Vec::new(),
70+
place_cache: FxHashSet::default(),
71+
value_cache: FxHashSet::default(),
7272
};
7373
checker.visit_body(body);
7474
checker.check_cleanup_control_flow();
@@ -95,8 +95,8 @@ struct TypeChecker<'a, 'tcx> {
9595
unwind_edge_count: usize,
9696
reachable_blocks: BitSet<BasicBlock>,
9797
storage_liveness: ResultsCursor<'a, 'tcx, MaybeStorageLive<'static>>,
98-
place_cache: Vec<PlaceRef<'tcx>>,
99-
value_cache: Vec<u128>,
98+
place_cache: FxHashSet<PlaceRef<'tcx>>,
99+
value_cache: FxHashSet<u128>,
100100
}
101101

102102
impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
@@ -958,10 +958,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
958958

959959
self.value_cache.clear();
960960
self.value_cache.extend(targets.iter().map(|(value, _)| value));
961-
let all_len = self.value_cache.len();
962-
self.value_cache.sort_unstable();
963-
self.value_cache.dedup();
964-
let has_duplicates = all_len != self.value_cache.len();
961+
let has_duplicates = targets.iter().len() != self.value_cache.len();
965962
if has_duplicates {
966963
self.fail(
967964
location,
@@ -994,16 +991,14 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
994991
// passed by a reference to the callee. Consequently they must be non-overlapping.
995992
// Currently this simply checks for duplicate places.
996993
self.place_cache.clear();
997-
self.place_cache.push(destination.as_ref());
994+
self.place_cache.insert(destination.as_ref());
995+
let mut has_duplicates = false;
998996
for arg in args {
999997
if let Operand::Move(place) = arg {
1000-
self.place_cache.push(place.as_ref());
998+
has_duplicates |= !self.place_cache.insert(place.as_ref());
1001999
}
10021000
}
1003-
let all_len = self.place_cache.len();
1004-
let mut dedup = FxHashSet::default();
1005-
self.place_cache.retain(|p| dedup.insert(*p));
1006-
let has_duplicates = all_len != self.place_cache.len();
1001+
10071002
if has_duplicates {
10081003
self.fail(
10091004
location,

0 commit comments

Comments
 (0)