Skip to content

Commit 6eddaa5

Browse files
committed
create TC univar
1 parent 45e0850 commit 6eddaa5

15 files changed

+129
-89
lines changed

src/ecAst.ml

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,11 @@ and ty_node =
5757
| Tfun of ty * ty
5858

5959
(* -------------------------------------------------------------------- *)
60-
and etyarg = ty * tcwitness list
60+
and etyarg = ty * tcwitness list
6161

6262
and tcwitness =
63+
| TCIUni of EcUid.uid
64+
6365
| TCIConcrete of {
6466
path: EcPath.path;
6567
etyargs: (ty * tcwitness list) list;
@@ -68,12 +70,11 @@ and tcwitness =
6870
| TCIAbstract of {
6971
support: [
7072
| `Var of EcIdent.t
71-
| `Univar of EcUid.uid
7273
| `Abs of EcPath.path
7374
];
7475
offset: int;
7576
}
76-
77+
7778
(* -------------------------------------------------------------------- *)
7879
and ovariable = {
7980
ov_name : EcSymbols.symbol option;
@@ -374,6 +375,9 @@ let lp_fv = function
374375
(* -------------------------------------------------------------------- *)
375376
let rec tcw_fv (tcw : tcwitness) =
376377
match tcw with
378+
| TCIUni _ ->
379+
Mid.empty
380+
377381
| TCIConcrete { etyargs } ->
378382
List.fold_left
379383
(fun fv (ty, tcws) -> fv_union fv (fv_union ty.ty_fv (tcws_fv tcws)))
@@ -398,6 +402,9 @@ let etyargs_fv (tyargs : etyarg list) =
398402
(* -------------------------------------------------------------------- *)
399403
let rec tcw_equal (tcw1 : tcwitness) (tcw2 : tcwitness) =
400404
match tcw1, tcw2 with
405+
| TCIUni uid1, TCIUni uid2 ->
406+
uid_equal uid1 uid2
407+
401408
| TCIConcrete tcw1, TCIConcrete tcw2 ->
402409
EcPath.p_equal tcw1.path tcw2.path
403410
&& List.all2 etyarg_equal tcw1.etyargs tcw2.etyargs
@@ -409,8 +416,6 @@ let rec tcw_equal (tcw1 : tcwitness) (tcw2 : tcwitness) =
409416
match support1, support2 with
410417
| `Var x1, `Var x2 ->
411418
EcIdent.id_equal x1 x2
412-
| `Univar u1, `Univar u2 ->
413-
uid_equal u1 u2
414419
| `Abs p1, `Abs p2 ->
415420
EcPath.p_equal p1 p2
416421
| _, _ -> false
@@ -426,6 +431,9 @@ and etyarg_equal ((ty1, tcws1) : etyarg) ((ty2, tcws2) : etyarg) =
426431
(* -------------------------------------------------------------------- *)
427432
let rec tcw_hash (tcw : tcwitness) =
428433
match tcw with
434+
| TCIUni uid ->
435+
Hashtbl.hash uid
436+
429437
| TCIConcrete tcw ->
430438
Why3.Hashcons.combine_list
431439
etyarg_hash
@@ -435,9 +443,6 @@ let rec tcw_hash (tcw : tcwitness) =
435443
| TCIAbstract { support = `Var tyvar; offset } ->
436444
Why3.Hashcons.combine (EcIdent.id_hash tyvar) offset
437445

438-
| TCIAbstract { support = `Univar uni; offset } ->
439-
Why3.Hashcons.combine (Hashtbl.hash uni) offset
440-
441446
| TCIAbstract { support = `Abs p; offset } ->
442447
Why3.Hashcons.combine (EcPath.p_hash p) offset
443448

src/ecAst.mli

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ and ty_node =
5656
and etyarg = ty * tcwitness list
5757

5858
and tcwitness =
59+
| TCIUni of EcUid.uid
60+
5961
| TCIConcrete of {
6062
path: EcPath.path;
6163
etyargs: (ty * tcwitness list) list;
@@ -64,7 +66,6 @@ and tcwitness =
6466
| TCIAbstract of {
6567
support: [
6668
| `Var of EcIdent.t
67-
| `Univar of EcUid.uid
6869
| `Abs of EcPath.path
6970
];
7071
offset: int;

src/ecCoreEqTest.ml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ and for_etyargs env (tyargs1 : etyarg list) (tyargs2 : etyarg list) =
6262

6363
and for_tcw env (tcw1 : tcwitness) (tcw2 : tcwitness) =
6464
match tcw1, tcw2 with
65+
| TCIUni uid1, TCIUni uid2 ->
66+
EcUid.uid_equal uid1 uid2
67+
6568
| TCIConcrete tcw1, TCIConcrete tcw2 ->
6669
EcPath.p_equal tcw1.path tcw2.path
6770
&& for_etyargs env tcw1.etyargs tcw2.etyargs
@@ -70,10 +73,6 @@ and for_tcw env (tcw1 : tcwitness) (tcw2 : tcwitness) =
7073
TCIAbstract { support = `Var v2; offset = o2 } ->
7174
EcIdent.id_equal v1 v2 && o1 = o2
7275

73-
| TCIAbstract { support = `Univar v1; offset = o1 },
74-
TCIAbstract { support = `Univar v2; offset = o2 } ->
75-
EcUid.uid_equal v1 v2 && o1 = o2
76-
7776
| TCIAbstract { support = `Abs p1; offset = o1 },
7877
TCIAbstract { support = `Abs p2; offset = o2 } ->
7978
EcPath.p_equal p1 p2 && o1 = o2

src/ecCoreSubst.ml

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ type mod_extra = {
1717
(* -------------------------------------------------------------------- *)
1818
type f_subst = {
1919
fs_freshen : bool; (* true means freshen locals *)
20-
fs_u : etyarg Muid.t;
20+
fs_u : ty Muid.t;
21+
fs_utc : tcwitness Muid.t;
2122
fs_v : etyarg Mid.t;
2223
fs_mod : EcPath.mpath Mid.t;
2324
fs_modex : mod_extra Mid.t;
@@ -47,22 +48,36 @@ let fv_Mid (type a)
4748
=
4849
Mid.fold (fun _ t s -> fv_union s (fv t)) m s
4950

51+
(* -------------------------------------------------------------------- *)
52+
type unisubst = {
53+
uvars : ty Muid.t;
54+
utcvars : tcwitness Muid.t;
55+
}
56+
57+
(* -------------------------------------------------------------------- *)
58+
let unisubst0 : unisubst = {
59+
uvars = Muid.empty; utcvars = Muid.empty;
60+
}
61+
5062
(* -------------------------------------------------------------------- *)
5163
let f_subst_init
52-
?(freshen=false)
53-
?(tu=Muid.empty)
54-
?(tv=Mid.empty)
55-
?(esloc=Mid.empty)
56-
() =
64+
?(freshen = false)
65+
?(tu = unisubst0)
66+
?(tv = Mid.empty)
67+
?(esloc = Mid.empty)
68+
()
69+
=
5770

5871
let fv = Mid.empty in
59-
let fv = Muid.fold (fun _ t s -> fv_union s (etyarg_fv t)) tu fv in
72+
let fv = Muid.fold (fun _ t s -> fv_union s (ty_fv t)) tu.uvars fv in
73+
let fv = Muid.fold (fun _ t s -> fv_union s (tcw_fv t)) tu.utcvars fv in
6074
let fv = fv_Mid etyarg_fv tv fv in
6175
let fv = fv_Mid e_fv esloc fv in
6276

6377
{
6478
fs_freshen = freshen;
65-
fs_u = tu;
79+
fs_u = tu.uvars;
80+
fs_utc = tu.utcvars;
6681
fs_v = tv;
6782
fs_mod = Mid.empty;
6883
fs_modex = Mid.empty;
@@ -166,7 +181,7 @@ let rec ty_subst (s : f_subst) (ty : ty) : ty =
166181

167182
| Tunivar id ->
168183
Muid.find_opt id s.fs_u
169-
|> Option.map (fun (ty, _) -> ty_subst s ty)
184+
|> Option.map (ty_subst s)
170185
|> Option.value ~default:ty
171186

172187
| Tvar id ->
@@ -190,7 +205,11 @@ let rec ty_subst (s : f_subst) (ty : ty) : ty =
190205
(* -------------------------------------------------------------------- *)
191206
and tcw_subst (s : f_subst) (tcw : tcwitness) : tcwitness =
192207
match tcw with
193-
| TCIConcrete ({ etyargs = etyargs0 } as rtcw) ->
208+
| TCIUni uid ->
209+
Muid.find_opt uid s.fs_utc
210+
|> Option.value ~default:tcw
211+
212+
| TCIConcrete ({ etyargs = etyargs0 } as rtcw) ->
194213
let etyargs = List.Smart.map (etyarg_subst s) etyargs0 in
195214
if etyargs ==(*phy*) etyargs0 then
196215
tcw
@@ -201,11 +220,6 @@ and tcw_subst (s : f_subst) (tcw : tcwitness) : tcwitness =
201220
|> Option.map (fun (_, tcws) -> List.nth tcws offset)
202221
|> Option.value ~default:tcw
203222

204-
| TCIAbstract { support = `Univar uni; offset } ->
205-
Muid.find_opt uni s.fs_u
206-
|> Option.map (fun (_, tcws) -> List.nth tcws offset)
207-
|> Option.value ~default:tcw
208-
209223
| TCIAbstract { support = `Abs _ } ->
210224
tcw
211225

@@ -768,13 +782,13 @@ end
768782
769783
(* -------------------------------------------------------------------- *)
770784
module Tuni = struct
771-
let subst (uidmap : etyarg Muid.t) : f_subst =
785+
let subst (uidmap : unisubst) : f_subst =
772786
f_subst_init ~tu:uidmap ()
773787
774-
let subst1 ((id, t) : uid * etyarg) : f_subst =
775-
subst (Muid.singleton id t)
788+
let subst1 ((id, t) : uid * ty) : f_subst =
789+
subst { unisubst0 with uvars = Muid.singleton id t }
776790
777-
let subst_dom (uidmap : etyarg Muid.t) (dom : dom) : dom =
791+
let subst_dom (uidmap : unisubst) (dom : dom) : dom =
778792
List.map (ty_subst (subst uidmap)) dom
779793
780794
let occurs (u : uid) : ty -> bool =

src/ecCoreSubst.mli

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,15 @@ type tx = before:form -> after:form -> form
1616
type 'a tx_substitute = ?tx:tx -> 'a substitute
1717
type 'a subst_binder = f_subst -> 'a -> f_subst * 'a
1818

19+
(* -------------------------------------------------------------------- *)
20+
type unisubst = {
21+
uvars : ty Muid.t; utcvars : tcwitness Muid.t;
22+
}
23+
1924
(* -------------------------------------------------------------------- *)
2025
val f_subst_init :
2126
?freshen:bool
22-
-> ?tu:etyarg Muid.t
27+
-> ?tu:unisubst
2328
-> ?tv:etyarg Mid.t
2429
-> ?esloc:expr Mid.t
2530
-> unit
@@ -28,9 +33,9 @@ val f_subst_init :
2833
(* -------------------------------------------------------------------- *)
2934
module Tuni : sig
3035
val univars : ty -> Suid.t
31-
val subst1 : (uid * etyarg) -> f_subst
32-
val subst : etyarg Muid.t -> f_subst
33-
val subst_dom : etyarg Muid.t -> dom -> dom
36+
val subst1 : (uid * ty) -> f_subst
37+
val subst : unisubst -> f_subst
38+
val subst_dom : unisubst -> dom -> dom
3439
val occurs : uid -> ty -> bool
3540
val fv : ty -> Suid.t
3641
end
@@ -63,7 +68,7 @@ module Fsubst : sig
6368

6469
val f_subst_init :
6570
?freshen:bool
66-
-> ?tu:etyarg Muid.t
71+
-> ?tu:unisubst
6772
-> ?tv:etyarg Mid.t
6873
-> ?esloc:expr Mid.t
6974
-> unit -> f_subst

src/ecHiNotations.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ let trans_abbrev_r (env : env) (at : pabbrev located) =
8383
if not (EcUnify.UniEnv.closed ue) then
8484
nterror gloc env NTE_TyNotClosed;
8585

86-
let ts = Tuni.subst (EcUnify.UniEnv.close ue) in
87-
let es = e_subst ts in
86+
let ts = Tuni.subst (EcUnify.UniEnv.close ue) in
87+
let es = e_subst ts in
8888
let body = es body in
8989
let codom = ty_subst ts codom in
9090
let xs = List.map (snd_map (ty_subst ts)) xs in

src/ecHiPredicates.ml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
open EcUtils
33
open EcSymbols
44
open EcLocation
5-
open EcTypes
65
open EcCoreSubst
76
open EcParsetree
87
open EcDecl
@@ -20,8 +19,8 @@ exception TransPredError of EcLocation.t * EcEnv.env * tperror
2019
let tperror loc env e = raise (TransPredError (loc, env, e))
2120

2221
(* -------------------------------------------------------------------- *)
23-
let close_pr_body (uni : etyarg EcUid.Muid.t) (body : prbody) =
24-
let fsubst = EcFol.Fsubst.f_subst_init ~tu:uni () in
22+
let close_pr_body (uidmap : unisubst) (body : prbody) =
23+
let fsubst = EcFol.Fsubst.f_subst_init ~tu:uidmap () in
2524
let tsubst = ty_subst fsubst in
2625

2726
match body with

src/ecMatching.mli

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
(* -------------------------------------------------------------------- *)
22
open EcMaps
3-
open EcUid
43
open EcIdent
54
open EcTypes
65
open EcModules
@@ -196,7 +195,7 @@ val f_match :
196195
-> unienv * mevmap
197196
-> form
198197
-> form
199-
-> unienv * (etyarg Muid.t) * mevmap
198+
-> unienv * unisubst * mevmap
200199

201200
(* -------------------------------------------------------------------- *)
202201
type ptnpos = private [`Select of int | `Sub of ptnpos] Mint.t

src/ecPrinting.ml

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ let pp_modtype1 (ppe : PPEnv.t) fmt mty =
561561

562562
(* -------------------------------------------------------------------- *)
563563
let pp_local (ppe : PPEnv.t) fmt x =
564-
Format.fprintf fmt "%s" (EcIdent.tostring x) (* (PPEnv.local_symb ppe x) *)
564+
Format.fprintf fmt "%s" (PPEnv.local_symb ppe x)
565565

566566
(* -------------------------------------------------------------------- *)
567567
let pp_local ?fv (ppe : PPEnv.t) fmt x =
@@ -947,6 +947,36 @@ let pp_opname fmt (nm, op) =
947947

948948
in EcSymbols.pp_qsymbol fmt (nm, op)
949949

950+
(* -------------------------------------------------------------------- *)
951+
let rec pp_etyarg (ppe : PPEnv.t) (fmt : Format.formatter) ((ty, tcws) : etyarg) =
952+
Format.fprintf fmt "%a[%a]" (pp_type ppe) ty (pp_tcws ppe) tcws
953+
954+
(* -------------------------------------------------------------------- *)
955+
and pp_etyargs (ppe : PPEnv.t) (fmt : Format.formatter) (etys : etyarg list) =
956+
Format.fprintf fmt "%a" (pp_list ",@ " (pp_etyarg ppe)) etys
957+
958+
(* -------------------------------------------------------------------- *)
959+
and pp_tcw (ppe : PPEnv.t) (fmt : Format.formatter) (tcw : tcwitness) =
960+
match tcw with
961+
| TCIUni uid ->
962+
Format.fprintf fmt "%a" (pp_tyunivar ppe) uid
963+
964+
| TCIConcrete { path; etyargs } ->
965+
Format.fprintf fmt "%a[%a]"
966+
pp_qsymbol (EcPath.toqsymbol path)
967+
(pp_etyargs ppe) etyargs
968+
969+
| TCIAbstract { support = `Var x; offset } ->
970+
Format.fprintf fmt "%a.`%d" (pp_tyvar ppe) x (offset + 1)
971+
972+
| TCIAbstract { support = `Abs path; offset } ->
973+
Format.fprintf fmt "%a.`%d" (pp_tyname ppe) path (offset + 1)
974+
975+
(* -------------------------------------------------------------------- *)
976+
and pp_tcws (ppe : PPEnv.t) (fmt : Format.formatter) (tcws : tcwitness list) =
977+
Format.fprintf fmt "%a" (pp_list ",@ " (pp_tcw ppe)) tcws
978+
979+
(* -------------------------------------------------------------------- *)
950980
let pp_opname_with_tvi
951981
(ppe : PPEnv.t)
952982
(fmt : Format.formatter)
@@ -958,8 +988,7 @@ let pp_opname_with_tvi
958988

959989
| Some tvi ->
960990
Format.fprintf fmt "%a<:%a>"
961-
pp_opname (nm, op)
962-
(pp_list ",@ " (pp_type ppe)) (List.fst tvi)
991+
pp_opname (nm, op) (pp_etyargs ppe) tvi
963992

964993
(* -------------------------------------------------------------------- *)
965994
let pp_opapp

src/ecReduction.ml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,9 @@ let reduce_tc (env : EcEnv.env) (p : path) (tys : etyarg list) =
676676
let tcw = as_seq1 tcw in
677677

678678
match tcw with
679+
| TCIUni _ ->
680+
None
681+
679682
| TCIAbstract _ ->
680683
None
681684

0 commit comments

Comments
 (0)