Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 1f82a9f

Browse files
committed
Move HasTop and HasBottom into lattice.rs
1 parent f29533b commit 1f82a9f

File tree

3 files changed

+42
-27
lines changed

3 files changed

+42
-27
lines changed

compiler/rustc_mir_dataflow/src/framework/lattice.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,16 @@ pub trait MeetSemiLattice: Eq {
7373
fn meet(&mut self, other: &Self) -> bool;
7474
}
7575

76+
/// A set that has a "bottom" element, which is less than or equal to any other element.
77+
pub trait HasBottom {
78+
fn bottom() -> Self;
79+
}
80+
81+
/// A set that has a "top" element, which is greater than or equal to any other element.
82+
pub trait HasTop {
83+
fn top() -> Self;
84+
}
85+
7686
/// A `bool` is a "two-point" lattice with `true` as the top element and `false` as the bottom:
7787
///
7888
/// ```text
@@ -102,6 +112,18 @@ impl MeetSemiLattice for bool {
102112
}
103113
}
104114

115+
impl HasBottom for bool {
116+
fn bottom() -> Self {
117+
false
118+
}
119+
}
120+
121+
impl HasTop for bool {
122+
fn top() -> Self {
123+
true
124+
}
125+
}
126+
105127
/// A tuple (or list) of lattices is itself a lattice whose least upper bound is the concatenation
106128
/// of the least upper bounds of each element of the tuple (or list).
107129
///
@@ -250,3 +272,15 @@ impl<T: Clone + Eq> MeetSemiLattice for FlatSet<T> {
250272
true
251273
}
252274
}
275+
276+
impl<T> HasBottom for FlatSet<T> {
277+
fn bottom() -> Self {
278+
Self::Bottom
279+
}
280+
}
281+
282+
impl<T> HasTop for FlatSet<T> {
283+
fn top() -> Self {
284+
Self::Top
285+
}
286+
}

compiler/rustc_mir_dataflow/src/value_analysis.rs

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,10 @@ use rustc_middle::ty::{self, Ty, TyCtxt};
5656
use rustc_span::DUMMY_SP;
5757
use rustc_target::abi::VariantIdx;
5858

59+
use crate::lattice::{HasBottom, HasTop};
5960
use crate::{
60-
fmt::DebugWithContext, lattice::FlatSet, Analysis, AnalysisDomain, CallReturnPlaces,
61-
JoinSemiLattice, SwitchIntEdgeEffects,
61+
fmt::DebugWithContext, Analysis, AnalysisDomain, CallReturnPlaces, JoinSemiLattice,
62+
SwitchIntEdgeEffects,
6263
};
6364

6465
pub trait ValueAnalysis<'tcx> {
@@ -846,8 +847,8 @@ pub enum ValueOrPlace<V> {
846847
Place(PlaceIndex),
847848
}
848849

849-
impl<V: HasTop> HasTop for ValueOrPlace<V> {
850-
fn top() -> Self {
850+
impl<V: HasTop> ValueOrPlace<V> {
851+
pub fn top() -> Self {
851852
ValueOrPlace::Value(V::top())
852853
}
853854
}
@@ -859,8 +860,8 @@ pub enum ValueOrPlaceOrRef<V> {
859860
Ref(PlaceIndex),
860861
}
861862

862-
impl<V: HasTop> HasTop for ValueOrPlaceOrRef<V> {
863-
fn top() -> Self {
863+
impl<V: HasTop> ValueOrPlaceOrRef<V> {
864+
pub fn top() -> Self {
864865
ValueOrPlaceOrRef::Value(V::top())
865866
}
866867
}
@@ -874,26 +875,6 @@ impl<V> From<ValueOrPlace<V>> for ValueOrPlaceOrRef<V> {
874875
}
875876
}
876877

877-
pub trait HasBottom {
878-
fn bottom() -> Self;
879-
}
880-
881-
pub trait HasTop {
882-
fn top() -> Self;
883-
}
884-
885-
impl<V> HasBottom for FlatSet<V> {
886-
fn bottom() -> Self {
887-
Self::Bottom
888-
}
889-
}
890-
891-
impl<V> HasTop for FlatSet<V> {
892-
fn top() -> Self {
893-
Self::Top
894-
}
895-
}
896-
897878
/// The set of projection elements that can be used by a tracked place.
898879
///
899880
/// For now, downcast is not allowed due to aliasing between variants (see #101168).

compiler/rustc_mir_transform/src/dataflow_const_prop.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustc_middle::mir::visit::{MutVisitor, Visitor};
88
use rustc_middle::mir::*;
99
use rustc_middle::ty::{self, Ty, TyCtxt};
1010
use rustc_mir_dataflow::value_analysis::{
11-
HasTop, Map, State, TrackElem, ValueAnalysis, ValueOrPlace, ValueOrPlaceOrRef,
11+
Map, State, TrackElem, ValueAnalysis, ValueOrPlace, ValueOrPlaceOrRef,
1212
};
1313
use rustc_mir_dataflow::{lattice::FlatSet, Analysis, ResultsVisitor, SwitchIntEdgeEffects};
1414
use rustc_span::DUMMY_SP;

0 commit comments

Comments
 (0)