Skip to content

Commit 6754fce

Browse files
committed
Have Evd use einstance everywhere
1 parent ed30052 commit 6754fce

File tree

14 files changed

+52
-46
lines changed

14 files changed

+52
-46
lines changed

engine/eConstr.mli

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ end
7171

7272
module EInstance :
7373
sig
74-
type t
74+
type t = Evd.einstance
7575
(** Type of universe instances up-to universe unification. Similar to
7676
[ESorts.t] for [UVars.Instance.t]. *)
7777

@@ -452,7 +452,7 @@ val identity_subst_val : named_context_val -> t SList.t
452452

453453
(* XXX Missing Sigma proxy *)
454454
val fresh_global :
455-
?loc:Loc.t -> ?rigid:Evd.rigid -> ?names:UVars.Instance.t -> Environ.env ->
455+
?loc:Loc.t -> ?rigid:Evd.rigid -> ?names:EInstance.t -> Environ.env ->
456456
Evd.evar_map -> GlobRef.t -> Evd.evar_map * t
457457

458458
val is_global : Environ.env -> Evd.evar_map -> GlobRef.t -> t -> bool

engine/evarutil.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -787,8 +787,8 @@ let eq_constr_univs_test ~evd ~extended_evd t u =
787787
and u = EConstr.Unsafe.to_constr u in
788788
let sigma = ref extended_evd in
789789
let eq_universes _ u1 u2 =
790-
let u1 = normalize_universe_instance !sigma u1 in
791-
let u2 = normalize_universe_instance !sigma u2 in
790+
let u1 = EConstr.EInstance.(kind !sigma (make u1)) in
791+
let u2 = EConstr.EInstance.(kind !sigma (make u2)) in
792792
UGraph.check_eq_instances (universes !sigma) u1 u2
793793
in
794794
let eq_sorts s1 s2 =

engine/evd.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ type econstr = constr
2323
type etypes = types
2424
type esorts = Sorts.t
2525
type erelevance = Sorts.relevance
26+
type einstance = UVars.Instance.t
27+
type 'a puniverses = 'a * einstance
2628

2729
(** Generic filters *)
2830
module Filter :

engine/evd.mli

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ type econstr
3232
type etypes = econstr
3333
type esorts
3434
type erelevance
35+
type einstance
36+
type 'a puniverses = 'a * einstance
3537

3638
(** {5 Existential variables and unification states} *)
3739

@@ -571,14 +573,14 @@ val make_nonalgebraic_variable : evar_map -> Univ.Level.t -> evar_map
571573

572574
val is_flexible_level : evar_map -> Univ.Level.t -> bool
573575

574-
val normalize_universe_instance : evar_map -> UVars.Instance.t -> UVars.Instance.t
576+
val normalize_universe_instance : evar_map -> einstance -> einstance
575577

576578
val set_leq_sort : evar_map -> esorts -> esorts -> evar_map
577579
val set_eq_sort : evar_map -> esorts -> esorts -> evar_map
578580
val set_eq_level : evar_map -> Univ.Level.t -> Univ.Level.t -> evar_map
579581
val set_leq_level : evar_map -> Univ.Level.t -> Univ.Level.t -> evar_map
580582
val set_eq_instances : ?flex:bool ->
581-
evar_map -> UVars.Instance.t -> UVars.Instance.t -> evar_map
583+
evar_map -> einstance -> einstance -> evar_map
582584

583585
val set_eq_qualities : evar_map -> Sorts.Quality.t -> Sorts.Quality.t -> evar_map
584586
val set_above_prop : evar_map -> Sorts.Quality.t -> evar_map
@@ -641,15 +643,15 @@ val update_sigma_univs : UGraph.t -> evar_map -> evar_map
641643
val fresh_sort_in_quality : ?loc:Loc.t -> ?rigid:rigid
642644
-> evar_map -> UnivGen.QualityOrSet.t -> evar_map * esorts
643645
val fresh_constant_instance : ?loc:Loc.t -> ?rigid:rigid
644-
-> env -> evar_map -> Constant.t -> evar_map * pconstant
646+
-> env -> evar_map -> Constant.t -> evar_map * Constant.t puniverses
645647
val fresh_inductive_instance : ?loc:Loc.t -> ?rigid:rigid
646-
-> env -> evar_map -> inductive -> evar_map * pinductive
648+
-> env -> evar_map -> inductive -> evar_map * inductive puniverses
647649
val fresh_constructor_instance : ?loc:Loc.t -> ?rigid:rigid
648-
-> env -> evar_map -> constructor -> evar_map * pconstructor
650+
-> env -> evar_map -> constructor -> evar_map * constructor puniverses
649651
val fresh_array_instance : ?loc:Loc.t -> ?rigid:rigid
650-
-> env -> evar_map -> evar_map * UVars.Instance.t
652+
-> env -> evar_map -> evar_map * einstance
651653

