Skip to content

Commit 8a16fb5

Browse files
committed
fix alpha-conversion problems in ehoare
1 parent c996dd8 commit 8a16fb5

3 files changed

Lines changed: 30 additions & 22 deletions

File tree

src/phl/ecPhlApp.ml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,13 @@ let t_hoare_app_r i phi tc =
2626
let t_hoare_app = FApi.t_low2 "hoare-app" t_hoare_app_r
2727

2828
(* -------------------------------------------------------------------- *)
29-
let t_ehoare_app_r i f tc =
29+
let t_ehoare_app_r i phi tc =
3030
let env = FApi.tc1_env tc in
3131
let hs = tc1_as_ehoareS tc in
3232
let s1, s2 = s_split env i hs.ehs_s in
33-
let a = f_eHoareS (snd hs.ehs_m) (ehs_pr hs) (stmt s1) f in
34-
let b = f_eHoareS (snd hs.ehs_m) f (stmt s2) (ehs_po hs) in
33+
let phi = ss_inv_rebind phi (fst hs.ehs_m) in
34+
let a = f_eHoareS (snd hs.ehs_m) (ehs_pr hs) (stmt s1) phi in
35+
let b = f_eHoareS (snd hs.ehs_m) phi (stmt s2) (ehs_po hs) in
3536
FApi.xmutate1 tc `HlApp [a; b]
3637

3738
let t_ehoare_app = FApi.t_low2 "hoare-app" t_ehoare_app_r
@@ -124,11 +125,11 @@ let t_equiv_app_onesided side i pre post tc =
124125
let (ml, mr) = fst es.es_ml, fst es.es_mr in
125126
let s, s', p', q' =
126127
match side with
127-
| `Left ->
128+
| `Left ->
128129
let p' = ss_inv_generalize_as_left pre ml mr in
129130
let q' = ss_inv_generalize_as_left post ml mr in
130131
es.es_sl, es.es_sr, p', q'
131-
| `Right ->
132+
| `Right ->
132133
let p' = ss_inv_generalize_as_right pre ml mr in
133134
let q' = ss_inv_generalize_as_right post ml mr in
134135
es.es_sr, es.es_sl, p', q'

src/phl/ecPhlConseq.ml

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ let bd_goal_r fcmp fbd cmp bd =
3939
| FHle, (FHle | FHeq) -> Some (map_ss_inv2 f_real_le bd fbd)
4040
| FHge, (FHge | FHeq) -> Some (map_ss_inv2 f_real_le fbd bd)
4141
| FHeq, FHeq -> Some (map_ss_inv2 f_eq bd fbd)
42-
| FHeq, FHge -> Some (map_ss_inv2 f_and
43-
(map_ss_inv1 ((EcUtils.flip f_eq) f_r1) fbd)
42+
| FHeq, FHge -> Some (map_ss_inv2 f_and
43+
(map_ss_inv1 ((EcUtils.flip f_eq) f_r1) fbd)
4444
(map_ss_inv1 ((EcUtils.flip f_eq) f_r1) bd))
45-
| FHeq, FHle -> Some (map_ss_inv2 f_and
46-
(map_ss_inv1 ((EcUtils.flip f_eq) f_r0) fbd)
45+
| FHeq, FHle -> Some (map_ss_inv2 f_and
46+
(map_ss_inv1 ((EcUtils.flip f_eq) f_r0) fbd)
4747
(map_ss_inv1 ((EcUtils.flip f_eq) f_r0) bd))
4848
| _ , _ -> None
4949

@@ -453,6 +453,9 @@ let t_bdHoareS_conseq_nm = gen_conseq_nm t_bdHoareS_notmod t_bdHoareS_conseq
453453
let t_ehoareF_concave (fc: ss_inv) pre post tc =
454454
let env = FApi.tc1_env tc in
455455
let hf = tc1_as_ehoareF tc in
456+
let pre = ss_inv_rebind pre hf.ehf_m in
457+
let post = ss_inv_rebind post hf.ehf_m in
458+
let fc = ss_inv_rebind fc hf.ehf_m in
456459
let f = hf.ehf_f in
457460
let mpr,mpo = Fun.hoareF_memenv hf.ehf_m f env in
458461
let fsig = (Fun.by_xpath f env).f_sig in
@@ -491,6 +494,9 @@ let t_ehoareS_concave (fc: ss_inv) (* xreal -> xreal *) pre post tc =
491494
let hs = tc1_as_ehoareS tc in
492495
let s = hs.ehs_s in
493496
let m = fst hs.ehs_m in
497+
let pre = ss_inv_rebind pre m in
498+
let post = ss_inv_rebind post m in
499+
let fc = ss_inv_rebind fc m in
494500
(* ensure that f only depend of notmod *)
495501
let modi = s_write env s in
496502
let fv = PV.fv env m fc.inv in
@@ -614,7 +620,7 @@ let process_concave ((info, fc) : pformula option tuple2 gppterm * pformula) tc
614620

615621
let pre = map_ss_inv1 (fun gpre -> pre |> omap (TTC.pf_process_form !!tc penv txreal) |> odfl gpre) gpre in
616622
let post = map_ss_inv1 (fun gpost -> post |> omap (TTC.pf_process_form !!tc qenv txreal) |> odfl gpost) gpost in
617-
623+
618624
fmake pre post
619625

620626
in
@@ -665,9 +671,9 @@ let t_hoareS_conseq_conj pre post pre' post' tc =
665671
let hs = tc1_as_hoareS tc in
666672
let pre'' = map_ss_inv2 f_and pre' pre in
667673
let post'' = map_ss_inv2 f_and post' post in
668-
if not (ss_inv_alpha_eq hyps (hs_pr hs) pre'')
674+
if not (ss_inv_alpha_eq hyps (hs_pr hs) pre'')
669675
then tc_error !!tc "invalid pre-condition";
670-
if not (ss_inv_alpha_eq hyps (hs_po hs) post'')
676+
if not (ss_inv_alpha_eq hyps (hs_po hs) post'')
671677
then tc_error !!tc "invalid post-condition";
672678
let concl1 = f_hoareS (snd hs.hs_m) pre hs.hs_s post in
673679
let concl2 = f_hoareS (snd hs.hs_m) pre' hs.hs_s post' in
@@ -679,7 +685,7 @@ let t_hoareF_conseq_conj pre post pre' post' tc =
679685
let hf = tc1_as_hoareF tc in
680686
let pre'' = map_ss_inv2 f_and pre' pre in
681687
let post'' = map_ss_inv2 f_and post' post in
682-
if not (ss_inv_alpha_eq hyps (hf_pr hf) pre'')
688+
if not (ss_inv_alpha_eq hyps (hf_pr hf) pre'')
683689
then tc_error !!tc "invalid pre-condition";
684690
if not (ss_inv_alpha_eq hyps (hf_po hf) post'')
685691
then tc_error !!tc "invalid post-condition";
@@ -696,7 +702,7 @@ let t_bdHoareS_conseq_conj ~add post post' tc =
696702
if not (ss_inv_alpha_eq hyps (bhs_po hs) postc) then
697703
tc_error !!tc "invalid post-condition";
698704
let concl1 = f_hoareS (snd hs.bhs_m) (bhs_pr hs) hs.bhs_s post in
699-
let concl2 = f_bdHoareS (snd hs.bhs_m) (bhs_pr hs) hs.bhs_s posth
705+
let concl2 = f_bdHoareS (snd hs.bhs_m) (bhs_pr hs) hs.bhs_s posth
700706
hs.bhs_cmp (bhs_bd hs) in
701707
FApi.xmutate1 tc `HlConseqBd [concl1; concl2]
702708

