Skip to content

Commit a172f1b

Browse files
committed
Rewriting in the pre-condition of PL logics
Allows rewriting inside the pre-condition of any PL logic. Syntax: `proc rewrite @pre ...` The side conditions generated by the rewriting have to be checked under the initial pre-condition. This tactic is outside of the TCB.
1 parent de800c1 commit a172f1b

15 files changed

Lines changed: 161 additions & 35 deletions

src/ecAst.ml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,13 @@ let inv_of_inv (inv: inv) : form =
472472
match inv with
473473
| Inv_ss ss -> ss.inv
474474
| Inv_ts ts -> ts.inv
475-
| _ -> failwith "expected single or two sided invarinat"
475+
| _ -> failwith "expected single or two sided invariant"
476+
477+
let memories_of_inv (inv : inv) : memory list =
478+
match inv with
479+
| Inv_ss ss -> [ss.m]
480+
| Inv_ts ts -> [ts.ml; ts.mr]
481+
| Inv_hs hs -> [hs.hsi_m]
476482

477483
let lift_ss_inv (f: ss_inv -> 'a) : inv -> 'a =
478484
let f inv = match inv with

src/ecAst.mli

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,7 @@ type inv =
419419
| Inv_hs of hs_inv
420420

421421
val inv_of_inv : inv -> form
422+
val memories_of_inv : inv -> memory list
422423

423424
val lift_ss_inv : (ss_inv -> 'a) -> inv -> 'a
424425
val lift_ss_inv2 : (ss_inv -> ss_inv -> 'a) -> inv -> inv -> 'a

src/ecHiGoal.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1403,8 +1403,8 @@ let rec process_mintros_1 ?(cf = true) ttenv pis gs =
14031403

14041404
and intro1_dup (_ : ST.state) (tc : tcenv1) =
14051405
try
1406-
let pt = PT.pt_of_uglobal !!tc (FApi.tc1_hyps tc) LG.p_ip_dup in
1407-
EcLowGoal.Apply.t_apply_bwd_r ~mode:fmrigid ~canview:false pt tc
1406+
EcLowGoal.t_duplicate_top_assumtion tc
1407+
14081408
with EcLowGoal.Apply.NoInstance _ ->
14091409
tc_error !!tc "no top-assumption to duplicate"
14101410

src/ecHiTacticals.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ and process1_phl (_ : ttenv) (t : phltactic located) (tc : tcenv1) =
230230
| Plossless -> EcPhlHiAuto.t_lossless
231231
| Prepl_stmt infos -> EcPhlTrans.process_equiv_trans infos
232232
| Pprocrewrite (s, p, f) -> EcPhlRewrite.process_rewrite s p f
233+
| Pprocrewriteat (x, f) -> EcPhlRewrite.process_rewrite_at x f
233234
| Pchangestmt (s, p, c) -> EcPhlRewrite.process_change_stmt s p c
234235
| Prwprgm infos -> EcPhlRwPrgm.process_rw_prgm infos
235236
| Phoaresplit -> EcPhlHoare.process_hoaresplit

src/ecLowGoal.ml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -845,6 +845,12 @@ module Apply = struct
845845
846846
end
847847
848+
(* -------------------------------------------------------------------- *)
849+
let t_duplicate_top_assumtion (tc : tcenv1) =
850+
let hlemma = EcCoreLib.CI_Logic.p_ip_dup in
851+
let pt = PT.pt_of_uglobal !!tc (FApi.tc1_hyps tc) hlemma in
852+
Apply.t_apply_bwd_r ~mode:EcMatching.fmrigid ~canview:false pt tc
853+
848854
(* -------------------------------------------------------------------- *)
849855
type genclear = [`Clear | `TryClear | `NoClear]
850856

src/ecLowGoal.mli

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,9 @@ val t_right : ?reduce:lazyred -> FApi.backward
158158

159159
val t_or_intro_prind : ?reduce:lazyred -> side -> FApi.backward
160160

161+
(* -------------------------------------------------------------------- *)
162+
val t_duplicate_top_assumtion : FApi.backward
163+
161164
(* -------------------------------------------------------------------- *)
162165
val t_split : ?i: int -> ?closeonly:bool -> ?reduce:lazyred -> FApi.backward
163166
val t_split_prind : ?reduce:lazyred -> FApi.backward

src/ecLowPhlGoal.ml

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,6 @@ let get_post f =
268268
| FequivS es -> Some (Inv_ts (es_po es))
269269
| _ -> None
270270

271-
272271
let tc1_get_post tc =
273272
match get_post (FApi.tc1_goal tc) with
274273
| None -> tc_error_noXhl ~kinds:hlkinds_Xhl !!tc
@@ -304,6 +303,33 @@ let set_pre ~pre f =
304303
f_equivS (snd es.es_ml) (snd es.es_mr) pre es.es_sl es.es_sr (es_po es)
305304
| _ -> assert false
306305

306+
(* -------------------------------------------------------------------- *)
307+
let get_memenvs_pre (env : env) (f : form) =
308+
match f.f_node with
309+
| FhoareF hf -> Some [fst (EcEnv.Fun.hoareF_memenv hf.hf_m hf.hf_f env)]
310+
| FhoareS hs -> Some [hs.hs_m]
311+
| FeHoareF hf -> Some [fst (EcEnv.Fun.hoareF_memenv hf.ehf_m hf.ehf_f env)]
312+
| FeHoareS hs -> Some [hs.ehs_m]
313+
| FbdHoareF hf -> Some [fst (EcEnv.Fun.hoareF_memenv hf.bhf_m hf.bhf_f env)]
314+
| FbdHoareS hs -> Some [hs.bhs_m]
315+
| FequivF ef -> Some (List.of_pair (fst (EcEnv.Fun.equivF_memenv ef.ef_ml ef.ef_mr ef.ef_fl ef.ef_fr env)))
316+
| FequivS es -> Some [es.es_ml; es.es_mr]
317+
| _ -> None
318+
319+
(* -------------------------------------------------------------------- *)
320+
let push_memenvs_pre (hyps : LDecl.hyps) (f : form) =
321+
match get_memenvs_pre (LDecl.toenv hyps) f with
322+
| Some [m] ->
323+
let m = (EcIdent.create "&hr", snd m) in
324+
let hyps = EcEnv.LDecl.push_active_ss m hyps in
325+
([m], hyps)
326+
| Some [ml; mr] ->
327+
let ml = (EcIdent.create "&1", snd ml) in
328+
let mr = (EcIdent.create "&2", snd mr) in
329+
let hyps = EcEnv.LDecl.push_active_ts ml mr hyps in
330+
([ml; mr], hyps)
331+
| _ -> assert false
332+
307333
(* -------------------------------------------------------------------- *)
308334
exception InvalidSplit of codepos1
309335

src/ecParser.mly

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3201,6 +3201,9 @@ interleave_info:
32013201
| PROC REWRITE side=side? pos=codepos SLASHEQ
32023202
{ Pprocrewrite (side, pos, `Simpl) }
32033203

3204+
| PROC REWRITE AT tg=ident f=pterm
3205+
{ Pprocrewriteat (tg, f) }
3206+
32043207
| HOARE SPLIT
32053208
{ Phoaresplit }
32063209

src/ecParsetree.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -789,6 +789,7 @@ type phltactic =
789789
| Pbdhoare_split of bdh_split
790790
| Prwprgm of rwprgm
791791
| Pprocrewrite of side option * pcodepos * prrewrite
792+
| Pprocrewriteat of psymbol * ppterm
792793
| Pchangestmt of side option * pcodepos_range * pstmt
793794
| Phoaresplit
794795

src/ecSubst.ml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1201,3 +1201,12 @@ let hs_inv_rebind ({hsi_inv;hsi_m}: hs_inv) (m': memory) : hs_inv =
12011201
else
12021202
let hsi_inv = POE.map (subst_form (add_memory empty hsi_m m')) hsi_inv in
12031203
{ hsi_inv; hsi_m = m' }
1204+
1205+
(* -------------------------------------------------------------------- *)
1206+
let inv_rebind (inv : inv) (ms : memory list) : inv =
1207+
match inv, ms with
1208+
| Inv_ss ss, [m] -> Inv_ss (ss_inv_rebind ss m)
1209+
| Inv_ts ts, [ml; mr] -> Inv_ts (ts_inv_rebind ts ml mr)
1210+
| Inv_hs hs, [m] -> Inv_hs (hs_inv_rebind hs m)
1211+
| _, _ -> assert false
1212+

0 commit comments

Comments
 (0)