652-
val fresh_global : ?loc:Loc.t -> ?rigid:rigid -> ?names:UVars.Instance.t -> env ->
654+
val fresh_global : ?loc:Loc.t -> ?rigid:rigid -> ?names:einstance -> env ->
653655
evar_map -> GlobRef.t -> evar_map * econstr
654656

655657
(********************************************************************)
@@ -693,7 +695,7 @@ module MiniEConstr : sig
693695
end
694696

695697
module EInstance : sig
696-
type t
698+
type t = einstance
697699
val make : UVars.Instance.t -> t
698700
val kind : evar_map -> t -> UVars.Instance.t
699701
val empty : t

interp/primNotations.ml

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,9 @@ exception NotAValidPrimToken
267267
what it means for a term to be ground / to be able to be
268268
considered for parsing. *)
269269

270-
let constr_of_globref ?(allow_constant=true) env sigma = function
270+
let constr_of_globref ?(allow_constant=true) env sigma =
271+
let open EConstr in
272+
function
271273
| GlobRef.ConstructRef c ->
272274
let sigma,c = Evd.fresh_constructor_instance env sigma c in
273275
sigma,mkConstructU c
@@ -282,7 +284,9 @@ let constr_of_globref ?(allow_constant=true) env sigma = function
282284
(** [check_glob g c] checks that glob [g] is equal to constr [c]
283285
and returns [g] as a constr (with fresh universe instances)
284286
or raises [NotAValidPrimToken]. *)
285-
let rec check_glob env sigma g c = match DAst.get g, Constr.kind c with
287+
let rec check_glob env sigma g c =
288+
let open EConstr in
289+
match DAst.get g, Constr.kind c with
286290
| Glob_term.GRef (GlobRef.ConstructRef c as g, _), Constr.Construct (c', _)
287291
when Environ.QConstruct.equal env c c' -> constr_of_globref env sigma g
288292
| Glob_term.GRef (GlobRef.IndRef c as g, _), Constr.Ind (c', _)
@@ -308,12 +312,14 @@ let rec check_glob env sigma g c = match DAst.get g, Constr.kind c with
308312
sigma, mkArray (u,t,def,ty)
309313
| Glob_term.GSort s, Constr.Sort s' ->
310314
let sigma,s = Glob_ops.fresh_glob_sort_in_quality sigma s in
311-
let s = EConstr.ESorts.kind sigma s in
312-
if not (Sorts.equal s s') then raise NotAValidPrimToken;
315+
let s' = ESorts.make s' in
316+
if not (ESorts.equal sigma s s') then raise NotAValidPrimToken;
313317
sigma,mkSort s
314318
| _ -> raise NotAValidPrimToken
315319

316-
let rec constr_of_glob to_post post env sigma g = match DAst.get g with
320+
let rec constr_of_glob to_post post env sigma g =
321+
let open EConstr in
322+
match DAst.get g with
317323
| Glob_term.GRef (r, _) ->
318324
let o = List.find_opt (fun (_,r',_) -> Environ.QGlobRef.equal env r r') post in
319325
begin match o with
@@ -367,7 +373,6 @@ let rec constr_of_glob to_post post env sigma g = match DAst.get g with
367373
sigma, mkArray (u',t',def',ty')
368374
| Glob_term.GSort gs ->
369375
let sigma,c = Glob_ops.fresh_glob_sort_in_quality sigma gs in
370-
let c = EConstr.ESorts.kind sigma c in
371376
sigma,mkSort c
372377
| _ ->
373378
raise NotAValidPrimToken
@@ -514,6 +519,7 @@ let uninterp to_raw o n =
514519
let of_ty = EConstr.Unsafe.to_constr of_ty in
515520
try
516521
let sigma,n = constr_of_glob o.to_post env sigma n in
522+
let n = EConstr.Unsafe.to_constr n in
517523
let c = eval_constr_app env sigma of_ty n in
518524
let c = match snd o.of_kind with
519525
| Direct -> c

plugins/funind/gen_principle.ml

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -191,17 +191,17 @@ let build_functional_principle env (sigma : Evd.evar_map) old_princ_type sorts f
191191
(Induction.compute_elim_sig sigma (EConstr.of_constr old_princ_type))
192192
.Induction.nparams
193193
in
194+
let funs = Array.map EConstr.mkConstU funs in
194195
let new_principle_type =
195196
Functional_principles_types.compute_new_princ_type_from_rel (Global.env ())
196-
(Array.map Constr.mkConstU funs)
197+
(Array.map (EConstr.to_constr sigma) funs)
197198
(Array.map (fun s -> EConstr.ESorts.kind sigma s) sorts) old_princ_type
198199
in
199200
let sigma, _ =
200201
Typing.type_of ~refresh:true env sigma
201202
(EConstr.of_constr new_principle_type)
202203
in
203-
let map (c, u) = EConstr.mkConstU (c, EConstr.EInstance.make u) in
204-
let ftac = proof_tac (Array.map map funs) mutr_nparams in
204+
let ftac = proof_tac funs mutr_nparams in
205205
let uctx = Evd.ustate sigma in
206206
let typ = EConstr.of_constr new_principle_type in
207207
let body, typ, univs, _safe, _uctx =
@@ -364,7 +364,7 @@ let generate_principle (evd : Evd.evar_map ref) pconstants on_error is_general
364364
evd := sigma;
365365
let princ_type = EConstr.Unsafe.to_constr princ_type in
366366
generate_functional_principle evd princ_type None None
367-
(Array.of_list pconstants) (* funs_kn *)
367+
(Array.map_of_list (fun (c, u) -> c, EConstr.EInstance.make u ) pconstants) (* funs_kn *)
368368
i
369369
(continue_proof 0 [|funs_kn.(i)|]))
370370
0 fix_rec_l
@@ -1274,7 +1274,7 @@ let get_funs_constant mp =
12741274
in
12751275
l_const
12761276

1277-
let make_scheme evd (fas : (Constr.pconstant * UnivGen.QualityOrSet.t) list) : _ list =
1277+
let make_scheme evd (fas : (Constant.t EConstr.puniverses * UnivGen.QualityOrSet.t) list) : _ list =
12781278
let exception Found_type of int in
12791279
let env = Global.env () in
12801280
let funs = List.map fst fas in
@@ -1300,7 +1300,7 @@ let make_scheme evd (fas : (Constr.pconstant * UnivGen.QualityOrSet.t) list) : _
13001300
List.map
13011301
(fun idx ->
13021302
let ind = (first_fun_kn, idx) in
1303-
((ind, EConstr.EInstance.make @@ snd first_fun), true, EConstr.ESorts.prop))
1303+
((ind, snd first_fun), true, EConstr.ESorts.prop))
13041304
funs_indexes
13051305
in
13061306
let sigma, schemes = Indrec.build_mutual_induction_scheme env !evd ind_list in
@@ -1354,7 +1354,7 @@ let make_scheme evd (fas : (Constr.pconstant * UnivGen.QualityOrSet.t) list) : _
13541354
if List.is_empty other_princ_types then [(body, typ, univs, opaque)]
13551355
else
13561356
let other_fun_princ_types =
1357-
let funs = Array.map Constr.mkConstU this_block_funs in
1357+
let funs = Array.map EConstr.(mkConstU %> to_constr sigma) this_block_funs in
13581358
let sorts = Array.of_list sorts in
13591359
let sorts = Array.map (fun s -> EConstr.ESorts.kind sigma s) sorts in
13601360
List.map
@@ -1418,14 +1418,13 @@ let make_scheme evd (fas : (Constr.pconstant * UnivGen.QualityOrSet.t) list) : _
14181418
lemmas for each function in [funs] w.r.t. [graphs]
14191419
*)
14201420

1421-
let derive_correctness (funs : Constr.pconstant list) (graphs : inductive list)
1421+
let derive_correctness (funs : Constant.t EConstr.puniverses list) (graphs : inductive list)
14221422
=
14231423
let open EConstr in
14241424
assert (funs <> []);
14251425
assert (graphs <> []);
14261426
let funs = Array.of_list funs and graphs = Array.of_list graphs in
1427-
let map (c, u) = mkConstU (c, EInstance.make u) in
1428-
let funs_constr = Array.map map funs in
1427+
let funs_constr = Array.map mkConstU funs in
14291428
(* XXX STATE Why do we need this... why is the toplevel protection not enough *)
14301429
funind_purify
14311430
(fun () ->
@@ -1595,8 +1594,7 @@ let derive_inversion env fix_names =
15951594
Evd.fresh_global env evd
15961595
(Option.get (Constrintern.locate_reference (Libnames.qualid_of_ident id)))
15971596
in
1598-
let cst, u = EConstr.destConst evd c in
1599-
(evd, (cst, EConstr.EInstance.kind evd u) :: l))
1597+
(evd, EConstr.destConst evd c :: l))
16001598
fix_names (evd', [])
16011599
in
16021600
(*
@@ -2154,7 +2152,7 @@ let build_scheme fas =
21542152
++ spc ()
21552153
++ str "should be the named of a globally defined function")
21562154
in
2157-
((c, EConstr.EInstance.kind !evd u), sort))
2155+
((c, u), sort))
21582156
fas
21592157
in
21602158
let bodies_types = make_scheme evd pconstants in

