Skip to content

Commit dbf0289

Browse files
committed
Things compile.
All the program logic tactics are out of order but core logic mostly works with new module system.
1 parent f54f899 commit dbf0289

29 files changed

+550
-140
lines changed

src/ecCommands.ml

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -199,28 +199,42 @@ let process_locate scope x =
199199
(* -------------------------------------------------------------------- *)
200200
module HiPrinting = struct
201201
let pr_glob fmt env pm =
202+
match pm with
203+
| FM_ff _ -> failwith "implement."
204+
| FM_FunOrVar _ -> failwith "implement."
205+
| FM_Mod pm -> begin
202206
let ppe = EcPrinting.PPEnv.ofenv env in
203207
let (p, _) = EcTyping.trans_msymbol env pm in
204-
let us = EcEnv.NormMp.mod_use env p in
205-
206-
Format.fprintf fmt "Globals [# = %d]:@."
207-
(Sid.cardinal us.EcEnv.us_gl);
208-
Sid.iter (fun id ->
209-
Format.fprintf fmt " %s@." (EcIdent.name id))
210-
us.EcEnv.us_gl;
211-
212-
Format.fprintf fmt "@.";
213-
214-
Format.fprintf fmt "Prog. variables [# = %d]:@."
215-
(Mx.cardinal us.EcEnv.us_pv);
216-
List.iter (fun (xp,_) ->
208+
let _fp, us = EcMemRestr.module_uses env p None in
209+
210+
Format.fprintf fmt "Calls [# = %d]:@."
211+
(EcPath.Sx.cardinal us.us_calls);
212+
EcPath.Sx.iter (fun xp ->
213+
Format.fprintf fmt " @[%a@]@."
214+
(EcPrinting.pp_funname ppe) xp
215+
)
216+
us.us_calls;
217+
Format.fprintf fmt "Reads [# = %d]:@."
218+
(EcPath.Sx.cardinal us.us_reads);
219+
EcPath.Sx.iter (fun xp ->
217220
let pv = EcTypes.pv_glob xp in
218221
let ty = EcEnv.Var.by_xpath xp env in
219222
Format.fprintf fmt " @[%a : %a@]@."
220223
(EcPrinting.pp_pv ppe) pv
221-
(EcPrinting.pp_type ppe) ty)
222-
(List.rev (Mx.bindings us.EcEnv.us_pv))
223-
224+
(EcPrinting.pp_type ppe) ty
225+
)
226+
us.us_reads;
227+
Format.fprintf fmt "Writes [# = %d]:@."
228+
(EcPath.Sx.cardinal us.us_writes);
229+
EcPath.Sx.iter (fun xp ->
230+
let pv = EcTypes.pv_glob xp in
231+
let ty = EcEnv.Var.by_xpath xp env in
232+
Format.fprintf fmt " @[%a : %a@]@."
233+
(EcPrinting.pp_pv ppe) pv
234+
(EcPrinting.pp_type ppe) ty
235+
)
236+
us.us_writes
237+
end
224238

225239
let pr_goal fmt scope n =
226240
match EcScope.xgoal scope with

src/ecCorePrinting.ml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,12 @@ module type PrinterAPI = sig
5656
val pp_tcname : PPEnv.t -> path pp
5757
val pp_thname : PPEnv.t -> path pp
5858

59-
val pp_mem : PPEnv.t -> EcIdent.t pp
60-
val pp_memtype : PPEnv.t -> EcMemory.memtype pp
61-
val pp_tyvar : PPEnv.t -> ident pp
62-
val pp_tyunivar : PPEnv.t -> EcUid.uid pp
63-
val pp_path : path pp
59+
val pp_mem : PPEnv.t -> EcIdent.t pp
60+
val pp_memtype : PPEnv.t -> EcMemory.memtype pp
61+
val pp_mem_restr : PPEnv.t -> EcAst.mem_restr pp
62+
val pp_tyvar : PPEnv.t -> ident pp
63+
val pp_tyunivar : PPEnv.t -> EcUid.uid pp
64+
val pp_path : path pp
6465

