Skip to content

Commit ab3c768

Browse files
Gustavo2622strub
andcommitted
Remove prototype type-classes implementation.
Co-authored-by: Gustavo Delerue <gxdelerue@proton.me> Co-authored-by: Pierre-Yves Strub <pierre-yves@strub.nu>
1 parent a0bf172 commit ab3c768

29 files changed

Lines changed: 266 additions & 554 deletions

src/ecCallbyValue.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ and try_reduce_fixdef
300300

301301
let body = EcFol.form_of_expr body in
302302
let body =
303-
Tvar.f_subst ~freshen:true (List.map fst op.EcDecl.op_tparams) tys body in
303+
Tvar.f_subst ~freshen:true op.EcDecl.op_tparams tys body in
304304

305305
Some (cbv st subst body (Args.create ty eargs))
306306

src/ecCommands.ml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -418,13 +418,6 @@ and process_subtype (scope : EcScope.scope) (subtype : psubtype located) =
418418
EcScope.notify scope `Info "added subtype: `%s'" (unloc subtype.pl_desc.pst_name);
419419
scope
420420

421-
(* -------------------------------------------------------------------- *)
422-
and process_typeclass (scope : EcScope.scope) (tcd : ptypeclass located) =
423-
EcScope.check_state `InTop "type class" scope;
424-
let scope = EcScope.Ty.add_class scope tcd in
425-
EcScope.notify scope `Info "added type class: `%s'" (unloc tcd.pl_desc.ptc_name);
426-
scope
427-
428421
(* -------------------------------------------------------------------- *)
429422
and process_tycinst (scope : EcScope.scope) (tci : ptycinstance located) =
430423
EcScope.check_state `InTop "type class instance" scope;
@@ -758,7 +751,6 @@ and process ?(src : string option) (ld : Loader.loader) (scope : EcScope.scope)
758751
match g.pl_desc with
759752
| Gtype t -> `Fct (fun scope -> process_types ?src scope (List.map (mk_loc loc) t))
760753
| Gsubtype t -> `Fct (fun scope -> process_subtype scope (mk_loc loc t))
761-
| Gtypeclass t -> `Fct (fun scope -> process_typeclass scope (mk_loc loc t))
762754
| Gtycinstance t -> `Fct (fun scope -> process_tycinst scope (mk_loc loc t))
763755
| Gmodule m -> `Fct (fun scope -> process_module ?src scope m)
764756
| Ginterface i -> `Fct (fun scope -> process_interface ?src scope i)

src/ecDecl.ml

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ module Ssym = EcSymbols.Ssym
1111
module CS = EcCoreSubst
1212

1313
(* -------------------------------------------------------------------- *)
14-
type ty_param = EcIdent.t * EcPath.Sp.t
14+
type ty_param = EcIdent.t
1515
type ty_params = ty_param list
1616
type ty_pctor = [ `Int of int | `Named of ty_params ]
1717

@@ -29,7 +29,7 @@ type ty_dtype = {
2929

3030
type ty_body =
3131
| Concrete of EcTypes.ty
32-
| Abstract of Sp.t
32+
| Abstract
3333
| Datatype of ty_dtype
3434
| Record of ty_record
3535

@@ -44,7 +44,7 @@ let tydecl_as_concrete (td : tydecl) =
4444
match td.tyd_type with Concrete x -> Some x | _ -> None
4545

4646
let tydecl_as_abstract (td : tydecl) =
47-
match td.tyd_type with Abstract x -> Some x | _ -> None
47+
match td.tyd_type with Abstract -> Some () | _ -> None
4848

4949
let tydecl_as_datatype (td : tydecl) =
5050
match td.tyd_type with Datatype x -> Some x | _ -> None
@@ -53,23 +53,23 @@ let tydecl_as_record (td : tydecl) =
5353
match td.tyd_type with Record (x, y) -> Some (x, y) | _ -> None
5454

5555
(* -------------------------------------------------------------------- *)
56-
let abs_tydecl ?(tc = Sp.empty) ?(params = `Int 0) lc =
56+
let abs_tydecl ?(params = `Int 0) lc =
5757
let params =
5858
match params with
5959
| `Named params ->
6060
params
6161
| `Int n ->
6262
let fmt = fun x -> Printf.sprintf "'%s" x in
6363
List.map
64-
(fun x -> (EcIdent.create x, Sp.empty))
64+
(fun x -> (EcIdent.create x))
6565
(EcUid.NameGen.bulk ~fmt n)
6666
in
6767

68-
{ tyd_params = params; tyd_type = Abstract tc; tyd_loca = lc; }
68+
{ tyd_params = params; tyd_type = Abstract; tyd_loca = lc; }
6969

7070
(* -------------------------------------------------------------------- *)
7171
let ty_instantiate (params : ty_params) (args : ty list) (ty : ty) =
72-
let subst = CS.Tvar.init (List.map fst params) args in
72+
let subst = CS.Tvar.init params args in
7373
CS.Tvar.subst subst ty
7474

7575
(* -------------------------------------------------------------------- *)
@@ -254,12 +254,19 @@ let operator_as_prind (op : operator) =
254254
| _ -> assert false
255255

256256
(* -------------------------------------------------------------------- *)
257-
let axiomatized_op ?(nargs = 0) ?(nosmt = false) path (tparams, axbd) lc =
257+
let axiomatized_op
258+
?(nargs = 0)
259+
?(nosmt = false)
260+
(path : EcPath.path)
261+
((tparams, axbd) : ty_params * form)
262+
(lc : locality)
263+
: axiom
264+
=
258265
let axbd, axpm =
259-
let bdpm = List.map fst tparams in
266+
let bdpm = tparams in
260267
let axpm = List.map EcIdent.fresh bdpm in
261268
(CS.Tvar.f_subst ~freshen:true bdpm (List.map EcTypes.tvar axpm) axbd,
262-
List.combine axpm (List.map snd tparams))
269+
axpm)
263270
in
264271

265272
let args, axbd =
@@ -271,7 +278,7 @@ let axiomatized_op ?(nargs = 0) ?(nosmt = false) path (tparams, axbd) lc =
271278
in
272279

273280
let opargs = List.map (fun (x, ty) -> f_local x (gty_as_ty ty)) args in
274-
let tyargs = List.map (EcTypes.tvar |- fst) axpm in
281+
let tyargs = List.map EcTypes.tvar axpm in
275282
let op = f_op path tyargs (toarrow (List.map f_ty opargs) axbd.EcAst.f_ty) in
276283
let op = f_app op opargs axbd.f_ty in
277284
let axspec = f_forall args (f_eq op axbd) in

src/ecDecl.mli

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22
open EcUtils
33
open EcSymbols
44
open EcBigInt
5-
open EcPath
65
open EcTypes
76
open EcCoreFol
87

98
(* -------------------------------------------------------------------- *)
10-
type ty_param = EcIdent.t * EcPath.Sp.t
9+
type ty_param = EcIdent.t
1110
type ty_params = ty_param list
1211
type ty_pctor = [ `Int of int | `Named of ty_params ]
1312

@@ -25,7 +24,7 @@ type ty_dtype = {
2524

2625
type ty_body =
2726
| Concrete of EcTypes.ty
28-
| Abstract of Sp.t
27+
| Abstract
2928
| Datatype of ty_dtype
3029
| Record of ty_record
3130

@@ -37,11 +36,11 @@ type tydecl = {
3736
}
3837

3938
val tydecl_as_concrete : tydecl -> EcTypes.ty option
40-
val tydecl_as_abstract : tydecl -> Sp.t option
39+
val tydecl_as_abstract : tydecl -> unit option
4140
val tydecl_as_datatype : tydecl -> ty_dtype option
4241
val tydecl_as_record : tydecl -> (form * (EcSymbols.symbol * EcTypes.ty) list) option
4342

44-
val abs_tydecl : ?tc:Sp.t -> ?params:ty_pctor -> locality -> tydecl
43+
val abs_tydecl : ?params:ty_pctor -> locality -> tydecl
4544

4645
val ty_instantiate : ty_params -> ty list -> ty -> ty
4746

src/ecEnv.ml

Lines changed: 10 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -782,13 +782,13 @@ module MC = struct
782782

783783
match tyd.tyd_type with
784784
| Concrete _ -> mc
785-
| Abstract _ -> mc
785+
| Abstract -> mc
786786

787787
| Datatype dtype ->
788788
let cs = dtype.tydt_ctors in
789789
let schelim = dtype.tydt_schelim in
790790
let schcase = dtype.tydt_schcase in
791-
let params = List.map (fun (x, _) -> tvar x) tyd.tyd_params in
791+
let params = List.map tvar tyd.tyd_params in
792792
let for1 i (c, aty) =
793793
let aty = EcTypes.toarrow aty (tconstr mypath params) in
794794
let aty = EcSubst.freshen_type (tyd.tyd_params, aty) in
@@ -829,7 +829,7 @@ module MC = struct
829829
) mc projs
830830

831831
| Record (scheme, fields) ->
832-
let params = List.map (fun (x, _) -> tvar x) tyd.tyd_params in
832+
let params = List.map tvar tyd.tyd_params in
833833
let nfields = List.length fields in
834834
let cfields =
835835
let for1 i (f, aty) =
@@ -911,7 +911,7 @@ module MC = struct
911911
let opname = EcIdent.name opid in
912912
let optype = EcSubst.subst_ty tsubst optype in
913913
let opdecl =
914-
mk_op ~opaque:optransparent [(self, Sp.singleton mypath)]
914+
mk_op ~opaque:optransparent [(self)]
915915
optype (Some OP_TC) loca
916916
in (opid, xpath opname, optype, opdecl)
917917
in
@@ -931,7 +931,7 @@ module MC = struct
931931
List.map
932932
(fun (x, ax) ->
933933
let ax = EcSubst.subst_form fsubst ax in
934-
(x, { ax_tparams = [(self, Sp.singleton mypath)];
934+
(x, { ax_tparams = [(self)];
935935
ax_spec = ax;
936936
ax_kind = `Lemma;
937937
ax_loca = loca;
@@ -1107,9 +1107,6 @@ module MC = struct
11071107
else
11081108
(add2mc _up_theory xsubth cth mc, None)
11091109

1110-
| Th_typeclass (x, tc) ->
1111-
(add2mc _up_typeclass x tc mc, None)
1112-
11131110
| Th_baserw (x, _) ->
11141111
(add2mc _up_rwbase x (expath x) mc, None)
11151112

@@ -1406,11 +1403,6 @@ module TypeClass = struct
14061403
let myself = EcPath.pqname (root env) name in
14071404
{ env with env_tc = TC.Graph.add ~src:myself ~dst:prt env.env_tc }
14081405
1409-
let bind ?(import = true) name tc env =
1410-
let env = rebind name tc env in
1411-
let item = Th_typeclass (name, tc) in
1412-
{ env with env_item = mkitem ~import item :: env.env_item }
1413-
14141406
let lookup qname (env : env) =
14151407
MC.lookup_typeclass qname env
14161408
@@ -2548,7 +2540,7 @@ module Ty = struct
25482540
match by_path_opt name env with
25492541
| Some ({ tyd_type = Concrete body } as tyd) ->
25502542
Tvar.subst
2551-
(Tvar.init (List.map fst tyd.tyd_params) args)
2543+
(Tvar.init tyd.tyd_params args)
25522544
body
25532545
| _ -> raise (LookupFailure (`Path name))
25542546
@@ -2603,22 +2595,7 @@ module Ty = struct
26032595
| _ -> None
26042596
26052597
let rebind name ty env =
2606-
let env = MC.bind_tydecl name ty env in
2607-
2608-
match ty.tyd_type with
2609-
| Abstract tc ->
2610-
let myty =
2611-
let myp = EcPath.pqname (root env) name in
2612-
let typ = List.map (fst_map EcIdent.fresh) ty.tyd_params in
2613-
(typ, EcTypes.tconstr myp (List.map (tvar |- fst) typ)) in
2614-
let instr =
2615-
Sp.fold
2616-
(fun p inst -> TypeClass.bind_instance myty (`General p) inst)
2617-
tc env.env_tci
2618-
in
2619-
{ env with env_tci = instr }
2620-
2621-
| _ -> env
2598+
MC.bind_tydecl name ty env
26222599
26232600
let bind ?(import = true) name ty env =
26242601
let env = rebind name ty env in
@@ -2722,7 +2699,7 @@ module Op = struct
27222699
27232700
let reduce ?mode ?nargs env p tys =
27242701
let op, f = core_reduce ?mode ?nargs env p in
2725-
Tvar.f_subst ~freshen:true (List.map fst op.op_tparams) tys f
2702+
Tvar.f_subst ~freshen:true op.op_tparams tys f
27262703
27272704
let is_projection env p =
27282705
try EcDecl.is_proj (by_path p env)
@@ -2815,7 +2792,7 @@ module Ax = struct
28152792
let instantiate p tys env =
28162793
match by_path_opt p env with
28172794
| Some ({ ax_spec = f } as ax) ->
2818-
Tvar.f_subst ~freshen:true (List.map fst ax.ax_tparams) tys f
2795+
Tvar.f_subst ~freshen:true ax.ax_tparams tys f
28192796
| _ -> raise (LookupFailure (`Path p))
28202797
28212798
let iter ?name f (env : env) =
@@ -2930,20 +2907,6 @@ module Theory = struct
29302907
| Th_theory (x, cth) when cth.cth_mode = `Concrete ->
29312908
bind_instance_th (xpath x) inst cth.cth_items
29322909
2933-
| Th_type (x, tyd) -> begin
2934-
match tyd.tyd_type with
2935-
| Abstract tc ->
2936-
let myty =
2937-
let typ = List.map (fst_map EcIdent.fresh) tyd.tyd_params in
2938-
(typ, EcTypes.tconstr (xpath x) (List.map (tvar |- fst) typ))
2939-
in
2940-
Sp.fold
2941-
(fun p inst -> TypeClass.bind_instance myty (`General p) inst)
2942-
tc inst
2943-
2944-
| _ -> inst
2945-
end
2946-
29472910
| _ -> inst
29482911
29492912
(* ------------------------------------------------------------------ *)
@@ -2964,17 +2927,6 @@ module Theory = struct
29642927
end
29652928
| _ -> odfl base (tx path base item.ti_item)
29662929
2967-
(* ------------------------------------------------------------------ *)
2968-
let bind_tc_th =
2969-
let for1 path base = function
2970-
| Th_typeclass (x, tc) ->
2971-
tc.tc_prt |> omap (fun prt ->
2972-
let src = EcPath.pqname path x in
2973-
TC.Graph.add ~src ~dst:prt base)
2974-
| _ -> None
2975-
2976-
in bind_base_th for1
2977-
29782930
(* ------------------------------------------------------------------ *)
29792931
let bind_br_th =
29802932
let for1 path base = function
@@ -3047,14 +2999,13 @@ module Theory = struct
30472999
| _, `Concrete ->
30483000
let thname = EcPath.pqname (root env) cth.name in
30493001
let env_tci = bind_instance_th thname env.env_tci items in
3050-
let env_tc = bind_tc_th thname env.env_tc items in
30513002
let env_rwbase = bind_br_th thname env.env_rwbase items in
30523003
let env_atbase = bind_at_th thname env.env_atbase items in
30533004
let env_ntbase = bind_nt_th thname env.env_ntbase items in
30543005
let env_redbase = bind_rd_th thname env.env_redbase items in
30553006
let env =
30563007
{ env with
3057-
env_tci ; env_tc ; env_rwbase;
3008+
env_tci ; env_rwbase;
30583009
env_atbase; env_ntbase; env_redbase; }
30593010
in
30603011
add_restr_th thname env items
@@ -3106,9 +3057,6 @@ module Theory = struct
31063057
| Th_theory (x, ({cth_mode = `Abstract} as th)) ->
31073058
MC.import_theory (xpath x) th env
31083059
3109-
| Th_typeclass (x, tc) ->
3110-
MC.import_typeclass (xpath x) tc env
3111-
31123060
| Th_baserw (x, _) ->
31133061
MC.import_rwbase (xpath x) env
31143062
@@ -3265,7 +3213,6 @@ module Theory = struct
32653213
| `Concrete ->
32663214
{ env with
32673215
env_tci = bind_instance_th thpath env.env_tci cth.cth_items;
3268-
env_tc = bind_tc_th thpath env.env_tc cth.cth_items;
32693216
env_rwbase = bind_br_th thpath env.env_rwbase cth.cth_items;
32703217
env_atbase = bind_at_th thpath env.env_atbase cth.cth_items;
32713218
env_ntbase = bind_nt_th thpath env.env_ntbase cth.cth_items;

src/ecEnv.mli

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,6 @@ module TypeClass : sig
380380
type t = typeclass
381381

382382
val add : path -> env -> env
383-
val bind : ?import:bool -> symbol -> t -> env -> env
384383
val graph : env -> EcTypeClass.graph
385384

386385
val by_path : path -> env -> t

src/ecHiGoal.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ let process_exacttype qs (tc : tcenv1) =
490490
tc_error !!tc "%a" EcEnv.pp_lookup_failure cause
491491
in
492492
let tys =
493-
List.map (fun (a,_) -> EcTypes.tvar a)
493+
List.map (fun a -> EcTypes.tvar a)
494494
(EcEnv.LDecl.tohyps hyps).h_tvar in
495495
let pt = ptglobal ~tys p in
496496

@@ -700,7 +700,7 @@ let process_delta ~und_delta ?target (s, o, p) tc =
700700
match sform_of_form fp with
701701
| SFop ((_, tvi), []) -> begin
702702
(* FIXME: TC HOOK *)
703-
let body = Tvar.f_subst ~freshen:true (List.map fst tparams) tvi body in
703+
let body = Tvar.f_subst ~freshen:true tparams tvi body in
704704
let body = f_app body args topfp.f_ty in
705705
try EcReduction.h_red EcReduction.beta_red hyps body
706706
with EcEnv.NotReducible -> body
@@ -723,7 +723,7 @@ let process_delta ~und_delta ?target (s, o, p) tc =
723723
| `RtoL ->
724724
let fp =
725725
(* FIXME: TC HOOK *)
726-
let body = Tvar.f_subst ~freshen:true (List.map fst tparams) tvi body in
726+
let body = Tvar.f_subst ~freshen:true tparams tvi body in
727727
let fp = f_app body args p.f_ty in
728728
try EcReduction.h_red EcReduction.beta_red hyps fp
729729
with EcEnv.NotReducible -> fp

0 commit comments

Comments
 (0)