@@ -230,19 +230,29 @@ let process_rewrite_at
230230 |> FApi. t_sub [t_pre; t_post; EcLowGoal. t_id]
231231
232232(* -------------------------------------------------------------------- *)
233- (* [change] replaces a code range with [s] by generating:
233+ (* [t_change_stmt side pos ?me s] replaces a code range with [s] by
234+ generating:
234235 - a local equivalence goal showing that the original fragment and [s]
235236 agree under the framed precondition on the variables they both read,
236237 and produce the same values for everything observable afterwards;
237- - the original program-logic goal with the selected range rewritten. *)
238+ - the original program-logic goal with the selected range rewritten.
239+
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. *)
238243let t_change_stmt
239- (side : side option )
240- (pos : EcMatching.Position.codegap_range )
241- (s : stmt )
242- (tc : tcenv1 )
244+ (side : side option )
245+ (pos : EcMatching.Position.codegap_range )
246+ ?(me : memenv option )
247+ (s : stmt )
248+ (tc : tcenv1 )
243249=
244250 let env = FApi. tc1_env tc in
245- let me, stmt = EcLowPhlGoal. tc1_get_stmt side tc in
251+
252+ let me, stmt =
253+ let metc, stmt = EcLowPhlGoal. tc1_get_stmt side tc in
254+ (odfl metc me, stmt)
255+ in
246256
247257 let zpr, (_,stmt, epilog), _nmr =
248258 EcMatching.Zipper. zipper_and_split_of_cgap_range env pos stmt in
@@ -342,10 +352,12 @@ let t_change_stmt
342352(* -------------------------------------------------------------------- *)
343353let process_change_stmt
344354 (side : side option )
355+ (binds : ptybindings option )
345356 (pos : prange1_or_insert )
346357 (s : pstmt )
347358 (tc : tcenv1 )
348359=
360+ let hyps = FApi. tc1_hyps tc in
349361 let env = FApi. tc1_env tc in
350362
351363 begin match side, (FApi. tc1_goal tc).f_node with
@@ -366,14 +378,27 @@ let process_change_stmt
366378
367379 let me, _ = EcLowPhlGoal. tc1_get_stmt side tc in
368380
369- let pos =
381+ let pos =
370382 let env = EcEnv.Memory. push_active_ss me env in
371383 EcTyping. trans_range1_or_insert ~memory: (fst me) env pos
372384 in
373385
374- let s = match side with
375- | Some side -> EcProofTyping. tc1_process_prhl_stmt tc side s
376- | None -> EcProofTyping. tc1_process_Xhl_stmt tc s
386+ (* Add the new variables *)
387+ let bindings =
388+ binds
389+ |> odfl []
390+ |> List. map (fun (xs , ty ) -> List. map (fun x -> (x, ty)) xs)
391+ |> List. flatten
392+ |> List. map (fun (x , ty ) ->
393+ let ty = EcProofTyping. process_type hyps ty in
394+ let x = Option. map EcLocation. unloc (EcLocation. unloc x) in
395+ EcAst. { ov_name = x; ov_type = ty; }
396+ )
377397 in
398+ let me, _ = EcMemory. bindall_fresh bindings me in
399+
400+ (* Process the given statement using the new bound variables *)
401+ let hyps = EcEnv.LDecl. push_active_ss me hyps in
402+ let s = EcProofTyping. process_stmt hyps s in
378403
379- t_change_stmt side pos s tc
404+ t_change_stmt side pos ~me s tc
0 commit comments