6566
(* ------------------------------------------------------------------ *)
6667
val pp_typedecl : PPEnv.t -> (path * tydecl ) pp

src/ecEnv.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1792,7 +1792,8 @@ module Mod = struct
17921792
(fun s (x, _) a -> EcSubst.add_module s x a)
17931793
EcSubst.empty params args
17941794
in
1795-
f s o
1795+
1796+
f s o
17961797
17971798
let clearparams n params =
17981799
let _, remaining = List.takedrop n params in

src/ecLowGoal.ml

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ module LowApply = struct
169169
(* FIXME: poor API ==> poor error recovery *)
170170
try
171171
EcTyping.check_modtype env mp mt emt;
172-
(EcFol.f_bind_mod sbt x mp env, f)
172+
(Fsubst.f_bind_mod sbt x mp, f)
173173
with _ -> raise InvalidProofTerm
174174
end
175175

@@ -1627,7 +1627,7 @@ let t_rewrite_hyp ?xconv ?mode ?donot (id : EcIdent.t) pos (tc : tcenv1) =
16271627
(* -------------------------------------------------------------------- *)
16281628
type vsubst = [
16291629
| `Local of EcIdent.t
1630-
| `Glob of EcIdent.t * EcMemory.memory
1630+
| `Glob of EcAst.functor_fun * EcMemory.memory
16311631
| `PVar of EcTypes.prog_var * EcMemory.memory
16321632
]
16331633

@@ -1673,10 +1673,12 @@ module LowSubst = struct
16731673

