Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DMS-41] Fix locations for while loop invariants #29

Merged
merged 1 commit into from
Jun 17, 2024
Merged
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
3 changes: 2 additions & 1 deletion src/viper/pretty.ml
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,8 @@ and pp_fldacc ppf fldacc =
fprintf ppf "@[(%a).%s@]" pp_exp exp1 id.it

and pp_loop_inv ppf inv =
fprintf ppf "invariant %a" pp_exp inv
marks := inv.at :: !marks;
fprintf ppf "\017invariant %a\019" pp_exp inv

let prog_mapped file tuple_arities p =
marks := [];
Expand Down
4 changes: 2 additions & 2 deletions src/viper/trans.ml
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ let rec extract_loop_invariants (e : M.exp) : (M.exp list * M.exp) =
| _ -> ([], e)
and extract_loop_invariants' (ds : M.dec list) (acc : M.exp list) : (M.exp list * M.dec list) =
match ds with
| M.({ it = ExpD ({ it = AssertE (Loop_invariant, inv); _ }); _ }) :: ds ->
extract_loop_invariants' ds (inv :: acc)
| M.({ it = ExpD ({ it = AssertE (Loop_invariant, inv); at = assert_at; _ }); _ }) :: ds ->
extract_loop_invariants' ds ({ inv with at = assert_at } :: acc)
| _ -> (List.rev acc, ds)

let rec extract_concurrency (seq : seqn) : stmt' list * seqn =
Expand Down
9 changes: 5 additions & 4 deletions test/viper/ok/reverse.vpr.ok
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,13 @@ method reverseArray$Nat($Self: Ref, a: Array)
invariant ((i < length) && (i >= 0))
invariant ((j < length) && (j >= 0))
invariant (i == (($size(a) - 1) - j))
invariant forall k : Int :: (((j <= k) && (k <= i)) ==> (($loc(a, k)).$int ==
old(($loc(a, k)).$int)))
invariant forall k : Int :: (((j <= k) && (k <= i)) ==> (($loc(a,
k)).$int ==
old(($loc(a, k)).$int)))
invariant forall k : Int :: (((0 <= k) && (k < j)) ==> (($loc(a, k)).$int ==
old(($loc(a, (($size(a) - 1) - k))).$int)))
old(($loc(a, (($size(a) - 1) - k))).$int)))
invariant forall k : Int :: (((i < k) && (k < $size(a))) ==> (
($loc(a, k)).$int == old(($loc(a, (($size(a) - 1) - k))).$int)))
($loc(a, k)).$int == old(($loc(a, (($size(a) - 1) - k))).$int)))
invariant ($Perm($Self) && $Inv($Self))
{ var tmp: Int
tmp := ($loc(a, i)).$int;
Expand Down
Loading