Skip to content

Commit 7ab1ba9

Browse files
committed
Remove Unknown state in favor of Value(Top)
1 parent 1765587 commit 7ab1ba9

File tree

2 files changed

+21
-20
lines changed

2 files changed

+21
-20
lines changed

compiler/rustc_mir_dataflow/src/value_analysis.rs

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -183,15 +183,15 @@ pub trait ValueAnalysis<'tcx> {
183183
.map()
184184
.find(place.as_ref())
185185
.map(ValueOrPlaceOrRef::Ref)
186-
.unwrap_or(ValueOrPlaceOrRef::Unknown),
186+
.unwrap_or(ValueOrPlaceOrRef::top()),
187187
Rvalue::Ref(_, _, place) | Rvalue::AddressOf(_, place) => {
188188
state.flood(place.as_ref(), self.map());
189-
ValueOrPlaceOrRef::Unknown
189+
ValueOrPlaceOrRef::top()
190190
}
191191
Rvalue::CopyForDeref(place) => {
192192
self.handle_operand(&Operand::Copy(*place), state).into()
193193
}
194-
_ => ValueOrPlaceOrRef::Unknown,
194+
_ => ValueOrPlaceOrRef::top(),
195195
}
196196
}
197197

@@ -218,7 +218,7 @@ pub trait ValueAnalysis<'tcx> {
218218
self.map()
219219
.find(place.as_ref())
220220
.map(ValueOrPlace::Place)
221-
.unwrap_or(ValueOrPlace::Unknown)
221+
.unwrap_or(ValueOrPlace::top())
222222
}
223223
}
224224
}
@@ -511,9 +511,6 @@ impl<V: Clone + HasTop> State<V> {
511511
self.assign_place_idx(target_deref, source, map);
512512
}
513513
}
514-
ValueOrPlaceOrRef::Unknown => {
515-
self.flood_idx(target, map);
516-
}
517514
}
518515
}
519516

@@ -756,27 +753,35 @@ impl<'a> Iterator for Children<'a> {
756753
}
757754
}
758755
}
759-
760-
// FIXME: See if we can get rid of `Unknown`.
761756
pub enum ValueOrPlace<V> {
762757
Value(V),
763758
Place(PlaceIndex),
764-
Unknown,
759+
}
760+
761+
impl<V: HasTop> ValueOrPlace<V> {
762+
pub fn top() -> Self {
763+
ValueOrPlace::Value(V::top())
764+
}
765765
}
766766

767767
pub enum ValueOrPlaceOrRef<V> {
768768
Value(V),
769769
Place(PlaceIndex),
770-
Ref(PlaceIndex),
771-
Unknown,
770+
Ref(PlaceIndex)
772771
}
773772

773+
impl<V: HasTop> ValueOrPlaceOrRef<V> {
774+
pub fn top() -> Self {
775+
ValueOrPlaceOrRef::Value(V::top())
776+
}
777+
}
778+
779+
774780
impl<V> From<ValueOrPlace<V>> for ValueOrPlaceOrRef<V> {
775781
fn from(x: ValueOrPlace<V>) -> Self {
776782
match x {
777783
ValueOrPlace::Value(value) => ValueOrPlaceOrRef::Value(value),
778784
ValueOrPlace::Place(place) => ValueOrPlaceOrRef::Place(place),
779-
ValueOrPlace::Unknown => ValueOrPlaceOrRef::Unknown,
780785
}
781786
}
782787
}

compiler/rustc_mir_transform/src/dataflow_const_prop.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ impl<'tcx> ValueAnalysis<'tcx> for ConstAnalysis<'tcx> {
105105
.ecx
106106
.misc_cast(&operand, *ty)
107107
.map(|result| ValueOrPlaceOrRef::Value(self.wrap_immediate(result, *ty)))
108-
.unwrap_or(ValueOrPlaceOrRef::Unknown),
109-
_ => ValueOrPlaceOrRef::Unknown,
108+
.unwrap_or(ValueOrPlaceOrRef::top()),
109+
_ => ValueOrPlaceOrRef::top(),
110110
}
111111
}
112112
Rvalue::BinaryOp(op, box (left, right)) => {
@@ -156,7 +156,6 @@ impl<'tcx> ValueAnalysis<'tcx> for ConstAnalysis<'tcx> {
156156
let value = match self.handle_operand(discr, state) {
157157
ValueOrPlace::Value(value) => value,
158158
ValueOrPlace::Place(place) => state.get_idx(place, self.map()),
159-
ValueOrPlace::Unknown => FlatSet::Top,
160159
};
161160
let result = match value {
162161
FlatSet::Top => FlatSet::Top,
@@ -241,7 +240,6 @@ impl<'tcx> ConstAnalysis<'tcx> {
241240
let value = match self.handle_operand(op, state) {
242241
ValueOrPlace::Value(value) => value,
243242
ValueOrPlace::Place(place) => state.get_idx(place, &self.map),
244-
ValueOrPlace::Unknown => FlatSet::Top,
245243
};
246244
match value {
247245
FlatSet::Top => FlatSet::Top,
@@ -384,9 +382,7 @@ impl<'tcx, 'map, 'a> Visitor<'tcx> for OperandCollector<'tcx, 'map, 'a> {
384382
FlatSet::Elem(value) => {
385383
self.visitor.before_effect.insert((location, *place), value);
386384
}
387-
FlatSet::Bottom => {
388-
// This only happens if this location is unreachable.
389-
}
385+
FlatSet::Bottom => (),
390386
}
391387
}
392388
_ => (),

0 commit comments

Comments
 (0)