@@ -19,6 +19,7 @@ module Mp = EcPath.Mp
1919module Sid = EcIdent. Sid
2020module Mid = EcIdent. Mid
2121module TC = EcTypeClass
22+ module Sint = EcMaps. Sint
2223module 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
226228and 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(* -------------------------------------------------------------------- *)
229238type 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
15831594end
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(* -------------------------------------------------------------------- *)
15861626module 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 = {
0 commit comments