@@ -236,13 +236,18 @@ let process_rewrite_at
236236 and produce the same values for everything observable afterwards;
237237 - the original program-logic goal with the selected range rewritten. *)
238238let t_change_stmt
239- (side : side option )
240- (pos : EcMatching.Position.codegap_range )
241- (s : stmt )
242- (tc : tcenv1 )
239+ (side : side option )
240+ (pos : EcMatching.Position.codegap_range )
241+ ?(me : memenv option )
242+ (s : stmt )
243+ (tc : tcenv1 )
243244=
244245 let env = FApi. tc1_env tc in
245- let me, stmt = EcLowPhlGoal. tc1_get_stmt side tc in
246+
247+ let me, stmt =
248+ let metc, stmt = EcLowPhlGoal. tc1_get_stmt side tc in
249+ (odfl metc me, stmt)
250+ in
246251
247252 let zpr, (_,stmt, epilog), _nmr =
248253 EcMatching.Zipper. zipper_and_split_of_cgap_range env pos stmt in
@@ -342,10 +347,12 @@ let t_change_stmt
342347(* -------------------------------------------------------------------- *)
343348let process_change_stmt
344349 (side : side option )
350+ (binds : ptybindings option )
345351 (pos : prange1_or_insert )
346352 (s : pstmt )
347353 (tc : tcenv1 )
348354=
355+ let hyps = FApi. tc1_hyps tc in
349356 let env = FApi. tc1_env tc in
350357
351358 begin match side, (FApi. tc1_goal tc).f_node with
@@ -366,14 +373,35 @@ let process_change_stmt
366373
367374 let me, _ = EcLowPhlGoal. tc1_get_stmt side tc in
368375
369- let pos =
376+ let pos =
370377 let env = EcEnv.Memory. push_active_ss me env in
371378 EcTyping. trans_range1_or_insert ~memory: (fst me) env pos
372379 in
373380
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
381+ (* Add the new variables *)
382+ let bindings =
383+ binds
384+ |> odfl []
385+ |> List. map (fun (xs , ty ) -> List. map (fun x -> (x, ty)) xs)
386+ |> List. flatten
387+ |> List. map (fun (x , ty ) ->
388+ let ty = EcProofTyping. process_type hyps ty in
389+ let x = Option. map EcLocation. unloc (EcLocation. unloc x) in
390+ EcAst. { ov_name = x; ov_type = ty; }
391+ )
392+ in
393+ let me, _ = EcMemory. bindall_fresh bindings me in
394+
395+ (* Process the given statement using the new bound variables *)
396+ let env = EcEnv.Memory. push_active_ss me env in
397+ let s =
398+ let ue = EcProofTyping. unienv_of_hyps hyps in
399+ let s = EcTyping. transstmt env ue s in
400+
401+ assert (EcUnify.UniEnv. closed ue);
402+
403+ let sb = EcCoreSubst.Tuni. subst (EcUnify.UniEnv. close ue) in
404+ EcCoreSubst. s_subst sb s
377405 in
378406
379- t_change_stmt side pos s tc
407+ t_change_stmt side pos ~me s tc
0 commit comments