@@ -765,7 +771,7 @@ let t_equivS_conseq_bd side pr po tc =
765771
let pos = ss_inv_generalize_as_left po ml mr in
766772
let prs = ss_inv_generalize_as_left pr ml mr in
767773
es.es_ml, es.es_sl, es.es_sr, prs, pos
768-
| `Right ->
774+
| `Right ->
769775
let pos = ss_inv_generalize_as_right po ml mr in
770776
let prs = ss_inv_generalize_as_right pr ml mr in
771777
es.es_mr, es.es_sr, es.es_sl, prs, pos
@@ -921,7 +927,7 @@ let rec t_hi_conseq notmod f1 f2 f3 tc =
921927
let tac = if notmod then t_hoareS_conseq_nm else t_hoareS_conseq in
922928

923929
t_on1seq 2
924-
(tac (map_ss_inv2 f_and (hs_pr hs) (hs_pr hs2))
930+
(tac (map_ss_inv2 f_and (hs_pr hs) (hs_pr hs2))
925931
(map_ss_inv2 f_and (hs_po hs) (hs_po hs2)))
926932
(FApi.t_seqsub
927933
(t_hoareS_conseq_conj (hs_pr hs2) (hs_po hs2) (hs_pr hs) (hs_po hs))
@@ -962,7 +968,7 @@ let rec t_hi_conseq notmod f1 f2 f3 tc =
962968
let po2 = ss_inv_rebind (hf_po hs2) hf.hf_m in
963969
(* check that the pre- and post-conditions are well formed *)
964970
t_on1seq 2
965-
((tac (map_ss_inv2 f_and pr1 pr2)
971+
((tac (map_ss_inv2 f_and pr1 pr2)
966972
(map_ss_inv2 f_and po1 po2)))
967973
(FApi.t_seqsub
968974
(t_hoareF_conseq_conj pr2 po2 pr1 po1)
@@ -1162,7 +1168,7 @@ let rec t_hi_conseq notmod f1 f2 f3 tc =
11621168
Some ((_, {f_node = FequivF ef}) as nef), Some((_, f2) as nf2), _ ->
11631169
let hf2 = pf_as_bdhoareF !!tc f2 in
11641170
FApi.t_seqsub
1165-
(t_bdHoareF_conseq_equiv hf2.bhf_f (ef_pr ef) (ef_po ef)
1171+
(t_bdHoareF_conseq_equiv hf2.bhf_f (ef_pr ef) (ef_po ef)
11661172
(bhf_pr hf2) (bhf_po hf2) (bhf_bd hf2))
11671173
[t_id; t_id; t_apply_r nef; t_apply_r nf2] tc
11681174

@@ -1467,7 +1473,7 @@ let process_conseq notmod ((info1, info2, info3) : conseq_ppterm option tuple3)
14671473
let f, pr, po = match f1 with
14681474
| None -> hf.hf_f, hf_pr hf, hf_po hf
14691475
| Some f1 -> match (snd f1).f_node with
1470-
| FequivF ef when side = `Left ->
1476+
| FequivF ef when side = `Left ->
14711477
ef.ef_fr, {m; inv=f_true}, {m; inv=f_true}
14721478
| _ -> hf.hf_f, hf_pr hf, hf_po hf
14731479
in
@@ -1482,7 +1488,7 @@ let process_conseq notmod ((info1, info2, info3) : conseq_ppterm option tuple3)
14821488
| Some f1 -> match (snd f1).f_node with
14831489
| FequivF ef when side = `Left ->
14841490
let f_xreal_1 = f_r2xr f_r1 in
1485-
ef.ef_fr, {m=ef.ef_mr; inv=f_xreal_1},
1491+
ef.ef_fr, {m=ef.ef_mr; inv=f_xreal_1},
14861492
{m=ef.ef_mr; inv=f_xreal_1}, ef.ef_mr
14871493
| _ -> hf.ehf_f, ehf_pr hf, ehf_po hf, hf.ehf_m
14881494
in
@@ -1502,7 +1508,7 @@ let process_conseq notmod ((info1, info2, info3) : conseq_ppterm option tuple3)
15021508
let f, pr, po, m = match f1 with
15031509
| None -> bhf.bhf_f, bhf_pr bhf, bhf_po bhf, bhf.bhf_m
15041510
| Some f1 -> match (snd f1).f_node with
1505-
| FequivF ef when side = `Left -> ef.ef_fr,
1511+
| FequivF ef when side = `Left -> ef.ef_fr,
15061512
{m=ef.ef_mr;inv=f_true}, {m=ef.ef_mr;inv=f_true}, ef.ef_mr
15071513
| _ -> bhf.bhf_f, bhf_pr bhf, bhf_po bhf, bhf.bhf_m
15081514
in

src/phl/ecPhlDeno.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ let t_phoare_deno_r pre post tc =
8686

8787
(* -------------------------------------------------------------------- *)
8888
let t_ehoare_deno_r pre post tc =
89-
assert (pre.m = post.m);
9089
let m = pre.m in
90+
assert (m = post.m);
9191
let env, _, concl = FApi.tc1_eflat tc in
9292

9393
let f, bd =
@@ -111,6 +111,7 @@ let t_ehoare_deno_r pre post tc =
111111

112112
(* forall m, ev%r%xr <= post *)
113113
let ev = pr.pr_event in
114+
let ev = ss_inv_rebind ev m in
114115
let concl_po = map_ss_inv2 f_xreal_le (map_ss_inv1 f_b2xr ev) post in
115116
let concl_po = f_forall_mems_ss_inv mpo concl_po in
116117

0 commit comments

Comments
 (0)