programs: no more optimization for singleton record types

parent fe31fcaf
...@@ -135,7 +135,8 @@ LIB_TRANSFORM = simplify_recursive_definition simplify_formula \ ...@@ -135,7 +135,8 @@ LIB_TRANSFORM = simplify_recursive_definition simplify_formula \
encoding_decorate encoding_bridge \ encoding_decorate encoding_bridge \
encoding_explicit encoding_guard encoding_sort \ encoding_explicit encoding_guard encoding_sort \
encoding_instantiate simplify_array filter_trigger \ encoding_instantiate simplify_array filter_trigger \
introduction abstraction close_epsilon lift_epsilon introduction abstraction close_epsilon lift_epsilon \
eval_match
LIB_PRINTER = print_real alt_ergo why3 smt smt2 coq tptp simplify gappa cvc3 LIB_PRINTER = print_real alt_ergo why3 smt smt2 coq tptp simplify gappa cvc3
......
...@@ -3,7 +3,7 @@ module M ...@@ -3,7 +3,7 @@ module M
use import int.Int use import int.Int
use import module ref.Ref use import module ref.Ref
parameter incr : x:ref int -> { } unit writes x { x = old x + 1 } parameter incr : x:ref int -> { } unit writes x { !x = old !x + 1 }
parameter x : ref int parameter x : ref int
...@@ -17,14 +17,14 @@ let test_and_1 () = ...@@ -17,14 +17,14 @@ let test_and_1 () =
{ result = 1 } { result = 1 }
let test_and_2 () = let test_and_2 () =
{ x <> 0 } { !x <> 0 }
if id_not_0 !x >= 1 && !x <= 1 then !x else 0+1 if id_not_0 !x >= 1 && !x <= 1 then !x else 0+1
{ result = 1 } { result = 1 }
let test_or_1 () = let test_or_1 () =
{ } { }
if (incr x; !x > 0) || !x < 0 then 1 else 2 if (incr x; !x > 0) || !x < 0 then 1 else 2
{ result = 1 -> x <> 0 } { result = 1 -> !x <> 0 }
let test_or_2 () = let test_or_2 () =
{ } { }
...@@ -32,19 +32,19 @@ let test_or_2 () = ...@@ -32,19 +32,19 @@ let test_or_2 () =
{ 0 <= result <= 1 } { 0 <= result <= 1 }
let test_not_1 () = let test_not_1 () =
{ } { }
if not (!x = 0) then x := 0 if not (!x = 0) then x := 0
{ x = 0 } { !x = 0 }
let test_not_2 () = let test_not_2 () =
{ x <= 0 } { !x <= 0 }
while not (!x = 0) do invariant { x <= 0 } incr x done while not (!x = 0) do invariant { !x <= 0 } incr x done
{ x = 0 } { !x = 0 }
let test_all_1 () = let test_all_1 () =
{ } { }
(!x >= 0 && not (!x = 0) || !x >= 1) (!x >= 0 && not (!x = 0) || !x >= 1)
{ result=True <-> x>=1 } { result=True <-> !x>=1 }
(* from Cesar Munoz's CD3D *) (* from Cesar Munoz's CD3D *)
...@@ -58,13 +58,13 @@ parameter sq : x:int -> {} int { result = x*x } ...@@ -58,13 +58,13 @@ parameter sq : x:int -> {} int { result = x*x }
let test_cd3d () = let test_cd3d () =
{ true } { true }
if !vx=0 && !vy=0 && sq !vx + sq !vy < sq d then 1 else 2 if !vx=0 && !vy=0 && sq !vx + sq !vy < sq d then 1 else 2
{ result=1 -> vx=0 and vy=0 } { result=1 -> !vx=0 and !vy=0 }
end end
(* (*
Local Variables: Local Variables:
compile-command: "unset LANG; make -C ../../.. bench/programs/good/booleans" compile-command: "unset LANG; make -C ../../.. bench/programs/good/booleans"
End: End:
*) *)
...@@ -7,18 +7,24 @@ exception Break ...@@ -7,18 +7,24 @@ exception Break
let f (n : int) : int = let f (n : int) : int =
{ true } { true }
let i = ref n in let i = ref n in
try try
while (!i > 0) do while (!i > 0) do
invariant { true } invariant { true }
variant { i } variant { !i }
if (!i <= 10) then raise Break; if (!i <= 10) then raise Break;
i := !i - 1 i := !i - 1
done done
with Break -> () with Break -> ()
end; end;
!i !i
{ result <= 10 } { result <= 10 }
end end
(*
Local Variables:
compile-command: "unset LANG; make -C ../../.. bench/programs/good/exceptions"
End:
*)
...@@ -12,28 +12,28 @@ exception F int ...@@ -12,28 +12,28 @@ exception F int
let p2 () = {} raise (F 1) : unit { false } | F -> { result = 1 } let p2 () = {} raise (F 1) : unit { false } | F -> { result = 1 }
let p2a () = let p2a () =
{} raise (F (raise E : int)) : unit { false } | E -> { true } | F -> { false } {} raise (F (raise E : int)) : unit { false } | E -> { true } | F -> { false }
(* composition of exceptions with other constructs *) (* composition of exceptions with other constructs *)
let p3 () = let p3 () =
{} begin raise (F 1); raise (F 2) : unit end { false } | F -> { result = 1 } {} begin raise (F 1); raise (F 2) : unit end { false } | F -> { result = 1 }
let p4 () = let p4 () =
{} {}
(if True then raise (F 1) else raise (F 2)) : unit (if True then raise (F 1) else raise (F 2)) : unit
{ false } | F -> { result = 1 } { false } | F -> { result = 1 }
let p5 () = let p5 () =
{} {}
begin begin
if True then raise (F 1); if True then raise (F 1);
raise E : unit raise E : unit
end end
{ false } | E -> { false } | F -> { result = 1 } { false } | E -> { false } | F -> { result = 1 }
let p6 () = let p6 () =
{} {}
begin begin
if False then raise (F 1); if False then raise (F 1);
...@@ -47,18 +47,18 @@ use import module ref.Ref ...@@ -47,18 +47,18 @@ use import module ref.Ref
parameter x : ref int parameter x : ref int
let p7 () = let p7 () =
{} begin x := 1; raise E; x := 2 end { false } | E -> { x = 1 } {} begin x := 1; raise E; x := 2 end { false } | E -> { !x = 1 }
let p8 () = let p8 () =
{} {}
begin x := 1; raise (F !x); x := 2 end begin x := 1; raise (F !x); x := 2 end
{ false } | F -> { x = 1 and result = 1 } { false } | F -> { !x = 1 and result = 1 }
let p9 () = let p9 () =
{} {}
(raise (F begin x := 1; !x end) : unit) (raise (F begin x := 1; !x end) : unit)
{ false } | F -> { x = 1 and result = 1 } { false } | F -> { !x = 1 and result = 1 }
(* try / with *) (* try / with *)
...@@ -66,39 +66,39 @@ let p10 () = {} (try raise E : int with E -> 0 end) { result = 0 } ...@@ -66,39 +66,39 @@ let p10 () = {} (try raise E : int with E -> 0 end) { result = 0 }
let p11 () = {} (try raise (F 1) : int with F x -> x end) { result = 1 } let p11 () = {} (try raise (F 1) : int with F x -> x end) { result = 1 }
let p12 () = let p12 () =
{} {}
try try
begin raise E; raise (F 1); 1 end begin raise E; raise (F 1); 1 end
with E -> 2 with E -> 2
| F x -> 3 | F x -> 3
end end
{ result = 2 } { result = 2 }
let p13 () = let p13 () =
{} {}
try try
begin raise E; raise (F 1); x := 1 end begin raise E; raise (F 1); x := 1 end
with E -> x := 2 with E -> x := 2
| F _ -> x := 3 | F _ -> x := 3
end end
{ x = 2 } { !x = 2 }
let p13a () = let p13a () =
{} {}
try try
(if !x = 1 then raise E) (if !x = 1 then raise E)
(*{ true | E => x = 1 }*) (*{ true | E => x = 1 }*)
with E -> with E ->
x := 0 x := 0
end end
{ x <> 1 } { !x <> 1 }
exception E1 exception E1
exception E2 exception E2
exception E3 exception E3
let p14 () = let p14 () =
{} {}
begin begin
if !x = 1 then raise E1; if !x = 1 then raise E1;
...@@ -106,22 +106,22 @@ let p14 () = ...@@ -106,22 +106,22 @@ let p14 () =
if !x = 3 then raise E3; if !x = 3 then raise E3;
raise E : unit raise E : unit
end end
{ false } | E1 -> { x = 1 } | E2 -> { x = 2 } | E3 -> { x = 3 } { false } | E1 -> { !x = 1 } | E2 -> { !x = 2 } | E3 -> { !x = 3 }
| E -> { x <> 1 and x <> 2 and x <> 3 } | E -> { !x <> 1 and !x <> 2 and !x <> 3 }
let p15 () = let p15 () =
{} {}
if !x = 0 then raise E else (x := 0; raise (F !x)) : unit if !x = 0 then raise E else (x := 0; raise (F !x)) : unit
{ false } | E -> { x=0 } | F -> { result=0 } { false } | E -> { !x=0 } | F -> { result=0 }
let p16 () = {} if !x = 0 then (x:=1; raise E) { x<>0 } | E -> { x=1 } let p16 () = {} if !x = 0 then (x:=1; raise E) { !x<>0 } | E -> { !x=1 }
let p17 () = {} (x := 0; (raise E; x := 1)) { false } | E -> { x=0 } let p17 () = {} (x := 0; (raise E; x := 1)) { false } | E -> { !x=0 }
end end
(* (*
Local Variables: Local Variables:
compile-command: "unset LANG; make -C ../../.. bench/programs/good/exns" compile-command: "unset LANG; make -C ../../.. bench/programs/good/exns"
End: End:
*) *)
...@@ -7,10 +7,10 @@ use import module ref.Ref ...@@ -7,10 +7,10 @@ use import module ref.Ref
let test1 () = let test1 () =
let x = ref 0 in let x = ref 0 in
for i = 1 to 10 do for i = 1 to 10 do
invariant { x = i-1 } invariant { !x = i-1 }
x := !x + 1 x := !x + 1
done; done;
assert { x = 10 } assert { !x = 10 }
(* we don't even enter *) (* we don't even enter *)
let test2 () = let test2 () =
...@@ -18,7 +18,7 @@ let test2 () = ...@@ -18,7 +18,7 @@ let test2 () =
for i = 2 to 1 do for i = 2 to 1 do
x := 1 x := 1
done; done;
assert { x = 0 } assert { !x = 0 }
exception E exception E
...@@ -50,17 +50,17 @@ let test4 x = ...@@ -50,17 +50,17 @@ let test4 x =
let test1d () = let test1d () =
let x = ref 11 in let x = ref 11 in
for i = 10 downto 1 do for i = 10 downto 1 do
invariant { x = i+1 } invariant { !x = i+1 }
x := !x - 1 x := !x - 1
done; done;
assert { x = 1 } assert { !x = 1 }
let test2d () = let test2d () =
let x = ref 0 in let x = ref 0 in
for i = 1 downto 2 do for i = 1 downto 2 do
x := 1 x := 1
done; done;
assert { x = 0 } assert { !x = 0 }
let test3d () = let test3d () =
{ } { }
......
...@@ -7,37 +7,37 @@ use import module ref.Ref ...@@ -7,37 +7,37 @@ use import module ref.Ref
parameter i : ref int parameter i : ref int
let loop1 (u:unit) = let loop1 (u:unit) =
{ i <= 10 } { !i <= 10 }
while !i < 10 do while !i < 10 do
invariant { i <= 10 } variant { 10 - i } invariant { !i <= 10 } variant { 10 - !i }
i := !i + 1 i := !i + 1
done done
{ i = 10 } { !i = 10 }
(** 2. The same loop, followed by a function call. *) (** 2. The same loop, followed by a function call. *)
parameter x: ref int parameter x: ref int
let negate (u:unit) = {} x := - !x { x = - (old x) } let negate (u:unit) = {} x := - !x { !x = - (old !x) }
let loop2 (u:unit) = let loop2 (u:unit) =
{ x <= 10 } { !x <= 10 }
begin begin
while !x < 10 do invariant { x <= 10 } variant { 10 - x } while !x < 10 do invariant { !x <= 10 } variant { 10 - !x }
x := !x + 1 x := !x + 1
done; done;
assert { x = 10 }; assert { !x = 10 };
if !x > 0 then (negate ()); if !x > 0 then (negate ());
assert { x = -10 } assert { !x = -10 }
end end
{} {}
end end
(* (*
Local Variables: Local Variables:
compile-command: "unset LANG; make -C ../../.. bench/programs/good/loops" compile-command: "unset LANG; make -C ../../.. bench/programs/good/loops"
End: End:
*) *)
...@@ -19,7 +19,7 @@ with is_odd x : bool variant {x} = ...@@ -19,7 +19,7 @@ with is_odd x : bool variant {x} =
end end
(* (*
Local Variables: Local Variables:
compile-command: "unset LANG; make -C ../../.. bench/programs/good/mutual" compile-command: "unset LANG; make -C ../../.. bench/programs/good/mutual"
End: End:
*) *)
...@@ -7,25 +7,25 @@ module M ...@@ -7,25 +7,25 @@ module M
parameter r : ref int parameter r : ref int
parameter f1 : y:int -> parameter f1 : y:int ->
{} unit writes r { q1 r (old r) y } {} unit writes r { q1 !r (old !r) y }
let g1 () = {} f1 !r { q1 r (old r) (old r) } let g1 () = {} f1 !r { q1 !r (old !r) (old !r) }
logic foo int : int logic foo int : int
logic q int int int logic q int int int
parameter f : t:ref int -> x:int -> parameter f : t:ref int -> x:int ->
{} unit writes t { q t (old t) x } {} unit writes t { q !t (old !t) x }
let g (t:ref int) = let g (t:ref int) =
{} {}
f t (foo !t) f t (foo !t)
{ q t (old t) (foo (old t)) } { q !t (old !t) (foo (old !t)) }
end end
(* (*
Local Variables: Local Variables:
compile-command: "unset LANG; make -C ../../.. bench/programs/good/oldify" compile-command: "unset LANG; make -C ../../.. bench/programs/good/oldify"
End: End:
*) *)
...@@ -11,13 +11,13 @@ parameter x : ref int ...@@ -11,13 +11,13 @@ parameter x : ref int
(* basic stuff: assignment, sequence and local variables *) (* basic stuff: assignment, sequence and local variables *)
let p1 () = { q (x+1) } begin x := !x + 1 end { q x } let p1 () = { q (!x+1) } begin x := !x + 1 end { q !x }
let p2 () = { q 7 } begin x := 3 + 4 end { q x } let p2 () = { q 7 } begin x := 3 + 4 end { q !x }
let p3 () = {} begin x := !x + 1; x := !x + 2 end { x = (old x) + 3 } let p3 () = {} begin x := !x + 1; x := !x + 2 end { !x = (old !x) + 3 }
let p4 () = {} begin x := 7; x := 2 * !x end { x = 14 } let p4 () = {} begin x := 7; x := 2 * !x end { !x = 14 }
let p5 () = {} 3 + 4 { result = 7 } let p5 () = {} 3 + 4 { result = 7 }
...@@ -27,15 +27,15 @@ let p7 () = {} 3 + (let a = 4 in a + a) { result = 11 } ...@@ -27,15 +27,15 @@ let p7 () = {} 3 + (let a = 4 in a + a) { result = 11 }
(* side effects in function arguments *) (* side effects in function arguments *)
let p8 () = let p8 () =
{ q (x+1) } 3 + begin x := !x + 1; !x end { q x and result = (old x) + 4 } { q (!x+1) } 3 + begin x := !x + 1; !x end { q !x and result = (old !x) + 4 }
(* evaluation order (argument first) *) (* evaluation order (argument first) *)
let p9 () = let p9 () =
{} begin x := 1; 1 end + begin x := 2; 1 end { result = 2 and x = 2 } {} begin x := 1; 1 end + begin x := 2; 1 end { result = 2 and !x = 2 }
let p9a () = {} begin x := 1; 1 end + 1 { result = 2 and x = 1 } let p9a () = {} begin x := 1; 1 end + 1 { result = 2 and !x = 1 }
(* function with a post-condition *) (* function with a post-condition *)
...@@ -49,24 +49,24 @@ let p11a () = {} let a = (fsucc 1) in a + a { result = 4 } ...@@ -49,24 +49,24 @@ let p11a () = {} let a = (fsucc 1) in a + a { result = 4 }
(* function with a post-condition and side-effects *) (* function with a post-condition and side-effects *)
parameter incrx : unit -> { } unit writes x { x = (old x) + 1 } parameter incrx : unit -> { } unit writes x { !x = (old !x) + 1 }
let p12 () = { x = 0 } incrx () { x = 1 } let p12 () = { !x = 0 } incrx () { !x = 1 }
let p13 () = {} begin incrx (); incrx () end { x = (old x) + 2 } let p13 () = {} begin incrx (); incrx () end { !x = (old !x) + 2 }
let p13a () = {} incrx (incrx ()) { x = (old x) + 2 } let p13a () = {} incrx (incrx ()) { !x = (old !x) + 2 }
(* function with side-effects, result and post-condition *) (* function with side-effects, result and post-condition *)
parameter incrx2 : unit -> { } int writes x { x = old x + 1 and result = x } parameter incrx2 : unit -> { } int writes x { !x = old !x + 1 and result = !x }
let p14 () = { x = 0 } incrx2 () { result = 1 } let p14 () = { !x = 0 } incrx2 () { result = 1 }
end end
(* (*
Local Variables: Local Variables:
compile-command: "unset LANG; make -C ../../.. bench/programs/good/po" compile-command: "unset LANG; make -C ../../.. bench/programs/good/po"
End: End:
*) *)
...@@ -4,13 +4,13 @@ let f (x:'a) = {} x { result=x } ...@@ -4,13 +4,13 @@ let f (x:'a) = {} x { result=x }
let p () = let p () =
{} {}
if f True then f 1 else f 2 if f True then f 1 else f 2
{ result = 1 } { result = 1 }
end end
(* (*