3
3
// https://github.com/proptest-rs/proptest/issues/447
4
4
#![ cfg_attr( test, allow( non_local_definitions) ) ]
5
5
6
- use std:: cmp:: Ordering ;
7
-
8
6
use ascent:: lattice:: { BoundedLattice , Lattice } ;
9
7
10
8
use super :: super :: partial_value:: { AbstractValue , PartialValue } ;
11
9
use hugr_core:: { types:: Signature , HugrView , IncomingPort , Node , OutgoingPort } ;
12
10
13
- #[ cfg( test) ]
14
- use proptest_derive:: Arbitrary ;
15
-
16
11
impl < V : AbstractValue > Lattice for PartialValue < V > {
17
12
fn meet ( self , other : Self ) -> Self {
18
13
self . meet ( other)
@@ -57,7 +52,6 @@ pub(super) fn value_outputs(h: &impl HugrView, n: Node) -> impl Iterator<Item =
57
52
}
58
53
59
54
#[ derive( PartialEq , Eq , Hash , Debug , Clone , Copy ) ]
60
- #[ cfg_attr( test, derive( Arbitrary ) ) ]
61
55
pub enum TailLoopTermination {
62
56
Bottom ,
63
57
ExactlyZeroContinues ,
@@ -70,114 +64,9 @@ impl TailLoopTermination {
70
64
if may_break && !may_continue {
71
65
Self :: ExactlyZeroContinues
72
66
} else if may_break && may_continue {
73
- Self :: top ( )
67
+ Self :: Top
74
68
} else {
75
- Self :: bottom ( )
76
- }
77
- }
78
- }
79
-
80
- impl PartialOrd for TailLoopTermination {
81
- fn partial_cmp ( & self , other : & Self ) -> Option < std:: cmp:: Ordering > {
82
- if self == other {
83
- return Some ( std:: cmp:: Ordering :: Equal ) ;
84
- } ;
85
- match ( self , other) {
86
- ( Self :: Bottom , _) => Some ( Ordering :: Less ) ,
87
- ( _, Self :: Bottom ) => Some ( Ordering :: Greater ) ,
88
- ( Self :: Top , _) => Some ( Ordering :: Greater ) ,
89
- ( _, Self :: Top ) => Some ( Ordering :: Less ) ,
90
- _ => None ,
91
- }
92
- }
93
- }
94
-
95
- impl Lattice for TailLoopTermination {
96
- fn meet ( mut self , other : Self ) -> Self {
97
- self . meet_mut ( other) ;
98
- self
99
- }
100
-
101
- fn join ( mut self , other : Self ) -> Self {
102
- self . join_mut ( other) ;
103
- self
104
- }
105
-
106
- fn meet_mut ( & mut self , other : Self ) -> bool {
107
- // let new_self = &mut self;
108
- match ( * self ) . partial_cmp ( & other) {
109
- Some ( Ordering :: Greater ) => {
110
- * self = other;
111
- true
112
- }
113
- Some ( _) => false ,
114
- _ => {
115
- * self = Self :: Bottom ;
116
- true
117
- }
118
- }
119
- }
120
-
121
- fn join_mut ( & mut self , other : Self ) -> bool {
122
- match ( * self ) . partial_cmp ( & other) {
123
- Some ( Ordering :: Less ) => {
124
- * self = other;
125
- true
126
- }
127
- Some ( _) => false ,
128
- _ => {
129
- * self = Self :: Top ;
130
- true
131
- }
132
- }
133
- }
134
- }
135
-
136
- impl BoundedLattice for TailLoopTermination {
137
- fn bottom ( ) -> Self {
138
- Self :: Bottom
139
- }
140
-
141
- fn top ( ) -> Self {
142
- Self :: Top
143
- }
144
- }
145
-
146
- #[ cfg( test) ]
147
- #[ cfg_attr( test, allow( non_local_definitions) ) ]
148
- mod test {
149
- use super :: * ;
150
- use proptest:: prelude:: * ;
151
-
152
- proptest ! {
153
- #[ test]
154
- fn bounded_lattice( v: TailLoopTermination ) {
155
- prop_assert!( v <= TailLoopTermination :: top( ) ) ;
156
- prop_assert!( v >= TailLoopTermination :: bottom( ) ) ;
157
- }
158
-
159
- #[ test]
160
- fn meet_join_self_noop( v1: TailLoopTermination ) {
161
- let mut subject = v1. clone( ) ;
162
-
163
- assert_eq!( v1. clone( ) , v1. clone( ) . join( v1. clone( ) ) ) ;
164
- assert!( !subject. join_mut( v1. clone( ) ) ) ;
165
- assert_eq!( subject, v1) ;
166
-
167
- assert_eq!( v1. clone( ) , v1. clone( ) . meet( v1. clone( ) ) ) ;
168
- assert!( !subject. meet_mut( v1. clone( ) ) ) ;
169
- assert_eq!( subject, v1) ;
170
- }
171
-
172
- #[ test]
173
- fn lattice( v1: TailLoopTermination , v2: TailLoopTermination ) {
174
- let meet = v1. clone( ) . meet( v2. clone( ) ) ;
175
- prop_assert!( meet <= v1, "meet not less <=: {:#?}" , & meet) ;
176
- prop_assert!( meet <= v2, "meet not less <=: {:#?}" , & meet) ;
177
-
178
- let join = v1. clone( ) . join( v2. clone( ) ) ;
179
- prop_assert!( join >= v1, "join not >=: {:#?}" , & join) ;
180
- prop_assert!( join >= v2, "join not >=: {:#?}" , & join) ;
69
+ Self :: Bottom
181
70
}
182
71
}
183
72
}
0 commit comments