@@ -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_albase : path Mp .t ; (* theory aliases *)
188190 env_modlcs : Sid .t ; (* declared modules *)
@@ -226,6 +228,13 @@ and atbase0 = path * [`Rigid | `Default]
226228
227229and atbase = atbase0 list Mint. t
228230
231+ and setoid = setoid1 Mp. t
232+
233+ and setoid1 = {
234+ spec : path ;
235+ morphisms : (path Mint .t ) Mp .t ;
236+ }
237+
229238(* -------------------------------------------------------------------- *)
230239type env = preenv
231240
@@ -312,6 +321,7 @@ let empty gstate =
312321 env_rwbase = Mip. empty;
313322 env_atbase = Msym. empty;
314323 env_redbase = Mrd. empty;
324+ env_stdbase = Mp. empty;
315325 env_ntbase = Mop. empty;
316326 env_albase = Mp. empty;
317327 env_modlcs = Sid. empty;
@@ -613,7 +623,7 @@ module MC = struct
613623 let mc = lookup_mc qn env in
614624 let objs = odfl [] (mc |> omap (fun mc -> MMsym. all x (proj mc))) in
615625 let _, objs =
616- List. map_fold
626+ List. fold_left_map
617627 (fun ps ((p , _ ) as obj )->
618628 if Sip. mem p ps
619629 then (ps, None )
@@ -1018,7 +1028,7 @@ module MC = struct
10181028 in
10191029
10201030 let (mc, submcs) =
1021- List. map_fold mc1_of_module
1031+ List. fold_left_map mc1_of_module
10221032 (empty_mc
10231033 (if p2 = None then Some me.me_params else None ))
10241034 me.me_comps
@@ -1113,12 +1123,13 @@ module MC = struct
11131123 (mc, None )
11141124
11151125 | Th_export _ | Th_addrw _ | Th_instance _
1116- | Th_auto _ | Th_reduction _ ->
1126+ | Th_auto _ | Th_reduction _ | Th_relation _
1127+ | Th_morphism _ ->
11171128 (mc, None )
11181129 in
11191130
11201131 let (mc, submcs) =
1121- List. map_fold mc1_of_theory (empty_mc None ) cth.cth_items
1132+ List. fold_left_map mc1_of_theory (empty_mc None ) cth.cth_items
11221133 in
11231134 ((x, mc), List. rev_pmap identity submcs)
11241135
@@ -1566,6 +1577,35 @@ module Auto = struct
15661577 Msym. values env.env_atbase |> List. map flatten_db |> List. flatten
15671578end
15681579
1580+ (* -------------------------------------------------------------------- *)
1581+ module Setoid = struct
1582+ type nonrec setoid1 = setoid1
1583+
1584+ let update_relation_db ((oppath , axpath ) : path * path ) (db : setoid ) =
1585+ Mp. add oppath { spec = axpath; morphisms = Mp. empty; } db
1586+
1587+ let add_relation ((oppath , axpath ) : path * path ) (env : env ) =
1588+ let item = mkitem ~import: true (Th_relation (oppath, axpath)) in
1589+ { env with
1590+ env_stdbase = update_relation_db (oppath, axpath) env.env_stdbase;
1591+ env_item = item :: env .env_item; }
1592+
1593+ let get_relation (env : env ) (oppath : path ) : setoid1 option =
1594+ Mp. find_opt oppath env.env_stdbase
1595+
1596+ let update_morphism_db ((rel , op , ax , pos ) : path * path * path * int ) (db : setoid ) =
1597+ Mp. change (fun db1 ->
1598+ Some { (oget db1) with morphisms =
1599+ Mp. change (fun m -> Some (Mint. add pos ax (odfl Mint. empty m))) op (oget db1).morphisms }
1600+ ) rel db
1601+
1602+ let add_morphism ((rel , op , ax , pos ) : path * path * path * int ) (env : env ) =
1603+ let item = mkitem ~import: true (Th_morphism (rel, op, ax, pos)) in
1604+ { env with
1605+ env_stdbase = update_morphism_db (rel, op, ax, pos) env.env_stdbase;
1606+ env_item = item :: env .env_item; }
1607+ end
1608+
15691609(* -------------------------------------------------------------------- *)
15701610module Fun = struct
15711611 type t = EcModules .function_
@@ -2974,6 +3014,17 @@ module Theory = struct
29743014
29753015 in bind_base_th for1
29763016
3017+ (* ------------------------------------------------------------------ *)
3018+ let bind_std_th =
3019+ let for1 _path db = function
3020+ | Th_relation r ->
3021+ Some (Setoid. update_relation_db r db)
3022+ | Th_morphism m ->
3023+ Some (Setoid. update_morphism_db m db)
3024+ | _ -> None
3025+
3026+ in bind_base_th for1
3027+
29773028 (* ------------------------------------------------------------------ *)
29783029 let bind_nt_th =
29793030 let for1 path base = function
@@ -3021,12 +3072,14 @@ module Theory = struct
30213072 let env_tc = bind_tc_th thname env.env_tc items in
30223073 let env_rwbase = bind_br_th thname env.env_rwbase items in
30233074 let env_atbase = bind_at_th thname env.env_atbase items in
3075+ let env_stdbase = bind_std_th thname env.env_stdbase items in
30243076 let env_ntbase = bind_nt_th thname env.env_ntbase items in
30253077 let env_redbase = bind_rd_th thname env.env_redbase items in
30263078 let env =
30273079 { env with
30283080 env_tci ; env_tc ; env_rwbase;
3029- env_atbase; env_ntbase; env_redbase; }
3081+ env_atbase; env_stdbase; env_ntbase;
3082+ env_redbase; }
30303083 in
30313084 add_restr_th thname env items
30323085
@@ -3086,7 +3139,12 @@ module Theory = struct
30863139 | Th_alias (name , path ) ->
30873140 rebind_alias name path env
30883141
3089- | Th_addrw _ | Th_instance _ | Th_auto _ | Th_reduction _ ->
3142+ | Th_addrw _
3143+ | Th_instance _
3144+ | Th_auto _
3145+ | Th_reduction _
3146+ | Th_relation _
3147+ | Th_morphism _ ->
30903148 env
30913149
30923150 in
@@ -3103,7 +3161,7 @@ module Theory = struct
31033161 (* ------------------------------------------------------------------ *)
31043162 let rec filter clears root cleared items =
31053163 snd_map (List. pmap identity)
3106- (List. map_fold (filter1 clears root) cleared items)
3164+ (List. fold_left_map (filter1 clears root) cleared items)
31073165
31083166 and filter_th clears root cleared items =
31093167 let mempty = List. exists (EcPath. p_equal root) clears in
@@ -3239,6 +3297,7 @@ module Theory = struct
32393297 env_tc = bind_tc_th thpath env.env_tc cth.cth_items;
32403298 env_rwbase = bind_br_th thpath env.env_rwbase cth.cth_items;
32413299 env_atbase = bind_at_th thpath env.env_atbase cth.cth_items;
3300+ env_stdbase = bind_std_th thpath env.env_stdbase cth.cth_items;
32423301 env_ntbase = bind_nt_th thpath env.env_ntbase cth.cth_items;
32433302 env_redbase = bind_rd_th thpath env.env_redbase cth.cth_items;
32443303 env_thenvs = Mp. set_union env.env_thenvs compiled.compiled; }
@@ -3442,7 +3501,7 @@ module LDecl = struct
34423501 let do1 hyps s =
34433502 let id = fresh_id hyps s in
34443503 (add_local id (LD_var (tbool, None )) hyps, id)
3445- in List. map_fold do1 hyps names
3504+ in List. fold_left_map do1 hyps names
34463505
34473506 (* ------------------------------------------------------------------ *)
34483507 type hyps = {
0 commit comments