16741674
(* Substitution of globs *)
16751675
| Fglob (mp, m), None when kind.sk_glob -> Some (`Glob (mp, m))
1676-
| Fglob (mp, m), Some (`Glob (mp', _)) when kind.sk_glob ->
1676+
| Fglob (mp, m), Some (`Glob (mp', _)) when kind.sk_glob -> assert false
1677+
(*
16771678
if EcIdent.id_equal mp mp'
16781679
then Some (`Glob (mp, m))
16791680
else None
1681+
*)
16801682

16811683
| _, _ -> None
16821684

@@ -1725,10 +1727,13 @@ module LowSubst = struct
17251727
if EcPV.PV.mem_pv env pv fv then None else Some aout
17261728

17271729
(* Substitution of globs *)
1728-
| Some ((_, `Glob (mp, m), f) as aout) ->
1730+
| Some ((_, `Glob (mp, m), f) as aout) -> assert false
1731+
(*
17291732
let f = simplify { no_red with delta_h = predT } hyps f in
17301733
let fv = EcPV.PV.fv env m f in
1731-
if EcPV.PV.mem_glob env (EcPath.mident mp) fv then None else Some aout in
1734+
if EcPV.PV.mem_glob env (EcPath.mident mp) fv then None else Some aout
1735+
*)
1736+
in
17321737
match aout with
17331738
| None -> None
17341739
| Some(side,v,f) ->
@@ -1759,8 +1764,8 @@ module LowSubst = struct
17591764
let check _tg = true in
17601765
(subst f, check)
17611766

1762-
| `Glob (mp, m) ->
1763-
let subst f = EcPV.PVM.subst env (EcPV.PVM.add_glob env (EcPath.mident mp) m f EcPV.PVM.empty) in
1767+
| `Glob (_ff, _m) ->
1768+
let subst _f = EcPV.PVM.subst env EcPV.PVM.empty in (* (EcPV.PVM.add_glob env (EcPath.mident mp) m f EcPV.PVM.empty) in *)
17641769
(* FIXME *)
17651770
let check _tg = true in
17661771
(subst f, check)

src/ecLowGoal.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ val t_cutdef : proofterm -> form -> FApi.backward
191191
(* -------------------------------------------------------------------- *)
192192
type vsubst = [
193193
| `Local of EcIdent.t
194-
| `Glob of EcIdent.t * EcMemory.memory
194+
| `Glob of EcAst.functor_fun * EcMemory.memory
195195
| `PVar of EcTypes.prog_var * EcMemory.memory
196196
]
197197

src/ecLowPhlGoal.ml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,8 @@ let subst_form_lv env m lv t f =
453453

454454
(* -------------------------------------------------------------------- *)
455455
(* Remark: m is only used to create fresh name, id_of_pv *)
456-
let generalize_subst_ env m uelts uglob =
456+
let generalize_subst_ env m uelts uglob = assert false
457+
(*
457458
let create (pv, ty) = id_of_pv pv m, GTty ty in
458459
let b = List.map create uelts in
459460
let s =
@@ -471,8 +472,10 @@ let generalize_subst_ env m uelts uglob =
471472
s uglob b'
472473
in
473474
(b', b, s)
475+
*)
474476

475-
let generalize_mod_ env m modi f =
477+
let generalize_mod_ env m modi f = assert false
478+
(*
476479
let (melts, mglob) = PV.ntr_elements modi in
477480
478481
(* 1. Compute the prog-vars and the globals used in [f] *)
@@ -512,7 +515,7 @@ let generalize_mod_ env m modi f =
512515
let s = PVM.of_mpv s m in
513516
let f = PVM.subst env s f in
514517
f_forall_simpl (bd'@bd) f, (bd', uglob), (bd, uelts)
515-
518+
*)
516519
let generalize_subst env m uelts uglob =
517520
let (b',b,f) = generalize_subst_ env m uelts uglob in
518521
b'@b, f

src/ecMatching.ml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -321,10 +321,10 @@ module MEV = struct
321321
let v = EV.fold (fun x k v -> f x (`Mod k) v) m.evm_mod v in
322322
v
323323

324-
let assubst ue ev env =
324+
let assubst ue ev _env =
325325
let subst = f_subst_init ~tu:(EcUnify.UniEnv.assubst ue) () in
326326
let subst = EV.fold (fun x m s -> Fsubst.f_bind_mem s x m) ev.evm_mem subst in
327-
let subst = EV.fold (fun x mp s -> EcFol.f_bind_mod s x mp env) ev.evm_mod subst in
327+
let subst = EV.fold (fun _x _mp _s -> assert false) ev.evm_mod subst in
328328
let seen = ref Sid.empty in
329329

330330
let rec for_ident x binding subst =
@@ -527,10 +527,13 @@ let f_match_core opts hyps (ue, ev) f1 f2 =
527527
| Fint i1, Fint i2 ->
528528
if not (EcBigInt.equal i1 i2) then failure ();
529529

530-
| Fglob (mp1, me1), Fglob (mp2, me2) ->
530+
| Fglob _, Fglob _ ->
531+
assert false;
532+
(*
531533
if not (EcIdent.id_equal mp1 mp2) then
532534
failure ();
533535
doit_mem env mxs me1 me2
536+
*)
534537

535538
| Ftuple fs1, Ftuple fs2 ->
536539
if List.length fs1 <> List.length fs2 then
@@ -717,7 +720,7 @@ let f_match_core opts hyps (ue, ev) f1 f2 =
717720
in (env, subst)
718721

719722
| GTmodty p1, GTmodty p2 ->
720-
if not (NormMp.mod_type_equiv env p1 p2) then
723+
if not (NormMp.module_type_equiv env (fst p1) (fst p2)) then
721724
raise MatchFailure;
722725

723726
let subst =

src/ecMemRestr.ml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ let ff_norm env ff mem =
9797
let _, fuses = funs_uses_core env ff.ff_params [ff.ff_xp] in
9898
Uses.to_form env ff.ff_params fuses mem
9999

100+
let ff_norm_ty env ff =
101+
let _, fuses = funs_uses_core env ff.ff_params [ff.ff_xp] in
102+
Uses.to_type env ff.ff_params fuses
100103

101104
let funs_uses_mr env params fs =
102105
let env, fuses = funs_uses_core env params fs in
@@ -157,6 +160,54 @@ let rec norm_mem_restr env mr =
157160
| Inter(s1, s2) -> mr_inter (norm_mem_restr env s1) (norm_mem_restr env s2)
158161
| Diff (s1, s2) -> mr_diff (norm_mem_restr env s1) (norm_mem_restr env s2)
159162

163+
164+
let rec norm_globs_restrs env f =
165+
let has_mod b =
166+
List.exists (fun (_,gty) ->
167+
match gty with GTmodty _ -> true | _ -> false) b in
168+
169+
let norm_bind env (x, gty) =
170+
match gty with
171+
| GTty ty -> begin
172+
match ty.ty_node with
173+
| Tglob ff -> (x, GTty (ff_norm_ty env ff))
174+
| _ -> (x, gty)
175+
end
176+
| GTmodty (mt, mr) -> (x, (GTmodty (mt, norm_mem_restr env mr)))
177+
| GTmem _ -> (x, gty)
178+
in
179+
180+
match f.f_node with
181+
| Fquant (q, bd, f) ->
182+
let env = if has_mod bd then EcEnv.Mod.add_mod_binding bd env else env in
183+
f_quant q (List.map (norm_bind env) bd) (norm_globs_restrs env f)
184+
| Fglob (ff, m) -> ff_norm env ff m
185+
| Fif (f1, f2, f3) ->
186+
f_if
187+
(norm_globs_restrs env f1)
188+
(norm_globs_restrs env f2)
189+
(norm_globs_restrs env f3)
190+
| Fmatch (b, fs, ty) ->
191+
f_match
192+
(norm_globs_restrs env b)
193+
(List.map (norm_globs_restrs env) fs)
194+
ty
195+
| Flet (lv, f1, f2) ->
196+
f_let
197+
lv
198+
(norm_globs_restrs env f1)
199+
(norm_globs_restrs env f2)
200+
| Fapp (e, es) ->
201+
f_app
202+
(norm_globs_restrs env e)
203+
(List.map (norm_globs_restrs env) es)
204+
f.f_ty
205+
| Ftuple es ->
206+
f_tuple (List.map (norm_globs_restrs env) es)
207+
| Fproj (e, i) ->
208+
f_proj (norm_globs_restrs env e) i f.f_ty
209+
| _ -> f
210+
160211
let sup env ff =
161212
(* The xpath is know to be normalised so it is abstract *)
162213
match (Fun.by_xpath ff.ff_xp env).f_def with
@@ -457,6 +508,16 @@ and process (env : env) (r : mem) (st : local_state) =
457508

458509
(* ------------------------------------------------------------------- *)
459510

511+
let rec dump_mem_restr mr =
512+
match mr with
513+
| Empty -> "Empty"
514+
| All -> "All"
515+
| Var x -> Format.sprintf "Var (%s)" (EcPath.x_tostring x)
516+
| GlobFun ff -> Format.sprintf "GlobFun (%s)" (EcPath.x_tostring ff.ff_xp)
517+
| Inter (l, r) -> Format.sprintf "Inter (%s, %s)" (dump_mem_restr l) (dump_mem_restr r)
518+
| Union (l, r) -> Format.sprintf "Union (%s, %s)" (dump_mem_restr l) (dump_mem_restr r)
519+
| Diff (l, r) -> Format.sprintf "Diff (%s, %s)" (dump_mem_restr l) (dump_mem_restr r)
520+
460521
(* /!\ Precondition s1 and s2 should have been normalised *)
461522
let core_subset env s1 s2 =
462523
(* add clause !(s1 subset s2)

src/ecMemRestr.mli

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ module Uses : sig
66
val to_form : env -> functor_params -> EcModules.uses -> memory -> form
77
end
88

9-
109
val ff_alpha_equal : functor_fun -> functor_fun -> bool
1110

1211
val ff_norm : env -> functor_fun -> memory -> form
12+
val ff_norm_ty : env -> functor_fun -> ty
1313

1414
val fun_uses_mr : env -> xpath -> mem_restr
1515

@@ -21,6 +21,8 @@ val module_uses_form : env -> mpath -> module_type option -> memory -> form
2121

2222
val module_uses : env -> mpath -> module_type option -> functor_params * EcModules.uses
2323

24+
val norm_globs_restrs : env -> form -> form
25+
2426
val equal : env -> mem_restr -> mem_restr -> bool
2527
val subset : env -> mem_restr -> mem_restr -> bool
2628
val disjoint : env -> mem_restr -> mem_restr -> bool

0 commit comments

Comments
 (0)