Skip to content

Commit 70089d8

Browse files
committed
[refold]: allow rigid unification
Syntax: `rewrite -/~(pattern)`
1 parent 3d043bb commit 70089d8

5 files changed

Lines changed: 31 additions & 22 deletions

File tree

src/ecHiGoal.ml

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -598,9 +598,10 @@ let process_rewrite1_core ?mode ?(close = true) ?target (s, p, o) pt tc =
598598
tc_error !!tc "r-pattern does not match the rewriting rule"
599599

600600
(* -------------------------------------------------------------------- *)
601-
let process_delta ~und_delta ?target (s, o, p) tc =
601+
let process_delta ~und_delta ?(rigid = false) ?target (s, o, p) tc =
602602
let env, hyps, concl = FApi.tc1_eflat tc in
603603
let o = norm_rwocc o in
604+
let occmode = if rigid then Some om_rigid else None in
604605

605606
let idtg, target =
606607
match target with
@@ -668,7 +669,7 @@ let process_delta ~und_delta ?target (s, o, p) tc =
668669
match s with
669670
| `LtoR -> begin
670671
let matches =
671-
try ignore (PT.pf_find_occurence ptenv ~ptn:p target); true
672+
try ignore (PT.pf_find_occurence ptenv ?occmode ~ptn:p target); true
672673
with PT.FindOccFailure _ -> false
673674
in
674675

@@ -729,23 +730,26 @@ let process_delta ~und_delta ?target (s, o, p) tc =
729730
with EcEnv.NotReducible -> fp
730731
in
731732

732-
let matches =
733-
try ignore (PT.pf_find_occurence ptenv ~ptn:fp target); true
734-
with PT.FindOccFailure _ -> false
735-
in
733+
begin
734+
match PT.pf_find_occurence ?occmode ptenv ~ptn:fp target with
735+
| (_, occmode) ->
736+
let p = concretize_form ptenv p in
737+
let fp = concretize_form ptenv fp in
738+
let cpos =
739+
try
740+
FPosition.select_form
741+
~xconv:(if rigid then `AlphaEq else `Conv)
742+
~keyed:occmode.k_keyed
743+
hyps o fp target
744+
with InvalidOccurence ->
745+
tc_error !!tc "invalid occurences selector" in
736746

737-
if matches then begin
738-
let p = concretize_form ptenv p in
739-
let fp = concretize_form ptenv fp in
740-
let cpos =
741-
try FPosition.select_form hyps o fp target
742-
with InvalidOccurence ->
743-
tc_error !!tc "invalid occurences selector"
744-
in
747+
let target = FPosition.map cpos (fun _ -> p) target in
748+
t_change ~ri ?target:idtg target tc
745749

746-
let target = FPosition.map cpos (fun _ -> p) target in
747-
t_change ~ri ?target:idtg target tc
748-
end else t_id tc
750+
| exception (PT.FindOccFailure _) ->
751+
t_id tc
752+
end
749753

750754
(* -------------------------------------------------------------------- *)
751755
let process_rewrite1_r ttenv ?target ri tc =
@@ -768,11 +772,11 @@ let process_rewrite1_r ttenv ?target ri tc =
768772
let target = target |> omap (fst -| ((LDecl.hyp_by_name^~ hyps) -| unloc)) in
769773
t_simplify_lg ?target ~delta:`IfApplied (ttenv, logic) tc
770774

771-
| RWDelta ((s, r, o, px), p) -> begin
775+
| RWDelta (rigid, (s, r, o, px), p) -> begin
772776
if Option.is_some px then
773777
tc_error !!tc "cannot use pattern selection in delta-rewrite rules";
774778

775-
let do1 tc = process_delta ~und_delta ?target (s, o, p) tc in
779+
let do1 tc = process_delta ~und_delta ~rigid ?target (s, o, p) tc in
776780

777781
match r with
778782
| None -> do1 tc

src/ecHiGoal.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ val process_clear : clear_info -> backward
7575
val process_smt : ?loc:EcLocation.t -> ttenv -> pprover_infos option -> backward
7676
val process_coq : loc:EcLocation.t -> name:string -> ttenv -> EcProvers.coq_mode option -> pprover_infos -> backward
7777
val process_apply : implicits:bool -> apply_t * prevert option -> backward
78-
val process_delta : und_delta:bool -> ?target:psymbol -> (rwside * rwocc * pformula) -> backward
78+
val process_delta : und_delta:bool -> ?rigid:bool -> ?target:psymbol -> (rwside * rwocc * pformula) -> backward
7979
val process_rewrite : ttenv -> ?target:psymbol -> rwarg list -> backward
8080
val process_subst : pformula list -> backward
8181
val process_cut : ?mode:cutmode -> engine -> ttenv -> cut_t -> backward

src/ecLexer.mll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,7 @@ rule main = parse
422422
| "<@" { [LEAT ] }
423423
| ":~" { [COLONTILD ] }
424424

425+
| "/~" { [SLASHTILD ] }
425426
| "/~=" { [SLASHTILDEQ ] }
426427
| "//~=" { [SLASHSLASHTILDEQ] }
427428

src/ecParser.mly

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,7 @@
563563
%token SLASHGT
564564
%token SLASHSHARP
565565
%token SLASHSLASHGT
566+
%token SLASHTILD
566567
%token SLASHTILDEQ
567568
%token SLASHSLASH
568569
%token SLASHSLASHEQ
@@ -2390,7 +2391,10 @@ rwarg1:
23902391
{ RWRw ((s, r, o, p), fp) }
23912392

23922393
| s=rwside r=rwrepeat? o=rwocc? SLASH x=sform_h %prec prec_tactic
2393-
{ RWDelta ((s, r, o, None), x); }
2394+
{ RWDelta (false, (s, r, o, None), x); }
2395+
2396+
| s=rwside r=rwrepeat? o=rwocc? SLASHTILD x=sform_h %prec prec_tactic
2397+
{ RWDelta (true, (s, r, o, None), x); }
23942398

23952399
| PR s=bracket(rwpr_arg)
23962400
{ RWPr s }

src/ecParsetree.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -860,7 +860,7 @@ type rwarg = (tfocus located) option * rwarg1 located
860860

861861
and rwarg1 =
862862
| RWSimpl of [`Default | `Variant]
863-
| RWDelta of (rwoptions * pformula)
863+
| RWDelta of (bool * rwoptions * pformula)
864864
| RWRw of (rwoptions * (rwside * ppterm) list)
865865
| RWPr of (psymbol * pformula option)
866866
| RWDone of [`Default | `Variant] option

0 commit comments

Comments
 (0)