about summary refs log tree commit diff
path: root/compiler/rustc_mir_dataflow/src/framework/lattice.rs
diff options
context:
space:
mode:
authorJannis Christopher Köhl <mail@koehl.dev>2022-10-25 00:56:51 +0200
committerJannis Christopher Köhl <mail@koehl.dev>2022-11-07 10:35:25 +0100
commit1f82a9f89e3c0388442835df632b56ccea08a971 (patch)
treef01da01ab1a395307a6cd54a407d00d3fb524bb9 /compiler/rustc_mir_dataflow/src/framework/lattice.rs
parentf29533b4e031771dae471bff534e3cc03ab48cd4 (diff)
downloadrust-1f82a9f89e3c0388442835df632b56ccea08a971.tar.gz
rust-1f82a9f89e3c0388442835df632b56ccea08a971.zip
Move HasTop and HasBottom into lattice.rs
Diffstat (limited to 'compiler/rustc_mir_dataflow/src/framework/lattice.rs')
-rw-r--r--compiler/rustc_mir_dataflow/src/framework/lattice.rs34
1 files changed, 34 insertions, 0 deletions
diff --git a/compiler/rustc_mir_dataflow/src/framework/lattice.rs b/compiler/rustc_mir_dataflow/src/framework/lattice.rs
index d6b89eb8227..f0e75c53ea1 100644
--- a/compiler/rustc_mir_dataflow/src/framework/lattice.rs
+++ b/compiler/rustc_mir_dataflow/src/framework/lattice.rs
@@ -73,6 +73,16 @@ pub trait MeetSemiLattice: Eq {
     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:
 ///
 /// ```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
 /// 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
     }
 }
+
+impl<T> HasBottom for FlatSet<T> {
+    fn bottom() -> Self {
+        Self::Bottom
+    }
+}
+
+impl<T> HasTop for FlatSet<T> {
+    fn top() -> Self {
+        Self::Top
+    }
+}