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-60] Misc fixes #37

Merged
merged 2 commits into from
Jul 2, 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
6 changes: 4 additions & 2 deletions src/viper/pretty.ml
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,15 @@ and pp_pres ppf exps =
fprintf ppf "@[<v 0>%a@]" (pp_print_list pp_pre) exps

and pp_pre ppf exp =
fprintf ppf "@[<v 2>requires %a@]" pp_exp exp
marks := exp.at :: !marks;
fprintf ppf "\017@[<v 2>requires %a@]\019" pp_exp exp

and pp_posts ppf exps =
fprintf ppf "@[<v 0>%a@]" (pp_print_list pp_post) exps

and pp_post ppf exp =
fprintf ppf "@[<v 2>ensures %a@]" pp_exp exp
marks := exp.at :: !marks;
fprintf ppf "\017@[<v 2>ensures %a@]\019" pp_exp exp

and pp_local ppf (id, typ) =
fprintf ppf "@[<2>%s: %a@]"
Expand Down
10 changes: 5 additions & 5 deletions src/viper/trans.ml
Original file line number Diff line number Diff line change
Expand Up @@ -407,8 +407,8 @@ and dec_field' ctxt d =
in
let stmts = stmt ctxt e in
let _, stmts = extract_concurrency stmts in
let pres, stmts' = List.partition_map (function { it = PreconditionS exp; _ } -> Left exp | s -> Right s) (snd stmts.it) in
let posts, stmts' = List.partition_map (function { it = PostconditionS exp; _ } -> Left exp | s -> Right s) stmts' in
let pres, stmts' = List.partition_map (function { it = PreconditionS exp; at; _ } -> Left { exp with at } | s -> Right s) (snd stmts.it) in
let posts, stmts' = List.partition_map (function { it = PostconditionS exp; at; _ } -> Left { exp with at } | s -> Right s) stmts' in
let arg_preds = local_access_preds ctxt in
let ret_preds, ret = rets ctxt t_opt in
let pres = arg_preds @ pres in
Expand All @@ -434,8 +434,8 @@ and dec_field' ctxt d =
in
let stmts = stmt ctxt e in
let _, stmts = extract_concurrency stmts in
let pres, stmts' = List.partition_map (function { it = PreconditionS exp; _ } -> Left exp | s -> Right s) (snd stmts.it) in
let posts, stmts' = List.partition_map (function { it = PostconditionS exp; _ } -> Left exp | s -> Right s) stmts' in
let pres, stmts' = List.partition_map (function { it = PreconditionS exp; at; _ } -> Left { exp with at } | s -> Right s) (snd stmts.it) in
let posts, stmts' = List.partition_map (function { it = PostconditionS exp; at; _ } -> Left { exp with at } | s -> Right s) stmts' in
let arg_preds = local_access_preds ctxt in
let ret_preds, ret = rets ctxt t_opt in
let pres = arg_preds @ pres in
Expand Down Expand Up @@ -562,7 +562,7 @@ and compile_while
let label, ctxt = loop_label ctxt label_id in
let stmts = stmt ctxt body in
let decls, stmts = stmts.it in
!!(decls, !!(LabelS label) :: stmts)
!!(decls, stmts @ [ !!(LabelS label) ])
| None -> stmt ctxt body
in
!!([], [ !!(WhileS(pred, invs, body)) ])
Expand Down
16 changes: 8 additions & 8 deletions test/viper/ok/array-of-tuples.vpr.ok
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,17 @@ method set_nested_mut_arr($Self: Ref, arr: Array)

