Skip to content

Commit 4d580f8

Browse files
committed
Make proof-local simplify hint databases visible to conversion
The named/local hint-database mechanism records the set of active databases per goal (g_simpl), but several tactics consulted user reduction rules through static reduction_info values (full_compat / full_red with an empty user_local), so rules activated with `hint +db.` were invisible to them. With this, `hint simplify in db : ...` + a proof-local `hint +db.` behaves exactly like the former global default-database hints.
1 parent 9ec8d13 commit 4d580f8

8 files changed

Lines changed: 62 additions & 28 deletions

File tree

src/ecCoreGoal.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,8 @@ module FApi = struct
420420
let tc_goal (tc : tcenv) = tc1_goal tc.tce_tcenv
421421
let tc_env (tc : tcenv) = tc1_env tc.tce_tcenv
422422

423+
let tc_simplify_context (tc : tcenv) = tc1_simplify_context tc.tce_tcenv
424+
423425
let tc_flat ?target (tc : tcenv) = tc1_flat ?target tc.tce_tcenv
424426
let tc_eflat ?target (tc : tcenv) = tc1_eflat ?target tc.tce_tcenv
425427
let tc_hyps ?target (tc : tcenv) = tc1_hyps ?target tc.tce_tcenv

src/ecCoreGoal.mli

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,7 @@ module FApi : sig
315315
val tc_flat : ?target:ident -> tcenv -> LDecl.hyps * form
316316
val tc_eflat : ?target:ident -> tcenv -> env * LDecl.hyps * form
317317
val tc_hyps : ?target:ident -> tcenv -> LDecl.hyps
318+
val tc_simplify_context : tcenv -> EcEnv.simplify_context
318319

319320
(* Accessors for focused goal parts (tcenv1) *)
320321
val tc1_handle : tcenv1 -> handle

src/ecHiGoal.ml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -986,15 +986,17 @@ let process_rewrite1_r ttenv ?target ri tc =
986986
let target = target |> omap (fst -| ((LDecl.hyp_by_name^~ hyps) -| unloc)) in
987987
let hyps = FApi.tc1_hyps ?target tc in
988988

989+
let simpl = FApi.tc1_simplify_context tc in
990+
989991
let ptenv, prw =
990992
match rwopt.match_ with
991993
| None ->
992-
PT.ptenv_of_penv hyps !!tc, None
994+
PT.ptenv_of_penv ~simpl hyps !!tc, None
993995

994996
| Some (RWM_Plain p) ->
995997
let (ps, ue), p = TTC.tc1_process_pattern tc p in
996998
let ev = MEV.of_idents (Mid.keys ps) `Form in
997-
(PT.ptenv !!tc hyps (ue, ev), Some (p, None))
999+
(PT.ptenv ~simpl !!tc hyps (ue, ev), Some (p, None))
9981000

9991001
| Some (RWM_Context (x, p)) ->
10001002
let ps = ref Mid.empty in
@@ -1005,7 +1007,7 @@ let process_rewrite1_r ttenv ?target ri tc =
10051007
let hyps = LDecl.add_local x (LD_var (xty, None)) hyps in
10061008
let p = EcTyping.trans_pattern (LDecl.toenv hyps) ps ue p in
10071009
let ev = MEV.of_idents (x :: Mid.keys !ps) `Form in
1008-
(PT.ptenv !!tc hyps (ue, ev), Some (p, Some (x, xty))) in
1010+
(PT.ptenv ~simpl !!tc hyps (ue, ev), Some (p, Some (x, xty))) in
10091011

10101012
let theside =
10111013
match rwopt.side, subs with

src/ecLowGoal.ml

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,9 @@ let t_cbv_with_info ?target (ri : reduction_info) (tc : tcenv1) =
387387
let t_cbv ?target ?(delta = `IfTransparent) ?(logic = Some `Full) (tc : tcenv1) =
388388
let ri = { nodelta with delta_p = fun _ -> delta } in
389389
let ri = { ri with logic } in
390+
(* thread the proof-local simplify overlay (hint +db, local rules) so
391+
that tactics built on [t_cbv] (done, progress, ...) see it *)
392+
let ri = { ri with user_local = FApi.tc1_simplify_context tc } in
390393
t_cbv_with_info ?target ri tc
391394

392395
(* -------------------------------------------------------------------- *)
@@ -398,6 +401,9 @@ let t_cbn_with_info ?target (ri : reduction_info) (tc : tcenv1) =
398401
let t_cbn ?target ?(delta = `IfTransparent) ?(logic = Some `Full) (tc : tcenv1) =
399402
let ri = { nodelta with delta_p = fun _ -> delta } in
400403
let ri = { ri with logic } in
404+
(* thread the proof-local simplify overlay (hint +db, local rules) so
405+
that tactics built on [t_cbn] (done, progress, ...) see it *)
406+
let ri = { ri with user_local = FApi.tc1_simplify_context tc } in
401407
t_cbn_with_info ?target ri tc
402408

