Skip to content
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
33 changes: 20 additions & 13 deletions src/phl/ecPhlCall.ml
Original file line number Diff line number Diff line change
Expand Up @@ -750,21 +750,32 @@ let process_call_concave (fc, info) tc =

| _ -> tc_error !!tc "the conclusion is not a ehoare" in

let process_spec tc =
let _, concl = FApi.tc1_flat tc in
(* As for [call] (see [process_call]), the specification is typed in the
memories of the called procedure, and the invariant in an abstract
memory: the local variables of the caller are not in scope (they
would be read as the callee's variables of the same name). *)
let process_spec tc pre post =
let hyps, concl = FApi.tc1_flat tc in
match concl.f_node with
| FeHoareS hs ->
let (_,f,_) = fst (tc1_last_call tc hs.ehs_s) in
(txreal, fun pre post -> f_eHoareF pre f post)
let m = EcIdent.create "&hr" in
let penv, qenv = LDecl.hoareF m f hyps in
let pre = TTC.pf_process_form !!tc penv txreal pre in
let post = TTC.pf_process_form !!tc qenv txreal post in
f_eHoareF {m; inv = pre} f {m; inv = post}

| _ -> tc_error !!tc "the conclusion is not a ehoare" in

let process_inv tc =
let _, concl = FApi.tc1_flat tc in
let process_inv tc inv =
let hyps, concl = FApi.tc1_flat tc in
match concl.f_node with
| FeHoareS hs ->
let m = fst hs.ehs_m in
let (_,f,_) = fst (tc1_last_call tc hs.ehs_s) in
(txreal, fun inv -> f_eHoareF inv f inv)
let hyps = LDecl.push_active_ss (EcMemory.abstract m) hyps in
let inv = {m; inv = TTC.pf_process_form !!tc hyps txreal inv} in
(f_eHoareF inv f inv, inv)

| _ -> tc_error !!tc "the conclusion is not a ehoare" in

Expand All @@ -773,17 +784,13 @@ let process_call_concave (fc, info) tc =
let process_cut tc info =
match info with
| CI_spec (pre, epost) ->
let ty,fmake = process_spec tc in
let _, pre = TTC.tc1_process_Xhl_form tc ty pre in
let _, post = TTC.tc1_process_Xhl_form tc ty epost.pnormal in
fmake pre post
process_spec tc pre epost.pnormal

| CI_inv inv ->
let ty, fmake = process_inv tc in
let _, inv = TTC.tc1_process_Xhl_form tc ty inv in
let spec, inv = process_inv tc inv in
subtactic := (fun tc ->
FApi.t_firsts t_trivial 2 (EcPhlFun.t_fun (Inv_ss inv) tc));
fmake inv
spec

| _ ->
tc_error !!tc "cannot supply additional information for call /"
Expand Down
41 changes: 41 additions & 0 deletions tests/ehoare-call-concave-locals.ec
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
(* [call /fc] on an ehoare goal: as for [call], the specification is typed
in the memories of the called procedure and the invariant in an
abstract memory, so that the local variables of the caller are not in
scope (they used to be read as the callee's variables of the same
name, which proves [false]). *)
require import AllCore Xreal.

module G = { var g : int }.

module M = {
proc g() = { var y; y <- 0; }

proc h() = { var y; G.g <- G.g + 1; y <- G.g; }

proc main() : int = { var y; y <- 1; g(); return y; }

proc main2() : bool = { var y; G.g <- 0; y <- 0; h(); return y <> G.g; }
}.

(* the specification mentions [y], a local of the caller *)
lemma bad : ehoare [M.main : 0%xr ==> (res = 1)%xr].
proof.
proc.
fail call /(fun x => x) (_ : 0%xr ==> (y = 1)%xr).
abort.

(* the invariant mentions [y], a local of the caller *)
lemma bad_inv : ehoare [M.main2 : 0%xr ==> res%xr].
proof.
proc.
fail call /(fun x => x) (: (y <> G.g)%xr).
abort.

(* globals only: accepted *)
lemma ok : ehoare [M.main2 : 1%xr ==> (G.g = 1)%xr].
proof.
proc.
call /(fun x => x) (_ : (G.g = 0)%xr ==> (G.g = 1)%xr).
+ by proc; auto => &hr /=; have -> : (G.g{hr} + 1 = 1) = (G.g{hr} = 0) by smt().
by auto.
qed.
Loading