plugins/ssr/ssrfwd.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ let basecuttac k c =
150150
let sigma, ug = match qg with
151151
| QConstant (QSProp | QProp) -> sigma, Univ.Level.set
152152
| _ -> Evd.new_univ_level_variable Evd.univ_flexible sigma in
153-
let names = UVars.Instance.of_array ([|qc;qg|],[|uc;ug|]) in
153+
let names = EInstance.make @@ UVars.Instance.of_array ([|qc;qg|],[|uc;ug|]) in
154154
let sigma, f = EConstr.fresh_global env sigma ~names f in
155155
let sigma, step = Evarutil.new_evar env sigma c in
156156
let stepg = Proofview_monad.with_empty_state (fst @@ destEvar sigma step) in

pretyping/cases.ml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,6 @@ let inductive_template env sigma tmloc ind =
290290
instead of the global default universes
291291
(and in the future fresh qualities?) *)
292292
let sigma, indu = Evd.fresh_inductive_instance env sigma ind in
293-
let indu = on_snd EInstance.make indu in
294293
let templ =
295294
match (Environ.lookup_mind (fst (fst indu)) env).mind_template with
296295
| None -> []

pretyping/pretyping.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ let instance ?loc evd (ql,ul) =
548548
(evd, l :: univs)) (evd, [])
549549
ul
550550
in
551-
evd, Some (UVars.Instance.of_array (Array.rev_of_list ql', Array.rev_of_list ul'))
551+
evd, Some (EInstance.make (UVars.Instance.of_array (Array.rev_of_list ql', Array.rev_of_list ul')))
552552

553553
let pretype_global ?loc rigid env evd gr us =
554554
let evd, instance =

pretyping/reductionops.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1276,7 +1276,7 @@ let sigma_compare_sorts _env pb s0 s1 sigma =
12761276
end
12771277

12781278
let sigma_compare_instances ~flex i0 i1 sigma =
1279-
match Evd.set_eq_instances ~flex sigma i0 i1 with
1279+
match Evd.set_eq_instances ~flex sigma (EInstance.make i0) (EInstance.make i1) with
12801280
| sigma -> Result.Ok sigma
12811281
| exception Evd.UniversesDiffer -> Result.Error None
12821282
| exception UGraph.UniverseInconsistency err -> Result.Error (Some err)

0 commit comments

Comments
 (0)