@@ -230,29 +230,27 @@ let process_rewrite_at
230230 |> FApi. t_sub [t_pre; t_post; EcLowGoal. t_id]
231231
232232(* -------------------------------------------------------------------- *)
233- (* [t_change_stmt side pos ?me s] replaces a code range with [s] by
233+ (* [t_change_stmt side pos ?mt s] replaces a code range with [s] by
234234 generating:
235235 - a local equivalence goal showing that the original fragment and [s]
236236 agree under the framed precondition on the variables they both read,
237237 and produce the same values for everything observable afterwards;
238238 - the original program-logic goal with the selected range rewritten.
239239
240- If [me ] is provided, it is used as the memory environment (e.g. when
241- fresh local variables have been bound); otherwise, the memory
242- environment is taken from the goal. *)
240+ If [mt ] is provided, it is used as the memtype of the selected side (e.g.
241+ when fresh local variables have been bound); otherwise, the memtype is
242+ taken from the goal. *)
243243let t_change_stmt
244244 (side : side option )
245245 (pos : EcMatching.Position.codegap_range )
246- ?(me : memenv option )
246+ ?(mt : memtype option )
247247 (s : stmt )
248248 (tc : tcenv1 )
249249=
250250 let env = FApi. tc1_env tc in
251251
252- let me, stmt =
253- let metc, stmt = EcLowPhlGoal. tc1_get_stmt side tc in
254- (odfl metc me, stmt)
255- in
252+ let (mid, metc), stmt = EcLowPhlGoal. tc1_get_stmt side tc in
253+ let mt = odfl metc mt in
256254
257255 let zpr, (_,stmt, epilog), _nmr =
258256 EcMatching.Zipper. zipper_and_split_of_cgap_range env pos stmt in
@@ -269,8 +267,8 @@ let t_change_stmt
269267 let frame =
270268 let filter (f : form ) =
271269 let pvs = EcPV. form_read env EcPV.PMVS. empty f in
272- let pvs_me = EcIdent.Mid. find_def EcPV.PV. empty (fst me) pvs in
273- let pvs = EcIdent.Mid. remove (fst me) pvs in
270+ let pvs_me = EcIdent.Mid. find_def EcPV.PV. empty mid pvs in
271+ let pvs = EcIdent.Mid. remove mid pvs in
274272
275273 EcIdent.Mid. is_empty pvs
276274 && (EcPV.PV. indep env modi pvs_me) in
@@ -293,7 +291,7 @@ let t_change_stmt
293291 EcLowPhlGoal. logicS_post_read env
294292 (EcLowPhlGoal. get_logicS (FApi. tc1_goal tc))
295293 in
296- EcIdent.Mid. find_def EcPV.PV. empty (fst me) pvs
294+ EcIdent.Mid. find_def EcPV.PV. empty mid pvs
297295 in
298296
299297 EcPV.PV. union obs goal
@@ -314,7 +312,7 @@ let t_change_stmt
314312 let mr = EcIdent. create " &2" in
315313
316314 let frame = omap (fun frame ->
317- let subst = EcSubst. add_memory EcSubst. empty (fst me) ml in
315+ let subst = EcSubst. add_memory EcSubst. empty mid ml in
318316 EcSubst. subst_form subst frame) frame in
319317
320318 let mk_pv_eq ((pv , ty ) : prog_var * ty ) =
@@ -329,10 +327,13 @@ let t_change_stmt
329327 let po_eq = List. map mk_pv_eq wr_pvs @ List. map mk_glob_eq wr_globs in
330328
331329 (* First subgoal: prove that the replacement fragment preserves the
332- observable behavior required by the outer proof. *)
330+ observable behavior required by the outer proof. The left program is the
331+ original fragment, which only mentions the pre-existing locals
332+ ([metc]); the right program is the replacement, which may use the
333+ freshly bound locals ([mt]). *)
333334 let goal1 =
334335 f_equivS
335- (snd me) (snd me)
336+ metc mt
336337 { ml; mr; inv = ofold f_and (f_ands pr_eq) frame; }
337338 (EcAst. stmt stmt) s
338339 { ml; mr; inv = f_ands po_eq; }
@@ -341,10 +342,11 @@ let t_change_stmt
341342 let stmt = EcMatching.Zipper. zip { zpr with z_tail = s.s_node @ epilog } in
342343
343344 (* Second subgoal: continue with the original goal after rewriting the
344- selected statement range. *)
345+ selected statement range. The rewritten side also takes [mt], as the new
346+ statement may mention the fresh locals. *)
345347 let goal2 =
346348 EcLowPhlGoal. hl_set_stmt
347- side (FApi. tc1_goal tc)
349+ ~mt side (FApi. tc1_goal tc)
348350 stmt in
349351
350352 FApi. xmutate1 tc `ProcChangeStmt [goal1; goal2]
@@ -401,4 +403,4 @@ let process_change_stmt
401403 let hyps = EcEnv.LDecl. push_active_ss me hyps in
402404 let s = EcProofTyping. process_stmt hyps s in
403405
404- t_change_stmt side pos ~me s tc
406+ t_change_stmt side pos ~mt: (snd me) s tc
0 commit comments