Skip to content

Commit 9073d88

Browse files
committed
setoid rewrite
1 parent c033d6c commit 9073d88

33 files changed

+930
-207
lines changed

src/ecCommands.ml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,14 @@ and process_addrw scope (local, base, names) =
682682
and process_reduction scope name =
683683
EcScope.Reduction.add_reduction scope name
684684

685+
(* -------------------------------------------------------------------- *)
686+
and process_relation (scope : EcScope.scope) (rel : prelation) =
687+
EcScope.Setoid.add_relation scope rel
688+
689+
(* -------------------------------------------------------------------- *)
690+
and process_morphism (scope : EcScope.scope) (mph : pmorphism) =
691+
EcScope.Setoid.add_morphism scope mph
692+
685693
(* -------------------------------------------------------------------- *)
686694
and process_hint scope hint =
687695
EcScope.Auto.add_hint scope hint
@@ -783,6 +791,8 @@ and process (ld : Loader.loader) (scope : EcScope.scope) g =
783791
| Goption opt -> `Fct (fun scope -> process_option scope opt)
784792
| Gaddrw hint -> `Fct (fun scope -> process_addrw scope hint)
785793
| Greduction red -> `Fct (fun scope -> process_reduction scope red)
794+
| Grelation rel -> `Fct (fun scope -> process_relation scope rel)
795+
| Gmorphism mph -> `Fct (fun scope -> process_morphism scope mph)
786796
| Ghint hint -> `Fct (fun scope -> process_hint scope hint)
787797
| GdumpWhy3 file -> `Fct (fun scope -> process_dump_why3 scope file)
788798
with

src/ecCoreGoal.ml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ module FApi = struct
508508

509509
(* ------------------------------------------------------------------ *)
510510
let xmutate (tc : tcenv) (vx : 'a) (fp : form list) =
511-
let (tc, hds) = List.map_fold (fun tc fp -> newgoal tc fp) tc fp in
511+
let (tc, hds) = List.fold_left_map (fun tc fp -> newgoal tc fp) tc fp in
512512
close tc (VExtern (vx, hds))
513513

514514
(* ------------------------------------------------------------------ *)
@@ -518,7 +518,7 @@ module FApi = struct
518518
(* ------------------------------------------------------------------ *)
519519
let xmutate_hyps (tc : tcenv) (vx : 'a) subgoals =
520520
let (tc, hds) =
521-
List.map_fold
521+
List.fold_left_map
522522
(fun tc (hyps, fp) -> newgoal tc ~hyps fp)
523523
tc subgoals
524524
in
@@ -564,11 +564,11 @@ module FApi = struct
564564

565565
(* ------------------------------------------------------------------ *)
566566
let on_sub1i_goals (tt : int -> backward) (hds : handle list) (pe : proofenv) =
567-
let do1 i pe hd =
567+
let do1 pe i hd =
568568
let tc = tt i (tcenv1_of_penv hd pe) in
569569
assert (tc.tce_tcenv.tce_ctxt = []);
570570
(tc_penv tc, tc_opened tc) in
571-
List.mapi_fold do1 pe hds
571+
List.fold_left_mapi do1 pe hds
572572

573573
(* ------------------------------------------------------------------ *)
574574
let on_sub1_goals (tt : backward) (hds : handle list) (pe : proofenv) =
@@ -578,11 +578,11 @@ module FApi = struct
578578
let on_sub1i_map_goals
579579
(tt : int -> tcenv1 -> 'a * tcenv) (hds : handle list) (pe : proofenv)
580580
=
581-
let do1 i pe hd =
581+
let do1 pe i hd =
582582
let data, tc = tt i (tcenv1_of_penv hd pe) in
583583
assert (tc.tce_tcenv.tce_ctxt = []);
584584
(tc_penv tc, (tc_opened tc, data)) in
585-
List.mapi_fold do1 pe hds
585+
List.fold_left_mapi do1 pe hds
586586

587587
(* ------------------------------------------------------------------ *)
588588
let on_sub1_map_goals

src/ecCoreSubst.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,7 @@ module Fsubst = struct
600600

601601
(* ------------------------------------------------------------------ *)
602602
and add_bindings (s : f_subst) : bindings -> f_subst * bindings =
603-
List.map_fold add_binding s
603+
List.fold_left_map add_binding s
604604

605605
(* ------------------------------------------------------------------ *)
606606
and add_mod_params (s : f_subst) (params : _) =

src/ecEnv.ml

Lines changed: 67 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ module Mp = EcPath.Mp
1919
module Sid = EcIdent.Sid
2020
module Mid = EcIdent.Mid
2121
module TC = EcTypeClass
22+
module Sint = EcMaps.Sint
2223
module Mint = EcMaps.Mint
2324

2425
(* -------------------------------------------------------------------- *)
@@ -183,6 +184,7 @@ type preenv = {
183184
env_rwbase : Sp.t Mip.t;
184185
env_atbase : atbase Msym.t;
185186
env_redbase : mredinfo;
187+
env_stdbase : setoid;
186188
env_ntbase : ntbase Mop.t;
187189
env_modlcs : Sid.t; (* declared modules *)
188190
env_item : theory_item list; (* in reverse order *)
@@ -225,6 +227,13 @@ and atbase0 = path * [`Rigid | `Default]
225227

226228
and atbase = atbase0 list Mint.t
227229

230+
and setoid = setoid1 Mp.t
231+
232+
and setoid1 = {
233+
spec : path;
234+
morphisms : (path Mint.t) Mp.t;
235+
}
236+
228237
(* -------------------------------------------------------------------- *)
229238
type env = preenv
230239

@@ -311,6 +320,7 @@ let empty gstate =
311320
env_rwbase = Mip.empty;
312321
env_atbase = Msym.empty;
313322
env_redbase = Mrd.empty;
323+
env_stdbase = Mp.empty;
314324
env_ntbase = Mop.empty;
315325
env_modlcs = Sid.empty;
316326
env_item = [];
@@ -611,7 +621,7 @@ module MC = struct
611621
let mc = lookup_mc qn env in
612622
let objs = odfl [] (mc |> omap (fun mc -> MMsym.all x (proj mc))) in
613623
let _, objs =
614-
List.map_fold
624+
List.fold_left_map
615625
(fun ps ((p, _) as obj)->
616626
if Sip.mem p ps
617627
then (ps, None)
@@ -1019,7 +1029,7 @@ module MC = struct
10191029
in
10201030

10211031
let (mc, submcs) =
1022-
List.map_fold mc1_of_module
1032+
List.fold_left_map mc1_of_module
10231033
(empty_mc
10241034
(if p2 = None then Some me.me_params else None))
10251035
me.me_comps
@@ -1110,12 +1120,13 @@ module MC = struct
11101120
(add2mc _up_rwbase x (expath x) mc, None)
11111121

11121122
| Th_export _ | Th_addrw _ | Th_instance _
1113-
| Th_auto _ | Th_reduction _ ->
1123+
| Th_auto _ | Th_reduction _ | Th_relation _
1124+
| Th_morphism _ ->
11141125
(mc, None)
11151126
in
11161127

11171128
let (mc, submcs) =
1118-
List.map_fold mc1_of_theory (empty_mc None) cth.cth_items
1129+
List.fold_left_map mc1_of_theory (empty_mc None) cth.cth_items
11191130
in
11201131
((x, mc), List.rev_pmap identity submcs)
11211132

@@ -1582,6 +1593,35 @@ module Auto = struct
15821593
Msym.values env.env_atbase |> List.map flatten_db |> List.flatten
15831594
end
15841595
1596+
(* -------------------------------------------------------------------- *)
1597+
module Setoid = struct
1598+
type nonrec setoid1 = setoid1
1599+
1600+
let update_relation_db ((oppath, axpath) : path * path) (db : setoid) =
1601+
Mp.add oppath { spec = axpath; morphisms = Mp.empty; } db
1602+
1603+
let add_relation ((oppath, axpath) : path * path) (env : env) =
1604+
let item = mkitem import0 (Th_relation (oppath, axpath)) in
1605+
{ env with
1606+
env_stdbase = update_relation_db (oppath, axpath) env.env_stdbase;
1607+
env_item = item :: env.env_item; }
1608+
1609+
let get_relation (env : env) (oppath : path) : setoid1 option =
1610+
Mp.find_opt oppath env.env_stdbase
1611+
1612+
let update_morphism_db ((rel, op, ax, pos) : path * path * path * int) (db : setoid) =
1613+
Mp.change (fun db1 ->
1614+
Some { (oget db1) with morphisms =
1615+
Mp.change (fun m -> Some (Mint.add pos ax (odfl Mint.empty m))) op (oget db1).morphisms }
1616+
) rel db
1617+
1618+
let add_morphism ((rel, op, ax, pos) : path * path * path * int) (env : env) =
1619+
let item = mkitem import0 (Th_morphism (rel, op, ax, pos)) in
1620+
{ env with
1621+
env_stdbase = update_morphism_db (rel, op, ax, pos) env.env_stdbase;
1622+
env_item = item :: env.env_item; }
1623+
end
1624+
15851625
(* -------------------------------------------------------------------- *)
15861626
module Fun = struct
15871627
type t = EcModules.function_
@@ -2975,6 +3015,17 @@ module Theory = struct
29753015
29763016
in bind_base_th for1
29773017
3018+
(* ------------------------------------------------------------------ *)
3019+
let bind_std_th =
3020+
let for1 _path db = function
3021+
| Th_relation r ->
3022+
Some (Setoid.update_relation_db r db)
3023+
| Th_morphism m ->
3024+
Some (Setoid.update_morphism_db m db)
3025+
| _ -> None
3026+
3027+
in bind_base_th for1
3028+
29783029
(* ------------------------------------------------------------------ *)
29793030
let bind_nt_th =
29803031
let for1 path base = function
@@ -3022,12 +3073,14 @@ module Theory = struct
30223073
let env_tc = bind_tc_th thname env.env_tc items in
30233074
let env_rwbase = bind_br_th thname env.env_rwbase items in
30243075
let env_atbase = bind_at_th thname env.env_atbase items in
3076+
let env_stdbase = bind_std_th thname env.env_stdbase items in
30253077
let env_ntbase = bind_nt_th thname env.env_ntbase items in
30263078
let env_redbase = bind_rd_th thname env.env_redbase items in
30273079
let env =
30283080
{ env with
30293081
env_tci ; env_tc ; env_rwbase;
3030-
env_atbase; env_ntbase; env_redbase; }
3082+
env_atbase; env_stdbase; env_ntbase;
3083+
env_redbase; }
30313084
in
30323085
add_restr_th thname env items
30333086
@@ -3088,7 +3141,12 @@ module Theory = struct
30883141
| Th_baserw (x, _) ->
30893142
MC.import_rwbase (xpath x) env
30903143
3091-
| Th_addrw _ | Th_instance _ | Th_auto _ | Th_reduction _ ->
3144+
| Th_addrw _
3145+
| Th_instance _
3146+
| Th_auto _
3147+
| Th_reduction _
3148+
| Th_relation _
3149+
| Th_morphism _ ->
30923150
env
30933151
30943152
in
@@ -3105,7 +3163,7 @@ module Theory = struct
31053163
(* ------------------------------------------------------------------ *)
31063164
let rec filter clears root cleared items =
31073165
snd_map (List.pmap identity)
3108-
(List.map_fold (filter1 clears root) cleared items)
3166+
(List.fold_left_map (filter1 clears root) cleared items)
31093167
31103168
and filter_th clears root cleared items =
31113169
let mempty = List.exists (EcPath.p_equal root) clears in
@@ -3241,6 +3299,7 @@ module Theory = struct
32413299
env_tc = bind_tc_th thpath env.env_tc cth.cth_items;
32423300
env_rwbase = bind_br_th thpath env.env_rwbase cth.cth_items;
32433301
env_atbase = bind_at_th thpath env.env_atbase cth.cth_items;
3302+
env_stdbase = bind_std_th thpath env.env_stdbase cth.cth_items;
32443303
env_ntbase = bind_nt_th thpath env.env_ntbase cth.cth_items;
32453304
env_redbase = bind_rd_th thpath env.env_redbase cth.cth_items;
32463305
env_thenvs = Mp.set_union env.env_thenvs compiled.compiled; }
@@ -3444,7 +3503,7 @@ module LDecl = struct
34443503
let do1 hyps s =
34453504
let id = fresh_id hyps s in
34463505
(add_local id (LD_var (tbool, None)) hyps, id)
3447-
in List.map_fold do1 hyps names
3506+
in List.fold_left_map do1 hyps names
34483507
34493508
(* ------------------------------------------------------------------ *)
34503509
type hyps = {

src/ecEnv.mli

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,21 @@ module Reduction : sig
413413
val get : topsym -> env -> rule list
414414
end
415415

416+
(* -------------------------------------------------------------------- *)
417+
type setoid1 = {
418+
spec : path;
419+
morphisms : (path EcMaps.Mint.t) Mp.t;
420+
}
421+
422+
module Setoid : sig
423+
type nonrec setoid1 = setoid1
424+
425+
val add_relation : path * path -> env -> env
426+
val get_relation : env -> path -> setoid1 option
427+
428+
val add_morphism : path * path * path * int -> env -> env
429+
end
430+
416431
(* -------------------------------------------------------------------- *)
417432
module Auto : sig
418433
type base0 = path * [`Rigid | `Default]

0 commit comments

Comments
 (0)