Skip to content

Commit ad61404

Browse files
bgregoirlyonel2017
authored andcommitted
fix conseq for exception with argument
1 parent 82537c9 commit ad61404

9 files changed

Lines changed: 55 additions & 40 deletions

File tree

examples/exception.ec

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,14 @@ proof.
107107
auto. smt(a5 a3 a4).
108108
qed.
109109

110+
op o : exn = e2.
111+
110112
module M1 ={
111113
var i:int
112114

113115
proc f1 (x:int) : int = {
114116
i <- 0;
115-
raise e2;
117+
raise o;
116118
return x;
117119
}
118120

@@ -128,7 +130,7 @@ lemma test (_x: int):
128130
proof.
129131
proc.
130132
call (: true ==> true | e2 => M1.i = 0).
131-
+ by proc; auto.
133+
+ proc. wp. auto.
132134
by auto.
133135
qed.
134136

@@ -167,3 +169,30 @@ proof.
167169
ecall(test3 x).
168170
auto.
169171
qed.
172+
173+
exception arg1 of int.
174+
175+
module M3 = {
176+
proc f () = {
177+
raise (arg1 3);
178+
}
179+
180+
}.
181+
182+
lemma test5 :
183+
hoare [M3.f : true ==> false | arg1 x => x = 3].
184+
proof.
185+
proc. wp. skip => //.
186+
qed.
187+
188+
lemma test6 :
189+
hoare [M3.f : true ==> false | arg1 x => x = 3].
190+
proof.
191+
conseq (: _ ==> _ | arg1 x => 3 = x).
192+
+ done.
193+
proc. wp. skip => //.
194+
qed.
195+
196+
197+
198+

src/ecAst.ml

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -652,26 +652,6 @@ let iter2_poe f (p1,m1,d1) (p2,m2,d2) =
652652
| Some d1, Some d2 -> f d1 d2
653653
| _, _ -> failwith "missing default exception"
654654

655-
let merge2_poe_list f (poe1,d1) (poe2,d2) =
656-
let get_default d =
657-
match d with
658-
| Some d -> d
659-
| None -> failwith "no default exception"
660-
in
661-
let aux _ a b =
662-
match a,b with
663-
| Some a, Some b -> Some (f b a)
664-
| Some a, None -> Some (f (get_default d2) a)
665-
| None, Some b -> Some (f b (get_default d1))
666-
| None, None -> assert false
667-
in
668-
let epost = Mp.merge aux poe1 poe2 in
669-
let poe = List.map snd (Mp.bindings epost) in
670-
match d2, d1 with
671-
| None, _ -> poe
672-
| Some d2, Some d1 -> f d2 d1 :: poe
673-
| _, _ -> failwith "no default exception"
674-
675655
(* ----------------------------------------------------------------- *)
676656
(* Accessors for program logic *)
677657
(* ----------------------------------------------------------------- *)

src/ecAst.mli

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -386,12 +386,6 @@ val forall2_poe : (form -> form -> bool) -> post -> post -> bool
386386
val poe_to_list : 'a * 'a Mp.t * 'a option -> 'a list
387387
val iter_poe : (form -> unit) -> post -> unit
388388
val iter2_poe : (form -> form -> unit) -> post -> post -> unit
389-
val merge2_poe_list :
390-
(form -> form -> form) ->
391-
form Mp.t * form option ->
392-
form Mp.t * form option ->
393-
form list
394-
395389

396390
(* -------------------------------------------------------------------- *)
397391

src/ecProofTyping.ml

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -263,22 +263,30 @@ let destruct_exists ?(reduce = true) hyps fp : dexists option =
263263
lazy_destruct ~reduce hyps doit fp
264264

265265
(* -------------------------------------------------------------------- *)
266-
let merge2_poe_list f (poe1,d1) (poe2,d2) =
266+
let merge2_poe_list (poe1,d1) (poe2,d2) =
267267
let get_default d =
268268
match d with
269269
| Some d -> d
270270
| None -> failwith "no default exception"
271271
in
272272
let aux _ a b =
273273
match a,b with
274-
| Some a, Some b -> Some (f b a)
275-
| Some a, None -> Some (f (get_default d2) a)
276-
| None, Some b -> Some (f b (get_default d1))
274+
| Some a, Some b ->
275+
let bd, body = decompose_lambda a in
276+
let args = List.map (fun (x, gty) -> f_local x (gty_as_ty gty)) bd in
277+
Some (f_forall bd (f_imp (f_app_simpl b args tbool) body))
278+
279+
| Some a, None ->
280+
let bd, body = decompose_lambda a in
281+
Some (f_forall bd (f_imp (get_default d2) body))
282+
| None, Some b ->
283+
let bd, body = decompose_lambda b in
284+
Some (f_forall bd (f_imp body (get_default d1)))
277285
| None, None -> assert false
278286
in
279287
let epost = Mp.merge aux poe1 poe2 in
280288
let poe = List.map snd (Mp.bindings epost) in
281289
match d2, d1 with
282290
| None, _ -> poe
283-
| Some d2, Some d1 -> f d2 d1 :: poe
291+
| Some d2, Some d1 -> f_imp d2 d1 :: poe
284292
| _, _ -> failwith "no default exception"

src/ecProofTyping.mli

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ val destruct_exists : ?reduce:bool -> EcEnv.LDecl.hyps -> form -> dexists optio
8686
(* -------------------------------------------------------------------- *)
8787

8888
val merge2_poe_list :
89-
(form -> form -> form) ->
9089
form Mp.t * form option ->
9190
form Mp.t * form option ->
9291
form list

src/phl/ecPhlCall.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ let t_hoare_call fpre fpost tc =
8888
let spre = subst_args_call env m (e_tuple args) PVM.empty in
8989
let post = map_ss_inv2 f_anda_simpl (map_ss_inv1 (PVM.subst env spre) fpre) post in
9090

91-
let poe = merge2_poe_list f_imp_simpl (epost,d) (fepost,fd) in
91+
let poe = TTC.merge2_poe_list (epost,d) (fepost,fd) in
9292
let poe = List.map (fun inv -> {m;inv}) poe in
9393
let penv_e = EcEnv.Fun.inv_memenv1 m env in
9494
let poe = List.map (generalize_mod_ss_inv penv_e modi) poe in

src/phl/ecPhlConseq.ml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,15 @@ let t_hoareF_conseq pre post tc =
7171
let cond1, cond2 =
7272
conseq_cond_ss (hf_pr hf) {m;inv=fpost} pre {m;inv=post}
7373
in
74-
let cond2e = merge2_poe_list f_imp (fepost,fd) (epost,d) in
74+
let cond2e = TTC.merge2_poe_list (fepost,fd) (epost,d) in
7575
let cond2 = List.fold f_and cond2.inv cond2e in
7676
let concl1 = f_forall_mems_ss_inv mpr cond1 in
7777
let concl2 = f_forall_mems_ss_inv mpo {m;inv=cond2} in
7878
let concl3 = f_hoareF pre hf.hf_f {hsi_m=m;hsi_inv=(post, epost,d)} in
7979
FApi.xmutate1 tc `Conseq [concl1; concl2; concl3]
8080

8181
(* -------------------------------------------------------------------- *)
82+
8283
let t_hoareS_conseq pre post tc =
8384
let hs = tc1_as_hoareS tc in
8485
let pre = ss_inv_rebind pre (fst hs.hs_m) in
@@ -89,7 +90,7 @@ let t_hoareS_conseq pre post tc =
8990
let cond1, cond2 =
9091
conseq_cond_ss (hs_pr hs) {m;inv=fpost} pre {m;inv=post}
9192
in
92-
let cond2e = merge2_poe_list f_imp (fepost,fd) (epost,d) in
93+
let cond2e = TTC.merge2_poe_list (fepost,fd) (epost,d) in
9394
let cond2 = List.fold f_and cond2.inv cond2e in
9495
let concl1 = f_forall_mems_ss_inv hs.hs_m cond1 in
9596
let concl2 = f_forall_mems_ss_inv hs.hs_m {m=fst hs.hs_m;inv=cond2} in
@@ -351,7 +352,7 @@ let t_hoareF_notmod post tc =
351352
let (post, epost, d) = p.hsi_inv in
352353
let (fpost, fepost,fd) = (hf_po hf).hsi_inv in
353354
let cond = f_imp post fpost in
354-
let econd1 = merge2_poe_list f_imp (fepost,fd) (epost,d) in
355+
let econd1 = TTC.merge2_poe_list (fepost,fd) (epost,d) in
355356
let cond1 = List.fold f_and cond econd1 in
356357
let cond1, _, _ = cond_hoareF_notmod tc {m=hf.hf_m;inv=cond1} in
357358
let cond2 = f_hoareF (hf_pr hf) hf.hf_f p in
@@ -379,7 +380,7 @@ let t_hoareS_notmod post tc =
379380
let (post, epost, d) = p.hsi_inv in
380381
let (fpost, fepost,fd) = (hs_po hs).hsi_inv in
381382
let cond = f_imp post fpost in
382-
let econd1 = merge2_poe_list f_imp (fepost,fd) (epost,d) in
383+
let econd1 = TTC.merge2_poe_list (fepost,fd) (epost,d) in
383384
let cond1 = List.fold f_and cond econd1 in
384385
let cond1, _, _ = cond_hoareS_notmod tc {m=fst hs.hs_m;inv=cond1} in
385386
let cond2 = f_hoareS (snd hs.hs_m) (hs_pr hs) hs.hs_s p in

src/phl/ecPhlWp.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ module LowInternal = struct
1818
let f = EcReduction.h_red_until EcReduction.full_red hyps f in
1919
let (ex, _tys), args = destr_op_app f in
2020
match Mp.find ex epost with
21-
| f -> f_app f args EcTypes.tbool
21+
| f -> f_app_simpl f args EcTypes.tbool
2222
| exception Not_found ->
2323
match d with
2424
| Some d -> d

theories/prelude/Pervasive.ec

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,7 @@ op mu: 'a distr -> ('a -> bool) -> real.
3434

3535
(* -------------------------------------------------------------------- *)
3636
op witness : 'a. (* All types are inhabited in EC *)
37+
38+
(* -------------------------------------------------------------------- *)
39+
40+
type exn.

0 commit comments

Comments
 (0)