8
8
//! Tests borrowed from the MonotonicFixpointIteratorTest.cpp in the C++ version.
9
9
10
10
mod liveness {
11
+ use std:: borrow:: Cow ;
11
12
use std:: collections:: HashMap ;
12
13
13
14
use im:: HashSet ;
@@ -147,8 +148,8 @@ mod liveness {
147
148
}
148
149
149
150
trait LivenessAnalysis {
150
- fn get_live_in_vars_at ( & self , n : NodeId ) -> LivenessDomain ;
151
- fn get_live_out_vars_at ( & self , n : NodeId ) -> LivenessDomain ;
151
+ fn get_live_in_vars_at ( & self , n : NodeId ) -> Cow < ' _ , LivenessDomain > ;
152
+ fn get_live_out_vars_at ( & self , n : NodeId ) -> Cow < ' _ , LivenessDomain > ;
152
153
}
153
154
154
155
type LivenessFixpointIterator < ' g > = MonotonicFixpointIterator <
@@ -159,11 +160,11 @@ mod liveness {
159
160
> ;
160
161
161
162
impl < ' g > LivenessAnalysis for LivenessFixpointIterator < ' g > {
162
- fn get_live_in_vars_at ( & self , n : NodeId ) -> LivenessDomain {
163
+ fn get_live_in_vars_at ( & self , n : NodeId ) -> Cow < ' _ , LivenessDomain > {
163
164
self . get_exit_state_at ( n)
164
165
}
165
166
166
- fn get_live_out_vars_at ( & self , n : NodeId ) -> LivenessDomain {
167
+ fn get_live_out_vars_at ( & self , n : NodeId ) -> Cow < ' _ , LivenessDomain > {
167
168
self . get_entry_state_at ( n)
168
169
}
169
170
}
@@ -283,12 +284,12 @@ mod liveness {
283
284
macro_rules! assert_analysis {
284
285
( $fp: ident, $index: literal, [ $( $live_in_vars: literal) ,* ] , [ $( $live_out_vars: literal) ,* ] ) => {
285
286
assert!( matches!(
286
- $fp. get_exit_state_at( $index) ,
287
- LivenessDomain :: Value ( _)
287
+ $fp. get_exit_state_at( $index) . as_ref ( ) ,
288
+ & LivenessDomain :: Value ( _)
288
289
) ) ;
289
290
assert!( matches!(
290
- $fp. get_entry_state_at( $index) ,
291
- LivenessDomain :: Value ( _)
291
+ $fp. get_entry_state_at( $index) . as_ref ( ) ,
292
+ & LivenessDomain :: Value ( _)
292
293
) ) ;
293
294
assert_analysis_values!( $fp, $index, get_live_in_vars_at, [ $( $live_in_vars) ,* ] ) ;
294
295
assert_analysis_values!( $fp, $index, get_live_out_vars_at, [ $( $live_out_vars) ,* ] ) ;
@@ -351,8 +352,14 @@ mod liveness {
351
352
assert_analysis ! ( fp, 5 , [ "a" , "b" , "y" ] , [ "a" , "b" , "x" , "y" ] ) ;
352
353
353
354
// 7: x = y + a;
354
- assert ! ( matches!( fp. get_exit_state_at( 6 ) , LivenessDomain :: Bottom ) ) ;
355
- assert ! ( matches!( fp. get_entry_state_at( 6 ) , LivenessDomain :: Bottom ) ) ;
355
+ assert ! ( matches!(
356
+ fp. get_exit_state_at( 6 ) . as_ref( ) ,
357
+ & LivenessDomain :: Bottom
358
+ ) ) ;
359
+ assert ! ( matches!(
360
+ fp. get_entry_state_at( 6 ) . as_ref( ) ,
361
+ & LivenessDomain :: Bottom
362
+ ) ) ;
356
363
}
357
364
358
365
#[ test]
@@ -771,7 +778,7 @@ mod numerical {
771
778
772
779
let bb1 = 0 ;
773
780
assert_eq ! (
774
- fp. get_entry_state_at( bb1) ,
781
+ fp. get_entry_state_at( bb1) . into_owned ( ) ,
775
782
IntegerSetAbstractEnvironment :: top( )
776
783
) ;
777
784
assert_eq ! (
@@ -829,7 +836,7 @@ mod numerical {
829
836
830
837
let bb1 = 0 ;
831
838
assert_eq ! (
832
- fp. get_entry_state_at( bb1) ,
839
+ fp. get_entry_state_at( bb1) . into_owned ( ) ,
833
840
IntegerSetAbstractEnvironment :: top( )
834
841
) ;
835
842
assert_eq ! (
0 commit comments