requires $Perm($Self)
requires $array_acc(arr, $option$tuple2$option$int$tuple2$bool$bool,
write)
write)
ensures $Perm($Self)
ensures $array_acc(arr, $option$tuple2$option$int$tuple2$bool$bool,
write)
write)
ensures ((($size(arr) >= 2) && (($loc(arr, 0)).$option$tuple2$option$int$tuple2$bool$bool ==
old(($loc(arr, 0)).$option$tuple2$option$int$tuple2$bool$bool))) && (
($loc(arr, 1)).$option$tuple2$option$int$tuple2$bool$bool == Some(
Tup$2(
Some(42),
Tup$2(true,
true)))))
old(($loc(arr, 0)).$option$tuple2$option$int$tuple2$bool$bool))) && (
($loc(arr, 1)).$option$tuple2$option$int$tuple2$bool$bool == Some(
Tup$2(
Some(42),
Tup$2(true,
true)))))
{
assume ($size(arr) >= 2);
($loc(arr, 1)).$option$tuple2$option$int$tuple2$bool$bool := Some(
Expand Down
4 changes: 2 additions & 2 deletions test/viper/ok/label-break-continue.vpr.ok
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,14 @@ method loops($Self: Ref)
invariant $Perm($Self)
invariant (i < 3)
{
label $lbl$continue$while_loop;
i := (i + 1);
if ((i == 3))
{
goto $lbl$while_loop;
};
goto $lbl$continue$while_loop;
i := 100;
i := 100;
label $lbl$continue$while_loop;
};
label $lbl$while_loop;
label $Ret;
Expand Down
5 changes: 3 additions & 2 deletions test/viper/ok/reverse.vpr.ok
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ method reverseArray$Nat($Self: Ref, a: Array)
ensures $array_acc(a, $int, write)
ensures ($size(($Self).xarray) == 5)
ensures ($size(a) == old($size(a)))
ensures (forall k : Int :: (((0 <= k) && (k < $size(a))) ==> (($loc(a, k)).$int ==
old(($loc(a, (($size(a) - 1) - k))).$int))))
ensures (forall k : Int :: (((0 <= k) && (k < $size(a))) ==> (($loc(a,
k)).$int ==
old(($loc(a, (($size(a) - 1) - k))).$int))))
{ var b: Array
var length: Int
var i: Int
Expand Down
2 changes: 2 additions & 0 deletions test/viper/ok/todo_record.tc.ok
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
todo_record.mo:109.23-109.28: warning [M0155], operator may trap for inferred type
Nat
71 changes: 36 additions & 35 deletions test/viper/ok/todo_record.vpr.ok
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,17 @@ method resize($Self: Ref, n: Int)
requires $Perm($Self)
requires ((0 <= ($Self).num) && (($Self).num <= $size(($Self).todos)))
requires (forall i : Int :: (((0 <= i) && (i < ($Self).num)) ==> (
(($loc(($Self).todos, i)).$c_ToDo).$ToDo$id < ($Self).nextId)))
(($loc(($Self).todos, i)).$c_ToDo).$ToDo$id < ($Self).nextId)))
ensures $Perm($Self)
ensures ((0 <= ($Self).num) && (($Self).num <= $size(($Self).todos)))
ensures (forall i : Int :: (((0 <= i) && (i < ($Self).num)) ==> (
(($loc(($Self).todos, i)).$c_ToDo).$ToDo$id < ($Self).nextId)))
(($loc(($Self).todos, i)).$c_ToDo).$ToDo$id < ($Self).nextId)))
ensures ((($Self).num == old(($Self).num)) && (($Self).nextId ==
old(($Self).nextId)))
old(($Self).nextId)))
ensures ($size(($Self).todos) >= n)
ensures (old($size(($Self).todos)) <= $size(($Self).todos))
ensures (forall i : Int :: (((0 <= i) && (i < old($size(($Self).todos)))) ==> (
($loc(($Self).todos, i)).$c_ToDo == old(($loc(($Self).todos, i)).$c_ToDo))))
($loc(($Self).todos, i)).$c_ToDo == old(($loc(($Self).todos, i)).$c_ToDo))))
{ var new_array: Array
var i: Int
if ((n <= $size(($Self).todos)))
Expand Down Expand Up @@ -111,10 +111,10 @@ method getTodos($Self: Ref)
ensures $Perm($Self)
ensures $array_acc($Res, $c_ToDo, wildcard)
ensures ((($Self).num == old(($Self).num)) && (($Self).nextId ==
old(($Self).nextId)))
old(($Self).nextId)))
ensures ($size(($Self).todos) == old($size(($Self).todos)))
ensures (forall i : Int :: (((0 <= i) && (i < old($size(($Self).todos)))) ==> (
($loc(($Self).todos, i)).$c_ToDo == old(($loc(($Self).todos, i)).$c_ToDo))))
($loc(($Self).todos, i)).$c_ToDo == old(($loc(($Self).todos, i)).$c_ToDo))))
ensures $Inv($Self)
{ var new_array: Array
inhale $array_acc(new_array, $c_ToDo, write);
Expand All @@ -132,26 +132,27 @@ method getTodo($Self: Ref, id: Int)
requires $Inv($Self)
ensures $Perm($Self)
ensures ((($Self).num == old(($Self).num)) && (($Self).nextId ==
old(($Self).nextId)))
old(($Self).nextId)))
ensures ($size(($Self).todos) == old($size(($Self).todos)))
ensures (forall i : Int :: (((0 <= i) && (i < old($size(($Self).todos)))) ==> (
($loc(($Self).todos, i)).$c_ToDo == old(($loc(($Self).todos, i)).$c_ToDo))))
($loc(($Self).todos, i)).$c_ToDo == old(($loc(($Self).todos, i)).$c_ToDo))))
ensures ((exists i : Int :: (((0 <= i) && (i < ($Self).num)) && (
(($loc(($Self).todos, i)).$c_ToDo).$ToDo$id == id))) ==>
(exists i : Int :: (((0 <= i) && (i < ($Self).num)) && (Some(($loc(
(($loc(($Self).todos, i)).$c_ToDo).$ToDo$id == id))) ==>
(exists i : Int :: (((0 <= i) && (i < ($Self).num)) && (Some((
$loc(
($Self).todos,
i)).$c_ToDo) ==
($Res).tup$2$0))))
($Res).tup$2$0))))
ensures ((($Res).tup$2$0 == None()) == (forall i : Int :: (((0 <= i) && (i <
($Self).num)) ==> ((($loc(
($Self).todos,
i)).$c_ToDo).$ToDo$id != id))))
($Self).num)) ==> ((($loc(
($Self).todos,
i)).$c_ToDo).$ToDo$id != id))))
ensures ((($Res).tup$2$0 != None()) ==> ((0 <= ($Res).tup$2$1) && (
($Res).tup$2$1 < $size(($Self).todos))))
ensures ((($Res).tup$2$0 != None()) ==> (($Res).tup$2$0 == Some((
$loc(
($Self).todos,
($Res).tup$2$1)).$c_ToDo)))
($Res).tup$2$1 < $size(($Self).todos))))
ensures ((($Res).tup$2$0 != None()) ==> (($Res).tup$2$0 == Some(
($loc(
($Self).todos,
($Res).tup$2$1)).$c_ToDo)))
ensures $Inv($Self)
{ var i: Int
var res: Option[ToDo]
Expand All @@ -178,12 +179,12 @@ method getTodo($Self: Ref, id: Int)
None()))
invariant ((res != None()) ==> (res == Some(($loc(($Self).todos, i)).$c_ToDo)))
{
label $lbl$continue$l;
if (((($loc(($Self).todos, i)).$c_ToDo).$ToDo$id == id))
{
res := Some(($loc(($Self).todos, i)).$c_ToDo);
goto $lbl$l;
};
};
label $lbl$continue$l;
};
label $lbl$l;
$Res := Tup$2(res, i);
Expand All @@ -200,10 +201,10 @@ method addTodo($Self: Ref, description: Int)
ensures (($Self).nextId == (old(($Self).nextId) + 1))
ensures ($Res == old(($Self).nextId))
ensures (($loc(($Self).todos, (($Self).num - 1))).$c_ToDo == $RecordCtor_ToDo(description,
$Res,
TODO()))
$Res,
TODO()))
ensures (forall i : Int :: (((0 <= i) && (i < (($Self).num - 1))) ==> (
($loc(($Self).todos, i)).$c_ToDo == old(($loc(($Self).todos, i)).$c_ToDo))))
($loc(($Self).todos, i)).$c_ToDo == old(($loc(($Self).todos, i)).$c_ToDo))))
ensures $Inv($Self)
{ var id: Int
id := ($Self).nextId;
Expand All @@ -225,14 +226,14 @@ method completeTodo($Self: Ref, id: Int)
requires $Inv($Self)
ensures $Perm($Self)
ensures ((($Self).num == old(($Self).num)) && (($Self).nextId ==
old(($Self).nextId)))
old(($Self).nextId)))
ensures ($size(($Self).todos) == old($size(($Self).todos)))
ensures (forall i : Int :: ((((0 <= i) && (i < ($Self).num)) && (
(($loc(($Self).todos, i)).$c_ToDo).$ToDo$id != id)) ==> (
($loc(($Self).todos, i)).$c_ToDo == old(($loc(($Self).todos, i)).$c_ToDo))))
(($loc(($Self).todos, i)).$c_ToDo).$ToDo$id != id)) ==> (
($loc(($Self).todos, i)).$c_ToDo == old(($loc(($Self).todos, i)).$c_ToDo))))
ensures (forall i : Int :: ((((0 <= i) && (i < ($Self).num)) && (
(($loc(($Self).todos, i)).$c_ToDo).$ToDo$id == id)) ==> (
(($loc(($Self).todos, i)).$c_ToDo).$ToDo$state == DONE())))
(($loc(($Self).todos, i)).$c_ToDo).$ToDo$id == id)) ==> (
(($loc(($Self).todos, i)).$c_ToDo).$ToDo$state == DONE())))
ensures $Inv($Self)
{ var i: Int
i := 0;
Expand Down Expand Up @@ -280,10 +281,10 @@ method showTodos($Self: Ref)
requires $Inv($Self)
ensures $Perm($Self)
ensures ((($Self).num == old(($Self).num)) && (($Self).nextId ==
old(($Self).nextId)))
old(($Self).nextId)))
ensures ($size(($Self).todos) == old($size(($Self).todos)))
ensures (forall i : Int :: (((0 <= i) && (i < ($Self).num)) ==> (
($loc(($Self).todos, i)).$c_ToDo == old(($loc(($Self).todos, i)).$c_ToDo))))
($loc(($Self).todos, i)).$c_ToDo == old(($loc(($Self).todos, i)).$c_ToDo))))
ensures $Inv($Self)
{ var output: Int
var i: Int
Expand Down Expand Up @@ -327,11 +328,11 @@ method clearstate($Self: Ref)
ensures (($Self).nextId == old(($Self).nextId))
ensures ($size(($Self).todos) == old($size(($Self).todos)))
ensures (forall i : Int :: ((((0 <= i) && (i < old(($Self).num))) && (
old((($loc(($Self).todos, i)).$c_ToDo).$ToDo$state) == TODO())) ==>
(exists k : Int :: (((0 <= k) && (k < $size(($Self).todos))) && (
($loc(($Self).todos, k)).$c_ToDo == old(($loc(($Self).todos, i)).$c_ToDo))))))
old((($loc(($Self).todos, i)).$c_ToDo).$ToDo$state) == TODO())) ==>
(exists k : Int :: (((0 <= k) && (k < $size(($Self).todos))) && (
($loc(($Self).todos, k)).$c_ToDo == old(($loc(($Self).todos, i)).$c_ToDo))))))
ensures (forall i : Int :: (((0 <= i) && (i < ($Self).num)) ==> (
(($loc(($Self).todos, i)).$c_ToDo).$ToDo$state == TODO())))
(($loc(($Self).todos, i)).$c_ToDo).$ToDo$state == TODO())))
ensures $Inv($Self)
{ var new_array: Array
var i: Int
Expand Down
2 changes: 2 additions & 0 deletions test/viper/ok/todo_record.vpr.stderr.ok
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
todo_record.mo:109.23-109.28: warning [M0155], operator may trap for inferred type
Nat
Loading
Loading