403409
(* -------------------------------------------------------------------- *)
@@ -676,7 +682,12 @@ let tt_apply ?(cutsolver : cutsolver option) (pt : proofterm) (tc : tcenv) =
676682
let tc, (pt, ax, subgoals) =
677683
RApi.to_pure (fun tc -> LowApply.check_with_cutsolve `Elim pt (`Tc (tc, None))) tc in
678684
679-
if not (EcReduction.is_conv hyps ax concl) then begin
685+
(* conversion sees the proof-local simplify context (hint +db) *)
686+
let conv_ri =
687+
{ EcReduction.full_red with
688+
EcReduction.user_local = FApi.tc_simplify_context tc } in
689+
690+
if not (EcReduction.is_conv ~ri:conv_ri hyps ax concl) then begin
680691
(*
681692
let env = FApi.tc_env tc in
682693
let ppe = EcPrinting.PPEnv.ofenv env in
@@ -757,7 +768,11 @@ module Apply = struct
757768
758769
exception NoInstance of (bool * reason * PT.pt_env * (form * form))
759770
760-
let t_apply_bwd_r ?(ri = EcReduction.full_compat) ?(mode = fmdelta) ?(canview = true) pt (tc : tcenv1) =
771+
let t_apply_bwd_r ?ri ?(mode = fmdelta) ?(canview = true) pt (tc : tcenv1) =
772+
(* by default, conversion sees the proof-local simplify context *)
773+
let ri = ri |> odfl
774+
{ EcReduction.full_compat with
775+
EcReduction.user_local = pt.PT.ptev_env.PT.pte_lc } in
761776
let ((hyps, concl), pterr) = (FApi.tc1_flat tc, PT.copy pt.ptev_env) in
762777
763778
let noinstance ?(dpe = false) reason =
@@ -834,7 +849,7 @@ module Apply = struct
834849
let t_apply_bwd ?(ri : EcReduction.reduction_info option) ?mode ?canview pt (tc : tcenv1) =
835850
let hyps = FApi.tc1_hyps tc in
836851
let pt, ax = LowApply.check `Elim pt (`Hyps (hyps, !!tc)) in
837-
let ptenv = ptenv_of_penv hyps !!tc in
852+
let ptenv = ptenv_of_penv ~simpl:(FApi.tc1_simplify_context tc) hyps !!tc in
838853
let pt = { ptev_env = ptenv; ptev_pt = pt; ptev_ax = ax; } in
839854
t_apply_bwd_r ?ri ?mode ?canview pt tc
840855
@@ -1728,6 +1743,10 @@ let t_rewrite
17281743
?xconv ?keyed ?target ?(mode : rwmode option) ?(donot=false)
17291744
(pt : proofterm) (s, pos) (tc : tcenv1)
17301745
=
1746+
(* conversion checks below see the proof-local simplify context *)
1747+
let conv_ri =
1748+
{ EcReduction.full_compat with
1749+
EcReduction.user_local = FApi.tc1_simplify_context tc } in
17311750
let tc = RApi.rtcenv_of_tcenv1 tc in
17321751
let (hyps, tgfp) = RApi.tc_flat ?target tc in
17331752
let env = LDecl.toenv hyps in
@@ -1763,7 +1782,7 @@ let t_rewrite
17631782
in
17641783
17651784
let change f =
1766-
if not (EcReduction.is_conv hyps f left) then
1785+
if not (EcReduction.is_conv ~ri:conv_ri hyps f left) then
17671786
raise InvalidGoalShape;
17681787
right in
17691788

