@@ -6,7 +6,6 @@ open EcCoreGoal
66open EcEnv
77open EcModules
88open EcFol
9- open EcMatching
109
1110module L = EcLocation
1211module PT = EcProofTerm
@@ -230,44 +229,11 @@ let process_rewrite_at
230229 EcPhlConseq. t_conseq pre post tc
231230 |> FApi. t_sub [t_pre; t_post; EcLowGoal. t_id]
232231
233- (* -------------------------------------------------------------------- *)
234- let zpr_write (env : env ) =
235- let rec doit (ctxt : instr option ) (pvs : EcPV.PV.t ) (zpr : Zipper.spath ) =
236- let (head, tail), ipath = zpr in
237- let tail = List. ocons ctxt tail in
238- let s = stmt (List. rev_append head tail) in
239-
240- let pvs = EcPV. is_write_r env pvs head in
241-
242- let parent, pvs =
243- match ipath with
244- | Zipper. ZTop ->
245- None , pvs
246-
247- | Zipper. ZIfThen (e , ps , se ) ->
248- Some (ps, i_if (e, s, se)), pvs
249-
250- | Zipper. ZIfElse (e , st , ps ) ->
251- Some (ps, i_if (e, st, s)), pvs
252-
253- | Zipper. ZMatch (e , ps , mpi ) ->
254- let bs =
255- List. rev_append mpi.prebr ((mpi.locals, s) :: mpi.postbr)
256- in Some (ps, i_match (e, bs)), pvs
257-
258- | Zipper. ZWhile (e , ps ) ->
259- Some (ps, i_while (e, s)), EcPV. is_write_r env pvs tail
260- in
261-
262- ofold (fun (zpr , ctxt ) pvs -> doit (Some ctxt) pvs zpr) pvs parent
263-
264- in fun pvs zpr -> doit None pvs zpr
265-
266232(* -------------------------------------------------------------------- *)
267233(* [change] replaces a code range with [s] by generating:
268234 - a local equivalence goal showing that the original fragment and [s]
269235 agree under the framed precondition on the variables they both read,
270- and produce the same values for everything they may write ;
236+ and produce the same values for everything observable afterwards ;
271237 - the original program-logic goal with the selected range rewritten. *)
272238let t_change_stmt
273239 (side : side option )
@@ -284,9 +250,9 @@ let t_change_stmt
284250 (* Collect the variables that may be modified by the surrounding context,
285251 excluding the fragment being replaced. *)
286252 let modi =
287- let zpr =
288- (zpr.z_head, List. drop ( List. length stmt) zpr.z_tail), zpr.z_path
289- in zpr_write env EcPV.PV. empty zpr in
253+ let zpr = { zpr with z_tail = epilog } in
254+ let zpr = (zpr.z_head, zpr.z_tail), zpr.z_path in
255+ EcPV. zpr_pv `Write `Before env EcPV.PV. empty zpr in
290256
291257 (* Keep only the top-level conjuncts of the current precondition that talk
292258 about the active memory and are independent from the surrounding writes. *)
@@ -307,8 +273,26 @@ let t_change_stmt
307273 let written = EcPV. is_write_r env written stmt in
308274 let written = EcPV. is_write_r env written s.s_node in
309275
276+ let obs =
277+ let zpr = { zpr with z_tail = epilog } in
278+ let zpr = (zpr.z_head, zpr.z_tail), zpr.z_path in
279+ let obs = EcPV. zpr_pv `Read `After env EcPV.PV. empty zpr in
280+
281+ let goal =
282+ let pvs =
283+ EcLowPhlGoal. logicS_post_read env
284+ (EcLowPhlGoal. get_logicS (FApi. tc1_goal tc))
285+ in
286+ EcIdent.Mid. find_def EcPV.PV. empty (fst me) pvs
287+ in
288+
289+ EcPV.PV. union obs goal
290+ in
291+
292+ let written = EcPV.PV. inter written obs in
293+
310294 (* The local equivalence goal relates shared reads in the precondition and
311- all possible writes in the postcondition. *)
295+ the writes that remain observable in the continuation/ postcondition. *)
312296 let wr_pvs, wr_globs = EcPV.PV. elements written in
313297
314298 let pr_pvs, pr_globs = EcPV.PV. elements @@ EcPV.PV. inter
@@ -337,11 +321,11 @@ let t_change_stmt
337321 (* First subgoal: prove that the replacement fragment preserves the
338322 observable behavior required by the outer proof. *)
339323 let goal1 =
340- f_equivS
341- (snd me) (snd me)
342- { ml; mr; inv = ofold f_and (f_ands pr_eq) frame; }
343- (EcAst. stmt stmt) s
344- { ml; mr; inv = f_ands po_eq; }
324+ f_equivS
325+ (snd me) (snd me)
326+ { ml; mr; inv = ofold f_and (f_ands pr_eq) frame; }
327+ (EcAst. stmt stmt) s
328+ { ml; mr; inv = f_ands po_eq; }
345329 in
346330
347331 let stmt = EcMatching.Zipper. zip { zpr with z_tail = s.s_node @ epilog } in
0 commit comments