Commit d60abe64 authored by MARCHE Claude's avatar MARCHE Claude

Merge branch 'issue_346' into 'master'

Unused variables message

See merge request !198
parents e0a8f060 f91bb58b
...@@ -6,17 +6,17 @@ module Test ...@@ -6,17 +6,17 @@ module Test
type t type t
function d (x : t) : int function d (x : t) : int
meta "model_projection" function d meta "model_projection" function d
function c (x : t) : int function c (x : t) : int
meta "model_projection" function c meta "model_projection" function c
(* Here the counterexample should not be a record *) (* Here the counterexample should not be a record *)
let f (x: t) : t let f (x: t) : (_t: t)
requires { c x > 0 } requires { c x > 0 }
ensures { d x < 0 } ensures { d x < 0 }
= =
x x
end end
...@@ -6,13 +6,13 @@ use ref.Ref ...@@ -6,13 +6,13 @@ use ref.Ref
val x : ref int val x : ref int
let f (a : int) : int let f (_a : int) : int
ensures { result = 0} ensures { result = 0}
= =
x := 42; x := 42;
!x !x
let f2 (a : int) : int let f2 (_a : int) : int
ensures { result = 0} ensures { result = 0}
= =
x := 42; x := 42;
......
use int.Int
(* Should not output any unused variable *)
val v (x : int) (y : int) : bool
ensures {x = y <-> result}
ensures {x = y}
use int.Int
exception E
exception F
exception G
exception H int
val f (x y z: int) : int
ensures { x = 42 }
ensures { result = 43 }
ensures { x = 45 }
raises { F -> x = -42 }
raises { E -> x <> x }
raises { G -> x = z }
raises { H res -> y = 42 }
...@@ -3,9 +3,8 @@ exception Exception ...@@ -3,9 +3,8 @@ exception Exception
val f0 (tt:unit) : unit val f0 (tt:unit) : unit
val f1 (tt:unit) : unit raises { Exception } val f1 (_tt:unit) : unit raises { Exception }
let f () let f ()
raises { Exception -> true } raises { Exception -> true }
= f0 (f1 ()) = f0 (f1 ())
...@@ -5,7 +5,6 @@ use ref.Ref ...@@ -5,7 +5,6 @@ use ref.Ref
val t : ref int val t : ref int
val m (a:int) (b:int) : unit raises { Exception } val m (_a:int) (_b:int) : unit raises { Exception }
let test () raises { Exception } = (m ( assert { true } ; 0) 0) let test () raises { Exception } = (m ( assert { true } ; 0) 0)
...@@ -7,7 +7,7 @@ use ref.Ref ...@@ -7,7 +7,7 @@ use ref.Ref
val i : ref int val i : ref int
let loop1 (u:unit) requires { !i <= 10 } ensures { !i = 10 } let loop1 (_u:unit) requires { !i <= 10 } ensures { !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
...@@ -18,9 +18,9 @@ let loop1 (u:unit) requires { !i <= 10 } ensures { !i = 10 } ...@@ -18,9 +18,9 @@ let loop1 (u:unit) requires { !i <= 10 } ensures { !i = 10 }
val x: ref int val x: ref int
let negate (u:unit) ensures { !x = - (old !x) } = x := - !x let negate (_u:unit) ensures { !x = - (old !x) } = x := - !x
let loop2 (u:unit) requires { !x <= 10 } let loop2 (_u:unit) requires { !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
...@@ -31,4 +31,3 @@ let loop2 (u:unit) requires { !x <= 10 } ...@@ -31,4 +31,3 @@ let loop2 (u:unit) requires { !x <= 10 }
end end
end end
...@@ -6,7 +6,7 @@ module T ...@@ -6,7 +6,7 @@ module T
(* g can raise MyExc *) (* g can raise MyExc *)
let rec f (x: int) : int raises {MyExc} = raise MyExc let rec f (_x: int) : int raises {MyExc} = raise MyExc
with g (x: int) : int raises {MyExc} = f x with g (x : int) : int raises {MyExc} = f x
end end
...@@ -15,7 +15,7 @@ module M ...@@ -15,7 +15,7 @@ module M
val x : ref int val x : ref int
let rec f2 (u:unit) : unit variant { !x } let rec f2 (_u:unit) : unit variant { !x }
requires { !x >= 0 } ensures { !x = 0 } requires { !x >= 0 } ensures { !x = 0 }
= if !x > 0 then begin x := !x - 1; f2 () end = if !x > 0 then begin x := !x - 1; f2 () end
...@@ -42,4 +42,3 @@ module M ...@@ -42,4 +42,3 @@ module M
= let b = ref 0 in let f = f5 x in f b = let b = ref 0 in let f = f5 x in f b
end end
use int.Int
(* result unused *)
val eq (x: int) (y: int) : bool
ensures { x = y }
use int.Int
(* z unused *)
function f (x : int) (y : int) : bool = forall z:int. x = y
use int.Int
(* y unused *)
function g (x: int) (y: int) : bool = forall z:int. x = z
use int.Int
(* result unused *)
let eq1 (x : int) (y : int) : bool
ensures { x = y }
= true
use int.Int
(* y unused *)
let eq2 (x: int) (y : int) : bool
ensures { result <-> (x = x) }
= true
use int.Int
(* y is unused *)
goal h : forall y x: int. x = 42
use int.Int
(* x is unused *)
predicate p (x: int) (y: int) = y = 0
use int.Int
exception E
exception F
exception G
exception H
val f (x: int) : int
ensures { x = 42 }
raises { F -> x = -42 }
raises { E -> x <> x }
raises { G -> x = x }
raises { H -> false }
...@@ -14,7 +14,7 @@ module M ...@@ -14,7 +14,7 @@ module M
| Some b -> | Some b ->
if b then if b then
( (
let rec aux (x: unit) : unit let rec aux (_x: unit) : unit
diverges diverges
raises { A -> true } raises { A -> true }
= =
......
...@@ -48,7 +48,7 @@ module ARM ...@@ -48,7 +48,7 @@ module ARM
(* memory *) (* memory *)
val mem : ref (map int int) val mem : ref (map int int)
val mem_ldr (a:int) : int ensures { result = !mem[a] } val mem_ldr (a:int) : int ensures { result = !mem[a] }
val mem_str (a:int) (v:int) : int writes { mem } val mem_str (a:int) (v:int) : (_r: int) writes { mem }
ensures { !mem = (old !mem)[a <- v] } ensures { !mem = (old !mem)[a <- v] }
(* data segment *) (* data segment *)
......
...@@ -34,7 +34,7 @@ module MapBase ...@@ -34,7 +34,7 @@ module MapBase
scope M scope M
type t = unit type t = unit
constant zero : unit = () constant zero : unit = ()
function op (x y:unit) : unit = () function op (_x _y:unit) : unit = ()
let lemma neutral_ (x:unit) : unit let lemma neutral_ (x:unit) : unit
ensures { op zero x = x = op x zero } ensures { op zero x = x = op x zero }
= match x with _ -> () end = match x with _ -> () end
...@@ -43,7 +43,7 @@ module MapBase ...@@ -43,7 +43,7 @@ module MapBase
clone export monoid.MonoidSumDef with type M.t = t, clone export monoid.MonoidSumDef with type M.t = t,
constant M.zero = zero,function M.op = op,goal M.assoc,goal M.neutral constant M.zero = zero,function M.op = op,goal M.assoc,goal M.neutral
let zero () : unit ensures { result = () } = () let zero () : unit ensures { result = () } = ()
let op (x y:unit) : unit ensures { result = () } = () let op (_x _y:unit) : unit ensures { result = () } = ()
end end
(** In associative tables, elements are selected (** In associative tables, elements are selected
...@@ -74,7 +74,7 @@ module MapBase ...@@ -74,7 +74,7 @@ module MapBase
(** Comparison-based binary search *) (** Comparison-based binary search *)
let selected_part (ghost lseq rseq:seq (D.t 'a)) let selected_part (ghost lseq rseq:seq (D.t 'a))
(k:K.t) (l:'e) (d:D.t 'a) (r:'f) : part_base K.t (k:K.t) (_l:'e) (d:D.t 'a) (_r:'f) : part_base K.t
requires { selection_possible k (lseq ++ cons d rseq) } requires { selection_possible k (lseq ++ cons d rseq) }
returns { Here -> let e2 = { left = lseq; returns { Here -> let e2 = { left = lseq;
middle = Some d; middle = Some d;
...@@ -937,4 +937,3 @@ module IMapAndSet ...@@ -937,4 +937,3 @@ module IMapAndSet
val CO.compare = compare val CO.compare = compare
end end
...@@ -119,7 +119,7 @@ theory Graph ...@@ -119,7 +119,7 @@ theory Graph
requires { path s l v /\ path_weight l v < n } requires { path s l v /\ path_weight l v < n }
(* then there exists a negative cycle. *) (* then there exists a negative cycle. *)
ensures { exists u. negative_cycle u } ensures { exists u. negative_cycle u }
= let rec aux (m: int) : 'a = let rec aux (m: int) : (_a: 'a)
requires { forall u. not negative_cycle u } requires { forall u. not negative_cycle u }
requires { exists l. path s l v /\ path_weight l v < n /\ length l <= m } requires { exists l. path s l v /\ path_weight l v < n /\ length l <= m }
ensures { false } ensures { false }
......
...@@ -13,7 +13,7 @@ use int.Int ...@@ -13,7 +13,7 @@ use int.Int
exception MyExc exception MyExc
let rec f (x:int) : int variant { 0 } raises { MyExc } = raise MyExc let rec f (_x:int) : int variant { 0 } raises { MyExc } = raise MyExc
with g (x:int) : int variant { 1 } raises { MyExc } = f x with g (x:int) : int variant { 1 } raises { MyExc } = f x
end end
...@@ -13,7 +13,7 @@ module T ...@@ -13,7 +13,7 @@ module T
exception MyExc exception MyExc
let rec f (a:t) : t raises { MyExc } = raise MyExc let rec f (_a:t) : t raises { MyExc } = raise MyExc
with g (a:t) : t = try (f a) with MyExc -> a end with g (a:t) : t = try (f a) with MyExc -> a end
end end
...@@ -14,7 +14,7 @@ module T ...@@ -14,7 +14,7 @@ module T
exception MyExc exception MyExc
let rec f (x:t) : t raises { MyExc } = raise MyExc let rec f (_x:t) : t raises { MyExc } = raise MyExc
with g (x:t) : t raises { MyExc } ensures { true } = f x with g (x:t) : (_r: t) raises { MyExc } ensures { true } = f x
end end
...@@ -22,7 +22,7 @@ module DijkstraShortestPath ...@@ -22,7 +22,7 @@ module DijkstraShortestPath
constant v: fset vertex constant v: fset vertex
val ghost function g_succ (x: vertex) : fset vertex val ghost function g_succ (_x: vertex) : fset vertex
ensures { subset result v } ensures { subset result v }
val get_succs (x: vertex): set val get_succs (x: vertex): set
...@@ -151,13 +151,13 @@ module DijkstraShortestPath ...@@ -151,13 +151,13 @@ module DijkstraShortestPath
(* there are paths for vertices in Q *) (* there are paths for vertices in Q *)
(forall v: vertex. mem v q -> path src v d[v]) (forall v: vertex. mem v q -> path src v d[v])
predicate inv_succ (src: vertex) (s q: set) (d: t int) = predicate inv_succ (_src: vertex) (s q: set) (d: t int) =
(* successors of vertices in S are either in S or in Q *) (* successors of vertices in S are either in S or in Q *)
forall x: vertex. mem x s -> forall x: vertex. mem x s ->
forall y: vertex. mem y (g_succ x) -> forall y: vertex. mem y (g_succ x) ->
(mem y s \/ mem y q) /\ d[y] <= d[x] + weight x y (mem y s \/ mem y q) /\ d[y] <= d[x] + weight x y
predicate inv_succ2 (src: vertex) (s q: set) (d: t int) (u: vertex) (su: set) = predicate inv_succ2 (_src: vertex) (s q: set) (d: t int) (u: vertex) (su: set) =
(* successors of vertices in S are either in S or in Q, (* successors of vertices in S are either in S or in Q,
unless they are successors of u still in su *) unless they are successors of u still in su *)
forall x: vertex. mem x s -> forall x: vertex. mem x s ->
......
...@@ -170,7 +170,7 @@ module FulcrumNoOverflow ...@@ -170,7 +170,7 @@ module FulcrumNoOverflow
meta coercion function v meta coercion function v
predicate biginv (b: big) = 89>55 (* used to enforce the type invariant *) predicate biginv (_b: big) = 89>55 (* used to enforce the type invariant *)
constant min_big : int = -m*m constant min_big : int = -m*m
constant max_big : int = m*m - 1 constant max_big : int = m*m - 1
......
...@@ -30,7 +30,7 @@ module M ...@@ -30,7 +30,7 @@ module M
val alloc : ref first_free_addr val alloc : ref first_free_addr
val new_pointer (tt:unit) : pointer writes { alloc } val new_pointer (_tt:unit) : pointer writes { alloc }
ensures { !alloc = old !alloc + 1 /\ result = old !alloc } ensures { !alloc = old !alloc + 1 /\ result = old !alloc }
(* (*
......
...@@ -91,7 +91,7 @@ module Impl ...@@ -91,7 +91,7 @@ module Impl
(forall i. 0 <= i < size -> path size link i (dist i) (repr i)) (forall i. 0 <= i < size -> path size link i (dist i) (repr i))
} by { } by {
size = 0; link = Array.make 0 0; rank = Array.make 0 0; size = 0; link = Array.make 0 0; rank = Array.make 0 0;
repr = (fun i -> i); dist = (fun i -> 0) repr = (fun i -> i); dist = (fun _i -> 0)
} }
let create (n: int) : t let create (n: int) : t
...@@ -105,7 +105,7 @@ module Impl ...@@ -105,7 +105,7 @@ module Impl
done; done;
let rank = Array.make n 0 in let rank = Array.make n 0 in
{ size = n; link = link; rank = rank; { size = n; link = link; rank = rank;
repr = (fun i -> i); dist = (fun i -> 0) } repr = (fun i -> i); dist = (fun _i -> 0) }
let rec lemma path_dist (size: int) (link: array int) (dist: int -> int) let rec lemma path_dist (size: int) (link: array int) (dist: int -> int)
(x d y: int) (x d y: int)
......
...@@ -150,14 +150,14 @@ theory List ...@@ -150,14 +150,14 @@ theory List
| Cons x xs -> if p x then (dropWhile p xs) else (Cons x xs) | Cons x xs -> if p x then (dropWhile p xs) else (Cons x xs)
end end
predicate pfalse (x: 'a) = false predicate pfalse (_x: 'a) = false
function dropWhile_False (l : list 'a) : list 'a = match l with function dropWhile_False (l : list 'a) : list 'a = match l with
| Nil -> Nil | Nil -> Nil
| Cons x xs -> if pfalse x then (dropWhile_False xs) else (Cons x xs) | Cons x xs -> if pfalse x then (dropWhile_False xs) else (Cons x xs)
end end
predicate ptrue (x: 'a) = true predicate ptrue (_x: 'a) = true
function takeWhile_True (l : list 'a) : list 'a = match l with function takeWhile_True (l : list 'a) : list 'a = match l with
| Nil -> Nil | Nil -> Nil
......
...@@ -512,7 +512,7 @@ module PatienceAbstract ...@@ -512,7 +512,7 @@ module PatienceAbstract
let stack_i,_ = s.positions[si] in let stack_i,_ = s.positions[si] in
0 <= stack_i < s.num_stacks 0 <= stack_i < s.num_stacks
) )
so range f sigma.seqlen s.num_stacks so range f sigma.seqlen s.num_stacks
so not (injective f sigma.seqlen) so not (injective f sigma.seqlen)
}; };
assert { (* contradiction from non-injectivity *) assert { (* contradiction from non-injectivity *)
......
...@@ -33,7 +33,7 @@ module SimpleQueue ...@@ -33,7 +33,7 @@ module SimpleQueue
m = 0; n = 0; m = 0; n = 0;
contents = S.empty; } contents = S.empty; }
let dequeue (q: t 'a) : 'a let dequeue (q: t 'a) : (_r: 'a)
requires { S.length q.contents > 0 } requires { S.length q.contents > 0 }
writes { q.m, q.contents } writes { q.m, q.contents }
ensures { S.(q.contents == (old q.contents)[1..]) } ensures { S.(q.contents == (old q.contents)[1..]) }
......
...@@ -24,8 +24,8 @@ predicate tworedneighbors (c: coloring) (i:int) ...@@ -24,8 +24,8 @@ predicate tworedneighbors (c: coloring) (i:int)
predicate valid (c:coloring) = predicate valid (c:coloring) =
forall i. 0 <= i < length c -> c[i] = Red -> tworedneighbors c i forall i. 0 <= i < length c -> c[i] = Red -> tworedneighbors c i
function black (n:int) : color = Black function black (_n:int) : color = Black
function red (n:int) : color = Red function red (_n:int) : color = Red
function colorings0 : fset coloring = add (create 0 black) Fset.empty function colorings0 : fset coloring = add (create 0 black) Fset.empty
function colorings1 : fset coloring = add (create 1 black) Fset.empty function colorings1 : fset coloring = add (create 1 black) Fset.empty
......
...@@ -57,7 +57,7 @@ let delete (g:gap_buffer) : unit ...@@ -57,7 +57,7 @@ let delete (g:gap_buffer) : unit
Implemented by a constant (K) in the problem statement. Implemented by a constant (K) in the problem statement.
This version is more general and account for the standard doubling pattern This version is more general and account for the standard doubling pattern
as well. *) as well. *)
val growth (g:gap_buffer) : int ensures { result > 0 } val growth (_g:gap_buffer) : int ensures { result > 0 }
(* Since it is an internal primitive, it is fine to refer to r as well. *) (* Since it is an internal primitive, it is fine to refer to r as well. *)
let grow (g:gap_buffer) : unit let grow (g:gap_buffer) : unit
......
...@@ -116,7 +116,7 @@ module NQueens ...@@ -116,7 +116,7 @@ module NQueens
use ref.Refint use ref.Refint
let rec count_bt_queens (board: array int) (n: int) (pos: int) : int let rec count_bt_queens (board: array int) (n: int) (pos: int) : (_r: int)
variant { n - pos } variant { n - pos }
requires { length board = n /\ 0 <= pos <= n /\ solution board pos } requires { length board = n /\ 0 <= pos <= n /\ solution board pos }
ensures { eq_board board (old board) pos } ensures { eq_board board (old board) pos }
...@@ -133,7 +133,7 @@ module NQueens ...@@ -133,7 +133,7 @@ module NQueens
!s !s
end end
let count_queens (board: array int) (n: int) : int let count_queens (board: array int) (n: int) : (_r: int)
requires { length board = n } requires { length board = n }
ensures { true } ensures { true }
= count_bt_queens board n 0 = count_bt_queens board n 0
...@@ -204,7 +204,7 @@ module NQueens63 ...@@ -204,7 +204,7 @@ module NQueens63
i := !i + 1 i := !i + 1
done done
let count_queens (n: int63) : P.t let count_queens (n: int63) : (_p: P.t)
requires { n >= 0 } requires { n >= 0 }
ensures { true } ensures { true }
= =
......
...@@ -118,7 +118,7 @@ module Harness ...@@ -118,7 +118,7 @@ module Harness
raises { Failure -> false } raises { Failure -> false }
= build (Cons 1 (Cons 3 (Cons 3 (Cons 2 Nil)))) = build (Cons 1 (Cons 3 (Cons 3 (Cons 2 Nil))))
let harness2 () let harness2 () : (_t : tree)
ensures { false } raises { Failure -> true } ensures { false } raises { Failure -> true }
= build (Cons 1 (Cons 3 (Cons 2 (Cons 2 Nil)))) = build (Cons 1 (Cons 3 (Cons 2 (Cons 2 Nil))))
......
...@@ -115,10 +115,14 @@ val dpattern : ?loc:Loc.position -> dpattern_node -> dpattern ...@@ -115,10 +115,14 @@ val dpattern : ?loc:Loc.position -> dpattern_node -> dpattern
val dterm : Coercion.t -> ?loc:Loc.position -> dterm_node -> dterm val dterm : Coercion.t -> ?loc:Loc.position -> dterm_node -> dterm
(** Final stage *) (** Unused variables *)
val debug_ignore_unused_var : Debug.flag val debug_ignore_unused_var : Debug.flag
val attr_w_unused_var_no : Ident.attribute