src/ecMatching.ml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -880,7 +880,7 @@ let fmnotation = {
880880

881881
(* -------------------------------------------------------------------- *)
882882
(* Rigid unification *)
883-
let f_match_core opts hyps (ue, ev) f1 f2 =
883+
let f_match_core ?(conv_ri = EcReduction.full_compat) opts hyps (ue, ev) f1 f2 =
884884
let ue = EcUnify.UniEnv.copy ue in
885885
let ev = ref ev in
886886

@@ -891,7 +891,7 @@ let f_match_core opts hyps (ue, ev) f1 f2 =
891891

892892
let conv =
893893
match opts.fm_conv with
894-
| true -> EcReduction.is_conv ~ri:EcReduction.full_compat hyps
894+
| true -> EcReduction.is_conv ~ri:conv_ri hyps
895895
| false -> EcReduction.is_alpha_eq hyps
896896
in
897897

@@ -1286,8 +1286,8 @@ let f_match_core opts hyps (ue, ev) f1 f2 =
12861286
doit (EcEnv.LDecl.toenv hyps) (Fsubst.f_subst_id, Mid.empty) f1 f2;
12871287
(ue, !ev)
12881288

1289-
let f_match opts hyps (ue, ev) f1 f2 =
1290-
let (ue, ev) = f_match_core opts hyps (ue, ev) f1 f2 in
1289+
let f_match ?conv_ri opts hyps (ue, ev) f1 f2 =
1290+
let (ue, ev) = f_match_core ?conv_ri opts hyps (ue, ev) f1 f2 in
12911291
if not (MEV.filled ev) then
12921292
raise MatchFailure;
12931293
let clue =

src/ecMatching.mli

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -371,15 +371,17 @@ val fmdelta : fmoptions
371371
val fmnotation : fmoptions
372372

373373
val f_match_core :
374-
fmoptions
374+
?conv_ri:EcReduction.reduction_info
375+
-> fmoptions
375376
-> EcEnv.LDecl.hyps
376377
-> unienv * mevmap
377378
-> form
378379
-> form
379380
-> unienv * mevmap
380381

381382
val f_match :
382-
fmoptions
383+
?conv_ri:EcReduction.reduction_info
384+
-> fmoptions
383385
-> EcEnv.LDecl.hyps
384386
-> unienv * mevmap
385387
-> form

src/ecProofTerm.ml

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ type pt_env = {
1919
pte_hy : LDecl.hyps;
2020
pte_ue : EcUnify.unienv;
2121
pte_ev : EcMatching.mevmap ref;
22+
pte_lc : EcEnv.simplify_context; (* proof-local simplify context *)
2223
}
2324

2425
type pt_ev = {
@@ -78,22 +79,24 @@ let argkind_of_ptarg arg : argkind =
7879
| PVASub _ -> `PTerm
7980

8081
(* -------------------------------------------------------------------- *)
81-
let ptenv pe hyps (ue, ev) =
82+
let ptenv ?(simpl = EcEnv.SimplifyContext.empty) pe hyps (ue, ev) =
8283
{ pte_pe = pe;
8384
pte_hy = hyps;
8485
pte_ue = EcUnify.UniEnv.copy ue;
85-
pte_ev = ref ev; }
86+
pte_ev = ref ev;
87+
pte_lc = simpl; }
8688

8789
(* -------------------------------------------------------------------- *)
8890
let copy pe =
89-
ptenv pe.pte_pe pe.pte_hy (pe.pte_ue, !(pe.pte_ev))
91+
ptenv ~simpl:pe.pte_lc pe.pte_pe pe.pte_hy (pe.pte_ue, !(pe.pte_ev))
9092

9193
(* -------------------------------------------------------------------- *)
92-
let ptenv_of_penv (hyps : LDecl.hyps) (pe : proofenv) =
94+
let ptenv_of_penv ?(simpl = EcEnv.SimplifyContext.empty) (hyps : LDecl.hyps) (pe : proofenv) =
9395
{ pte_pe = pe;
9496
pte_hy = hyps;
9597
pte_ue = PT.unienv_of_hyps hyps;
96-
pte_ev = ref EcMatching.MEV.empty; }
98+
pte_ev = ref EcMatching.MEV.empty;
99+
pte_lc = simpl; }
97100

98101
(* -------------------------------------------------------------------- *)
99102
let rec get_head_symbol (pt : pt_env) (f : form) =
@@ -272,17 +275,21 @@ let pattern_form ?name hyps ~ptn subject =
272275
let pf_form_match (pt : pt_env) ?mode ~ptn subject =
273276
let mode = mode |> odfl EcMatching.fmrigid in
274277

278+
(* conversion during matching sees the proof-local simplify context *)
279+
let conv_ri =
280+
{ EcReduction.full_compat with EcReduction.user_local = pt.pte_lc } in
281+
275282
try
276283
let (ue, ev) =
277-
EcMatching.f_match_core mode pt.pte_hy
284+
EcMatching.f_match_core ~conv_ri mode pt.pte_hy
278285
(pt.pte_ue, !(pt.pte_ev)) ptn subject
279286
in
280287
EcUnify.UniEnv.restore ~dst:pt.pte_ue ~src:ue;
281288
pt.pte_ev := ev
282289
with EcMatching.MatchFailure as exn ->
283290
(* FIXME: should we check for empty inters. with ecmap? *)
284291
if not mode.fm_conv ||
285-
not (EcReduction.is_conv ~ri:EcReduction.full_compat pt.pte_hy ptn subject) then
292+
not (EcReduction.is_conv ~ri:conv_ri pt.pte_hy ptn subject) then
286293
raise exn
287294

288295
(* -------------------------------------------------------------------- *)
@@ -883,37 +890,37 @@ let process_full_closed_pterm pe pf =
883890
let tc1_process_pterm_cut ~prcut tc ff =
884891
let pe = FApi.tc1_penv tc in
885892
let hyps = FApi.tc1_hyps tc in
886-
process_pterm_cut ~prcut (ptenv_of_penv hyps pe) ff
893+
process_pterm_cut ~prcut (ptenv_of_penv ~simpl:(FApi.tc1_simplify_context tc) hyps pe) ff
887894

888895
(* -------------------------------------------------------------------- *)
889896
let tc1_process_pterm tc ff =
890897
let pe = FApi.tc1_penv tc in
891898
let hyps = FApi.tc1_hyps tc in
892-
process_pterm (ptenv_of_penv hyps pe) ff
899+
process_pterm (ptenv_of_penv ~simpl:(FApi.tc1_simplify_context tc) hyps pe) ff
893900

894901
(* -------------------------------------------------------------------- *)
895902
let tc1_process_full_pterm_cut ~prcut (tc : tcenv1) (ff : 'a gppterm) =
896903
let pe = FApi.tc1_penv tc in
897904
let hyps = FApi.tc1_hyps tc in
898-
process_full_pterm_cut ~prcut (ptenv_of_penv hyps pe) ff
905+
process_full_pterm_cut ~prcut (ptenv_of_penv ~simpl:(FApi.tc1_simplify_context tc) hyps pe) ff
899906

900907
(* -------------------------------------------------------------------- *)
901908
let tc1_process_full_pterm ?implicits (tc : tcenv1) (ff : ppterm) =
902909
let pe = FApi.tc1_penv tc in
903910
let hyps = FApi.tc1_hyps tc in
904-
process_full_pterm ?implicits (ptenv_of_penv hyps pe) ff
911+
process_full_pterm ?implicits (ptenv_of_penv ~simpl:(FApi.tc1_simplify_context tc) hyps pe) ff
905912

906913
(* -------------------------------------------------------------------- *)
907914
let tc1_process_full_closed_pterm_cut ~prcut (tc : tcenv1) (ff : 'a gppterm) =
908915
let pe = FApi.tc1_penv tc in
909916
let hyps = FApi.tc1_hyps tc in
910-
process_full_closed_pterm_cut ~prcut (ptenv_of_penv hyps pe) ff
917+
process_full_closed_pterm_cut ~prcut (ptenv_of_penv ~simpl:(FApi.tc1_simplify_context tc) hyps pe) ff
911918

912919
(* -------------------------------------------------------------------- *)
913920
let tc1_process_full_closed_pterm (tc : tcenv1) (ff : ppterm) =
914921
let pe = FApi.tc1_penv tc in
915922
let hyps = FApi.tc1_hyps tc in
916-
process_full_closed_pterm (ptenv_of_penv hyps pe) ff
923+
process_full_closed_pterm (ptenv_of_penv ~simpl:(FApi.tc1_simplify_context tc) hyps pe) ff
917924

918925
(* -------------------------------------------------------------------- *)
919926
type prept = [

src/ecProofTerm.mli

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ type pt_env = {
3535
pte_hy : LDecl.hyps; (* local context *)
3636
pte_ue : EcUnify.unienv; (* unification env. *)
3737
pte_ev : mevmap ref; (* metavar env. *)
38+
pte_lc : EcEnv.simplify_context; (* proof-local simplify context *)
3839
}
3940

4041
type pt_ev = {
@@ -148,9 +149,9 @@ val concretize_e_form_gen : cptenv -> bindings -> form -> form
148149
val concretize_e_arg : cptenv -> pt_arg -> pt_arg
149150

150151
(* PTEnv constructor *)
151-
val ptenv_of_penv : LDecl.hyps -> proofenv -> pt_env
152+
val ptenv_of_penv : ?simpl:EcEnv.simplify_context -> LDecl.hyps -> proofenv -> pt_env
152153

153-
val ptenv : proofenv -> LDecl.hyps -> (EcUnify.unienv * mevmap) -> pt_env
154+
val ptenv : ?simpl:EcEnv.simplify_context -> proofenv -> LDecl.hyps -> (EcUnify.unienv * mevmap) -> pt_env
154155
val copy : pt_env -> pt_env
155156

156157
(* Proof-terms construction from components *)

0 commit comments

Comments
 (0)