mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-29 10:13:54 +00:00
Move HasTop and HasBottom into lattice.rs
This commit is contained in:
parent
f29533b4e0
commit
1f82a9f89e
@ -73,6 +73,16 @@ pub trait MeetSemiLattice: Eq {
|
|||||||
fn meet(&mut self, other: &Self) -> bool;
|
fn meet(&mut self, other: &Self) -> bool;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A set that has a "bottom" element, which is less than or equal to any other element.
|
||||||
|
pub trait HasBottom {
|
||||||
|
fn bottom() -> Self;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A set that has a "top" element, which is greater than or equal to any other element.
|
||||||
|
pub trait HasTop {
|
||||||
|
fn top() -> Self;
|
||||||
|
}
|
||||||
|
|
||||||
/// A `bool` is a "two-point" lattice with `true` as the top element and `false` as the bottom:
|
/// A `bool` is a "two-point" lattice with `true` as the top element and `false` as the bottom:
|
||||||
///
|
///
|
||||||
/// ```text
|
/// ```text
|
||||||
@ -102,6 +112,18 @@ impl MeetSemiLattice for bool {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl HasBottom for bool {
|
||||||
|
fn bottom() -> Self {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl HasTop for bool {
|
||||||
|
fn top() -> Self {
|
||||||
|
true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// A tuple (or list) of lattices is itself a lattice whose least upper bound is the concatenation
|
/// A tuple (or list) of lattices is itself a lattice whose least upper bound is the concatenation
|
||||||
/// of the least upper bounds of each element of the tuple (or list).
|
/// of the least upper bounds of each element of the tuple (or list).
|
||||||
///
|
///
|
||||||
@ -250,3 +272,15 @@ impl<T: Clone + Eq> MeetSemiLattice for FlatSet<T> {
|
|||||||
true
|
true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<T> HasBottom for FlatSet<T> {
|
||||||
|
fn bottom() -> Self {
|
||||||
|
Self::Bottom
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T> HasTop for FlatSet<T> {
|
||||||
|
fn top() -> Self {
|
||||||
|
Self::Top
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -56,9 +56,10 @@ use rustc_middle::ty::{self, Ty, TyCtxt};
|
|||||||
use rustc_span::DUMMY_SP;
|
use rustc_span::DUMMY_SP;
|
||||||
use rustc_target::abi::VariantIdx;
|
use rustc_target::abi::VariantIdx;
|
||||||
|
|
||||||
|
use crate::lattice::{HasBottom, HasTop};
|
||||||
use crate::{
|
use crate::{
|
||||||
fmt::DebugWithContext, lattice::FlatSet, Analysis, AnalysisDomain, CallReturnPlaces,
|
fmt::DebugWithContext, Analysis, AnalysisDomain, CallReturnPlaces, JoinSemiLattice,
|
||||||
JoinSemiLattice, SwitchIntEdgeEffects,
|
SwitchIntEdgeEffects,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub trait ValueAnalysis<'tcx> {
|
pub trait ValueAnalysis<'tcx> {
|
||||||
@ -846,8 +847,8 @@ pub enum ValueOrPlace<V> {
|
|||||||
Place(PlaceIndex),
|
Place(PlaceIndex),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<V: HasTop> HasTop for ValueOrPlace<V> {
|
impl<V: HasTop> ValueOrPlace<V> {
|
||||||
fn top() -> Self {
|
pub fn top() -> Self {
|
||||||
ValueOrPlace::Value(V::top())
|
ValueOrPlace::Value(V::top())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -859,8 +860,8 @@ pub enum ValueOrPlaceOrRef<V> {
|
|||||||
Ref(PlaceIndex),
|
Ref(PlaceIndex),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<V: HasTop> HasTop for ValueOrPlaceOrRef<V> {
|
impl<V: HasTop> ValueOrPlaceOrRef<V> {
|
||||||
fn top() -> Self {
|
pub fn top() -> Self {
|
||||||
ValueOrPlaceOrRef::Value(V::top())
|
ValueOrPlaceOrRef::Value(V::top())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -874,26 +875,6 @@ impl<V> From<ValueOrPlace<V>> for ValueOrPlaceOrRef<V> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait HasBottom {
|
|
||||||
fn bottom() -> Self;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub trait HasTop {
|
|
||||||
fn top() -> Self;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<V> HasBottom for FlatSet<V> {
|
|
||||||
fn bottom() -> Self {
|
|
||||||
Self::Bottom
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<V> HasTop for FlatSet<V> {
|
|
||||||
fn top() -> Self {
|
|
||||||
Self::Top
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The set of projection elements that can be used by a tracked place.
|
/// The set of projection elements that can be used by a tracked place.
|
||||||
///
|
///
|
||||||
/// For now, downcast is not allowed due to aliasing between variants (see #101168).
|
/// For now, downcast is not allowed due to aliasing between variants (see #101168).
|
||||||
|
@ -8,7 +8,7 @@ use rustc_middle::mir::visit::{MutVisitor, Visitor};
|
|||||||
use rustc_middle::mir::*;
|
use rustc_middle::mir::*;
|
||||||
use rustc_middle::ty::{self, Ty, TyCtxt};
|
use rustc_middle::ty::{self, Ty, TyCtxt};
|
||||||
use rustc_mir_dataflow::value_analysis::{
|
use rustc_mir_dataflow::value_analysis::{
|
||||||
HasTop, Map, State, TrackElem, ValueAnalysis, ValueOrPlace, ValueOrPlaceOrRef,
|
Map, State, TrackElem, ValueAnalysis, ValueOrPlace, ValueOrPlaceOrRef,
|
||||||
};
|
};
|
||||||
use rustc_mir_dataflow::{lattice::FlatSet, Analysis, ResultsVisitor, SwitchIntEdgeEffects};
|
use rustc_mir_dataflow::{lattice::FlatSet, Analysis, ResultsVisitor, SwitchIntEdgeEffects};
|
||||||
use rustc_span::DUMMY_SP;
|
use rustc_span::DUMMY_SP;
|
||||||
|
Loading…
Reference in New Issue
Block a user