Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions rust-proc-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,17 @@ pub fn derive_disjoint_union(input: TokenStream) -> TokenStream {

fn join_with(&mut self, rhs: Self) {
match (self, rhs) {
(_, r) if r.is_bottom() => {/*do nothing because bottom is the identity element of join*/},
(s, r) if s.is_bottom() => *s = r,
#( (#enum_name::#variant_idents(ref mut ldom), #enum_name::#variant_idents(rdom)) => ldom.join_with(rdom), )*
(s, _) => *s = Self::top(),
}
}

fn meet_with(&mut self, rhs: Self) {
match (self, rhs) {
(_, r) if r.is_top() => {/*do nothing because top is the identity element of meet*/},
(s, r) if s.is_top() => *s = r,
#( (#enum_name::#variant_idents(ref mut ldom), #enum_name::#variant_idents(rdom)) => ldom.meet_with(rdom), )*
(s, _) => *s = Self::bottom(),
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ use sparta::datatype::AbstractDomain;
use sparta::datatype::DisjointUnion;
use sparta::datatype::HashSetAbstractDomain;

#[derive(Clone, DisjointUnion, PartialEq, Eq)]
#[allow(dead_code)]
#[derive(Clone, DisjointUnion, PartialEq, Eq, Debug)]
enum MyUnionedDomain {
FirstCase(HashSetAbstractDomain<i32>),
SecondCase(HashSetAbstractDomain<i64>),
Expand Down Expand Up @@ -119,6 +120,31 @@ fn test_meet_diff_arm() {
assert!(met_mudom.is_bottom());
}

#[test]
fn test_bottom_is_right_identity_of_join() {
let mudom = MyUnionedDomain::SecondCase([1].into_iter().collect());
assert_eq!(mudom.clone().join(MyUnionedDomain::bottom()), mudom.clone());
}

#[test]
fn test_bottom_is_left_identity_of_join() {
let mudom = MyUnionedDomain::SecondCase([1].into_iter().collect());
assert_eq!(MyUnionedDomain::bottom().join(mudom.clone()), mudom);
}

#[test]
fn test_top_is_right_identity_of_meet() {
let mudom = MyUnionedDomain::SecondCase([1].into_iter().collect());
assert_eq!(mudom.clone().meet(MyUnionedDomain::top()), mudom.clone());
}

#[test]
fn test_top_is_left_identity_of_meet() {
let mudom = MyUnionedDomain::SecondCase([1].into_iter().collect());
assert_eq!(MyUnionedDomain::top().meet(mudom.clone()), mudom);
}

#[allow(dead_code)]
#[derive(Clone, DisjointUnion, PartialEq, Eq)]
enum TestGenericsDeriveTypechecks<S, T>
where
Expand All @@ -129,6 +155,7 @@ where
SecondCase(HashSetAbstractDomain<T>),
}

#[allow(dead_code)]
#[derive(Clone, DisjointUnion, PartialEq, Eq)]
enum TestGenericsDeriveForWholeDomainTypechecks<S: AbstractDomain, T>
where
Expand Down