@@ -376,6 +376,9 @@ fn verify_method(m: &Method, cx: &mut slang_ui::Context, solver: &mut Solver<Z3B
376
376
377
377
let dsa = ivl_to_dsa ( & ivl, & mut HashMap :: new ( ) ) ?;
378
378
379
+
380
+ //println!("Method {} IVL {:#?}", m.name.to_string(), ivl.to_string());
381
+
379
382
// Calculate obligation and error message (if obligation is not
380
383
// verified)
381
384
let wp_list = wp_set ( & dsa, vec ! [ ] ) ?;
@@ -854,7 +857,7 @@ fn return_to_ivl(expr: Option<&Expr>, span: &Span, method_context: &MethodContex
854
857
855
858
fn loop_to_ivl ( invariants : & Vec < Expr > , variant : & Option < Expr > , cases : & Cases , method_context : & MethodContext ) -> Result < IVLCmd , Error > {
856
859
let mut result = IVLCmd :: assert ( & Expr :: new_typed ( ExprKind :: Bool ( true ) , Type :: Bool ) , "Please don't fail!" ) ;
857
-
860
+
858
861
match variant {
859
862
Some ( variant_expr) => {
860
863
let mut variant_entry_assertion = IVLCmd :: assert ( & Expr :: op ( variant_expr, Op :: Ge , & Expr :: num ( 0 ) ) , "Loop variant might not be non-negative on entry" ) ;
@@ -867,10 +870,11 @@ fn loop_to_ivl(invariants: &Vec<Expr>, variant: &Option<Expr>, cases: &Cases, me
867
870
let mut loop_invariants_assertions: Vec < ( Expr , Expr ) > = Vec :: new ( ) ;
868
871
for invariant in invariants {
869
872
let expr_without_broke = replace_broke_in_expression ( invariant, false ) ;
873
+ let expr_without_old = replace_old_in_expression ( & expr_without_broke, & method_context. global_variables_old_values ) ;
870
874
result = result. seq ( & IVLCmd :: assert (
871
- & expr_without_broke ,
875
+ & expr_without_old ,
872
876
& format ! ( "Loop invariant {} might not hold on entry" , invariant. to_string( ) ) ) ) ;
873
- loop_invariants_assertions. push ( ( invariant. clone ( ) , expr_without_broke . clone ( ) ) ) ;
877
+ loop_invariants_assertions. push ( ( invariant. clone ( ) , expr_without_old . clone ( ) ) ) ;
874
878
}
875
879
876
880
for case in cases. cases . clone ( ) {
@@ -882,7 +886,8 @@ fn loop_to_ivl(invariants: &Vec<Expr>, variant: &Option<Expr>, cases: &Cases, me
882
886
883
887
for invariant in invariants {
884
888
let expr_without_broke = replace_broke_in_expression ( invariant, false ) ;
885
- result = result. seq ( & IVLCmd :: assume ( & expr_without_broke) )
889
+ let expr_without_old = replace_old_in_expression ( & expr_without_broke, & method_context. global_variables_old_values ) ;
890
+ result = result. seq ( & IVLCmd :: assume ( & expr_without_old) )
886
891
}
887
892
888
893
let variant_assertion = match variant {
@@ -910,7 +915,7 @@ fn loop_to_ivl(invariants: &Vec<Expr>, variant: &Option<Expr>, cases: &Cases, me
910
915
}
911
916
new_cases. push ( Case {
912
917
condition : case. condition . clone ( ) ,
913
- cmd :
918
+ cmd :
914
919
case. cmd
915
920
. seq ( & loop_invariants_assertions_commands)
916
921
. seq ( & Cmd :: assert ( & local_variant_assertion, & format ! ( "Loop variant might not be decreased in case {}" , case. condition. clone( ) . to_string( ) ) ) )
@@ -941,7 +946,7 @@ fn loop_to_ivl(invariants: &Vec<Expr>, variant: &Option<Expr>, cases: &Cases, me
941
946
}
942
947
943
948
}
944
-
949
+
945
950
946
951
result = result. seq ( & body_translation) ;
947
952
@@ -963,9 +968,9 @@ fn find_break_paths(command: &Cmd, context: IVLCmd, method_context: &MethodConte
963
968
for case in body. cases . clone ( ) {
964
969
let ivl_for_condition = IVLCmd :: assume ( & case. condition ) ;
965
970
let paths_for_case = find_break_paths (
966
- & case. cmd ,
967
- match_context. seq ( & ivl_for_condition) ,
968
- method_context,
971
+ & case. cmd ,
972
+ match_context. seq ( & ivl_for_condition) ,
973
+ method_context,
969
974
loop_context) ?;
970
975
paths. extend ( paths_for_case) ;
971
976
match_context = match_context. seq ( & IVLCmd :: assume ( & Expr :: prefix ( & case. condition , PrefixOp :: Not ) ) ) ;
@@ -1261,14 +1266,14 @@ fn replace_in_expression(original_expression: &Expr, identifier: &Name, replace_
1261
1266
ExprKind :: Ident ( name) if name. 0 == identifier. ident . 0 => replace_with_identifier. clone ( ) ,
1262
1267
ExprKind :: Prefix ( op, expr) => Expr :: new_typed (
1263
1268
ExprKind :: Prefix (
1264
- * op,
1269
+ * op,
1265
1270
Box :: new ( replace_in_expression ( expr, identifier, replace_with_identifier) )
1266
1271
) ,
1267
1272
original_expression. ty . clone ( ) ) ,
1268
1273
ExprKind :: Infix ( lhs, op, rhs) => Expr :: new_typed (
1269
1274
ExprKind :: Infix (
1270
1275
Box :: new ( replace_in_expression ( lhs, identifier, replace_with_identifier) ) ,
1271
- * op,
1276
+ * op,
1272
1277
Box :: new ( replace_in_expression ( rhs, identifier, replace_with_identifier) )
1273
1278
) ,
1274
1279
original_expression. ty . clone ( ) ) ,
0 commit comments