@@ -19,6 +19,7 @@ module Mp = EcPath.Mp
19
19
module Sid = EcIdent. Sid
20
20
module Mid = EcIdent. Mid
21
21
module TC = EcTypeClass
22
+ module Sint = EcMaps. Sint
22
23
module Mint = EcMaps. Mint
23
24
24
25
(* -------------------------------------------------------------------- *)
@@ -183,6 +184,7 @@ type preenv = {
183
184
env_rwbase : Sp .t Mip .t ;
184
185
env_atbase : atbase Msym .t ;
185
186
env_redbase : mredinfo ;
187
+ env_stdbase : setoid ;
186
188
env_ntbase : ntbase Mop .t ;
187
189
env_modlcs : Sid .t ; (* declared modules *)
188
190
env_item : theory_item list ; (* in reverse order *)
@@ -225,6 +227,13 @@ and atbase0 = path * [`Rigid | `Default]
225
227
226
228
and atbase = atbase0 list Mint. t
227
229
230
+ and setoid = setoid1 Mp. t
231
+
232
+ and setoid1 = {
233
+ spec : path ;
234
+ morphisms : (path Mint .t ) Mp .t ;
235
+ }
236
+
228
237
(* -------------------------------------------------------------------- *)
229
238
type env = preenv
230
239
@@ -311,6 +320,7 @@ let empty gstate =
311
320
env_rwbase = Mip. empty;
312
321
env_atbase = Msym. empty;
313
322
env_redbase = Mrd. empty;
323
+ env_stdbase = Mp. empty;
314
324
env_ntbase = Mop. empty;
315
325
env_modlcs = Sid. empty;
316
326
env_item = [] ;
@@ -611,7 +621,7 @@ module MC = struct
611
621
let mc = lookup_mc qn env in
612
622
let objs = odfl [] (mc |> omap (fun mc -> MMsym. all x (proj mc))) in
613
623
let _, objs =
614
- List. map_fold
624
+ List. fold_left_map
615
625
(fun ps ((p , _ ) as obj )->
616
626
if Sip. mem p ps
617
627
then (ps, None )
@@ -1019,7 +1029,7 @@ module MC = struct
1019
1029
in
1020
1030
1021
1031
let (mc, submcs) =
1022
- List. map_fold mc1_of_module
1032
+ List. fold_left_map mc1_of_module
1023
1033
(empty_mc
1024
1034
(if p2 = None then Some me.me_params else None ))
1025
1035
me.me_comps
@@ -1110,12 +1120,13 @@ module MC = struct
1110
1120
(add2mc _up_rwbase x (expath x) mc, None )
1111
1121
1112
1122
| Th_export _ | Th_addrw _ | Th_instance _
1113
- | Th_auto _ | Th_reduction _ ->
1123
+ | Th_auto _ | Th_reduction _ | Th_relation _
1124
+ | Th_morphism _ ->
1114
1125
(mc, None )
1115
1126
in
1116
1127
1117
1128
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
1119
1130
in
1120
1131
((x, mc), List. rev_pmap identity submcs)
1121
1132
@@ -1582,6 +1593,35 @@ module Auto = struct
1582
1593
Msym. values env.env_atbase |> List. map flatten_db |> List. flatten
1583
1594
end
1584
1595
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
+
1585
1625
(* -------------------------------------------------------------------- *)
1586
1626
module Fun = struct
1587
1627
type t = EcModules .function_
@@ -2975,6 +3015,17 @@ module Theory = struct
2975
3015
2976
3016
in bind_base_th for1
2977
3017
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
+
2978
3029
(* ------------------------------------------------------------------ *)
2979
3030
let bind_nt_th =
2980
3031
let for1 path base = function
@@ -3022,12 +3073,14 @@ module Theory = struct
3022
3073
let env_tc = bind_tc_th thname env.env_tc items in
3023
3074
let env_rwbase = bind_br_th thname env.env_rwbase items in
3024
3075
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
3025
3077
let env_ntbase = bind_nt_th thname env.env_ntbase items in
3026
3078
let env_redbase = bind_rd_th thname env.env_redbase items in
3027
3079
let env =
3028
3080
{ env with
3029
3081
env_tci ; env_tc ; env_rwbase;
3030
- env_atbase; env_ntbase; env_redbase; }
3082
+ env_atbase; env_stdbase; env_ntbase;
3083
+ env_redbase; }
3031
3084
in
3032
3085
add_restr_th thname env items
3033
3086
@@ -3088,7 +3141,12 @@ module Theory = struct
3088
3141
| Th_baserw (x , _ ) ->
3089
3142
MC. import_rwbase (xpath x) env
3090
3143
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 _ ->
3092
3150
env
3093
3151
3094
3152
in
@@ -3105,7 +3163,7 @@ module Theory = struct
3105
3163
(* ------------------------------------------------------------------ *)
3106
3164
let rec filter clears root cleared items =
3107
3165
snd_map (List. pmap identity)
3108
- (List. map_fold (filter1 clears root) cleared items)
3166
+ (List. fold_left_map (filter1 clears root) cleared items)
3109
3167
3110
3168
and filter_th clears root cleared items =
3111
3169
let mempty = List. exists (EcPath. p_equal root) clears in
@@ -3241,6 +3299,7 @@ module Theory = struct
3241
3299
env_tc = bind_tc_th thpath env.env_tc cth.cth_items;
3242
3300
env_rwbase = bind_br_th thpath env.env_rwbase cth.cth_items;
3243
3301
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;
3244
3303
env_ntbase = bind_nt_th thpath env.env_ntbase cth.cth_items;
3245
3304
env_redbase = bind_rd_th thpath env.env_redbase cth.cth_items;
3246
3305
env_thenvs = Mp. set_union env.env_thenvs compiled.compiled; }
@@ -3444,7 +3503,7 @@ module LDecl = struct
3444
3503
let do1 hyps s =
3445
3504
let id = fresh_id hyps s in
3446
3505
(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
3448
3507
3449
3508
(* ------------------------------------------------------------------ *)
3450
3509
type hyps = {
0 commit comments