Skip to content

Commit 61627b0

Browse files
Merge PR #20360: Cleanup univ.ml(i) (remove some aliases, move hcons functions)
Reviewed-by: ppedrot Co-authored-by: ppedrot <ppedrot@users.noreply.github.com>
2 parents e7f36b8 + 64b87aa commit 61627b0

File tree

10 files changed

+65
-76
lines changed

10 files changed

+65
-76
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
overlay metacoq https://github.com/SkySkimmer/metacoq clean-univ 20360

dev/top_printers.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ let ppqvarset l = pp (hov 1 (str "{" ++ prlist_with_sep spc QVar.raw_pr (QVar.Se
286286
let ppuniverse_set l = pp (Level.Set.pr prlev l)
287287
let ppuniverse_instance l = pp (Instance.pr prqvar prlev l)
288288
let ppuniverse_context l = pp (pr_universe_context prqvar prlev l)
289-
let ppuniverse_context_set l = pp (pr_universe_context_set prlev l)
289+
let ppuniverse_context_set l = pp (ContextSet.pr prlev l)
290290
let ppuniverse_subst l = pp (UnivSubst.pr_universe_subst Level.raw_pr l)
291291
let ppuniverse_opt_subst l = pp (UnivFlex.pr Level.raw_pr l)
292292
let ppqvar_subst l = pp (UVars.pr_quality_level_subst QVar.raw_pr l)

engine/uState.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1320,7 +1320,7 @@ let pr ctx =
13201320
else
13211321
v 0
13221322
(str"UNIVERSES:"++brk(0,1)++
1323-
h (Univ.pr_universe_context_set prl (context_set ctx)) ++ fnl () ++
1323+
h (Univ.ContextSet.pr prl (context_set ctx)) ++ fnl () ++
13241324
UnivFlex.pr prl (subst ctx) ++ fnl() ++
13251325
str"SORTS:"++brk(0,1)++
13261326
h (pr_sort_opt_subst ctx) ++ fnl() ++

kernel/safe_typing.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,9 +1046,9 @@ let check_opaque senv (i : Opaqueproof.opaque_handle) pf =
10461046
in
10471047
let ctx = match ctx with
10481048
| Opaqueproof.PrivateMonomorphic u ->
1049-
Opaqueproof.PrivateMonomorphic (snd @@ Univ.hcons_universe_context_set u)
1049+
Opaqueproof.PrivateMonomorphic (snd @@ Univ.ContextSet.hcons u)
10501050
| Opaqueproof.PrivatePolymorphic u ->
1051-
Opaqueproof.PrivatePolymorphic (snd @@ Univ.hcons_universe_context_set u)
1051+
Opaqueproof.PrivatePolymorphic (snd @@ Univ.ContextSet.hcons u)
10521052
in
10531053
{ opq_body = c; opq_univs = ctx; opq_handle = i; opq_nonce = nonce }
10541054

kernel/sorts.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -407,11 +407,11 @@ module Hsorts =
407407

408408
let hashcons = function
409409
| Type u as c ->
410-
let hu, u' = hcons_univ u in
410+
let hu, u' = Universe.hcons u in
411411
combinesmall 2 hu, if u' == u then c else Type u'
412412
| QSort (q, u) as c ->
413413
let hq, q' = QVar.hcons q in
414-
let hu, u' = hcons_univ u in
414+
let hu, u' = Universe.hcons u in
415415
combinesmall 3 (combine hu hq), if u' == u && q' == q then c else QSort (q', u')
416416
| SProp | Prop | Set as s -> hash s, s
417417
let eq s1 s2 = match (s1,s2) with

kernel/uVars.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ struct
315315
let hqnames, qnames = Hashcons.hashcons_array Names.Name.hcons qnames in
316316
let hunames, unames = Hashcons.hashcons_array Names.Name.hcons unames in
317317
let hunivs, univs = Instance.hcons univs in
318-
let hcsts, csts = hcons_constraints csts in
318+
let hcsts, csts = Constraints.hcons csts in
319319
Hashset.Combine.combine4 hqnames hunames hunivs hcsts, ((qnames, unames), (univs, csts))
320320

321321
let names ((names, _) : t) = names
@@ -380,7 +380,7 @@ struct
380380
let hcons ((qnames,unames), cst) =
381381
let hqnames, qnames = Hashcons.hashcons_array Names.Name.hcons qnames in
382382
let hunames, unames = Hashcons.hashcons_array Names.Name.hcons unames in
383-
let hcst, cst = hcons_constraints cst in
383+
let hcst, cst = Constraints.hcons cst in
384384
Hashset.Combine.combine3 hqnames hunames hcst, ((qnames, unames), cst)
385385

386386
let empty = (([||],[||]), Constraints.empty)

kernel/univ.ml

Lines changed: 44 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -229,14 +229,25 @@ module Level = struct
229229
let pr prl s =
230230
hov 1 (str"{" ++ prlist_with_sep spc prl (elements s) ++ str"}")
231231

232+
233+
module Huniverse_set =
234+
Hashcons.Make(
235+
struct
236+
type nonrec t = t
237+
let hashcons s =
238+
fold (fun x (h,acc) ->
239+
let hx, x = hcons x in
240+
Hashset.Combine.combine h hx, add x acc)
241+
s
242+
(0,empty)
243+
let eq s s' = Map.Set.equal s s'
244+
end)
245+
246+
let hcons = Hashcons.simple_hcons Huniverse_set.generate Huniverse_set.hcons ()
232247
end
233248

234249
end
235250

236-
type universe_level = Level.t
237-
238-
type universe_set = Level.Set.t
239-
240251
(* An algebraic universe [universe] is either a universe variable
241252
[Level.t] or a formal universe known to be greater than some
242253
universe variables and strictly greater than some (other) universe
@@ -444,6 +455,11 @@ let pr_constraint_type op =
444455
| Eq -> " = "
445456
in str op_str
446457

458+
let hash_constraint_type = function
459+
| Lt -> 0
460+
| Le -> 1
461+
| Eq -> 2
462+
447463
module UConstraintOrd =
448464
struct
449465
type t = univ_constraint
@@ -456,23 +472,6 @@ struct
456472
else Level.compare v v'
457473
end
458474

459-
module Constraints =
460-
struct
461-
module S = Set.Make(UConstraintOrd)
462-
include S
463-
464-
let pr prl c =
465-
v 0 (prlist_with_sep spc (fun (u1,op,u2) ->
466-
hov 0 (prl u1 ++ pr_constraint_type op ++ prl u2))
467-
(elements c))
468-
469-
end
470-
471-
let hash_constraint_type = function
472-
| Lt -> 0
473-
| Le -> 1
474-
| Eq -> 2
475-
476475
module Hconstraint =
477476
Hashcons.Make(
478477
struct
@@ -487,13 +486,23 @@ module Hconstraint =
487486

488487
let hcons_constraint = Hashcons.simple_hcons Hconstraint.generate Hconstraint.hcons ()
489488

490-
module Hconstraints = CSet.Hashcons(UConstraintOrd)(struct
491-
type t = UConstraintOrd.t
492-
let hcons = hcons_constraint
493-
end)
489+
module Constraints =
490+
struct
491+
module S = Set.Make(UConstraintOrd)
492+
include S
494493

495-
let hcons_constraints = Hashcons.simple_hcons Hconstraints.generate Hconstraints.hcons ()
494+
let pr prl c =
495+
v 0 (prlist_with_sep spc (fun (u1,op,u2) ->
496+
hov 0 (prl u1 ++ pr_constraint_type op ++ prl u2))
497+
(elements c))
496498

499+
module Hconstraints = CSet.Hashcons(UConstraintOrd)(struct
500+
type t = UConstraintOrd.t
501+
let hcons = hcons_constraint
502+
end)
503+
504+
let hcons = Hashcons.simple_hcons Hconstraints.generate Hconstraints.hcons ()
505+
end
497506

498507
(** A value with universe constraints. *)
499508
type 'a constrained = 'a * Constraints.t
@@ -533,7 +542,7 @@ let univ_level_rem u v min =
533542
(** A universe level substitution, note that no algebraic universes are
534543
involved *)
535544

536-
type universe_level_subst = universe_level Level.Map.t
545+
type universe_level_subst = Level.t Level.Map.t
537546

538547
(** A set of universes with universe constraints.
539548
We linearize the set to a list after typechecking.
@@ -542,7 +551,7 @@ type universe_level_subst = universe_level Level.Map.t
542551

543552
module ContextSet =
544553
struct
545-
type t = universe_set constrained
554+
type t = Level.Set.t constrained
546555

547556
let empty = (Level.Set.empty, Constraints.empty)
548557
let is_empty (univs, cst) = Level.Set.is_empty univs && Constraints.is_empty cst
@@ -579,12 +588,16 @@ struct
579588
let levels (univs, _cst) = univs
580589

581590
let size (univs,_) = Level.Set.cardinal univs
582-
end
583591

584-
type universe_context_set = ContextSet.t
592+
let hcons (v,c) =
593+
let hv, v = Level.Set.hcons v in
594+
let hc, c = Constraints.hcons c in
595+
Hashset.Combine.combine hv hc, (v, c)
596+
597+
end
585598

586599
(** A value in a universe context (resp. context set). *)
587-
type 'a in_universe_context_set = 'a * universe_context_set
600+
type 'a in_universe_context_set = 'a * ContextSet.t
588601

589602
(** Substitutions. *)
590603

@@ -617,31 +630,5 @@ let subst_univs_level_constraints subst csts =
617630

618631
(** Pretty-printing *)
619632

620-
let pr_universe_context_set = ContextSet.pr
621-
622633
let pr_universe_level_subst prl =
623634
Level.Map.pr prl (fun u -> str" := " ++ prl u ++ spc ())
624-
625-
module Huniverse_set =
626-
Hashcons.Make(
627-
struct
628-
type t = universe_set
629-
let hashcons s =
630-
Level.Set.fold (fun x (h,acc) ->
631-
let hx, x = Level.hcons x in
632-
Hashset.Combine.combine h hx, Level.Set.add x acc)
633-
s
634-
(0,Level.Set.empty)
635-
let eq s s' =
636-
Level.Set.equal s s'
637-
end)
638-
639-
let hcons_universe_set =
640-
Hashcons.simple_hcons Huniverse_set.generate Huniverse_set.hcons ()
641-
642-
let hcons_universe_context_set (v, c) =
643-
let hv, v = hcons_universe_set v in
644-
let hc, c = hcons_constraints c in
645-
Hashset.Combine.combine hv hc, (v, c)
646-
647-
let hcons_univ x = Universe.hcons x

kernel/univ.mli

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ sig
7272

7373
val pr : (elt -> Pp.t) -> t -> Pp.t
7474
(** Pretty-printing *)
75+
76+
val hcons : t Hashcons.f
7577
end
7678

7779
module Map :
@@ -181,6 +183,8 @@ module Constraints : sig
181183
include CSet.ExtS with type elt = univ_constraint
182184

183185
val pr : (Level.t -> Pp.t) -> t -> Pp.t
186+
187+
val hcons : t Hashcons.f
184188
end
185189

186190
(** A value with universe Constraints.t. *)
@@ -229,6 +233,11 @@ sig
229233
val size : t -> int
230234
(** The number of universes in the context *)
231235

236+
val hcons : t Hashcons.f
237+
238+
val pr : (Level.t -> Pp.t) -> t -> Pp.t
239+
240+
232241
end
233242

234243
(** A value in a universe context set. *)
@@ -249,13 +258,5 @@ val subst_univs_level_constraints : universe_level_subst -> Constraints.t -> Con
249258
(** {6 Pretty-printing of universes. } *)
250259

251260
val pr_constraint_type : constraint_type -> Pp.t
252-
val pr_universe_context_set : (Level.t -> Pp.t) -> ContextSet.t -> Pp.t
253261

254262
val pr_universe_level_subst : (Level.t -> Pp.t) -> universe_level_subst -> Pp.t
255-
256-
(** {6 Hash-consing } *)
257-
258-
val hcons_univ : Universe.t Hashcons.f
259-
val hcons_constraints : Constraints.t Hashcons.f
260-
val hcons_universe_set : Level.Set.t Hashcons.f
261-
val hcons_universe_context_set : ContextSet.t Hashcons.f

printing/printer.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ let universe_binders_with_opt_names orig names =
246246

247247
let pr_universe_ctx_set sigma c =
248248
if !Detyping.print_universes && not (Univ.ContextSet.is_empty c) then
249-
fnl()++pr_in_comment (v 0 (Univ.pr_universe_context_set (Termops.pr_evd_level sigma) c))
249+
fnl()++pr_in_comment (v 0 (Univ.ContextSet.pr (Termops.pr_evd_level sigma) c))
250250
else
251251
mt()
252252

@@ -268,7 +268,7 @@ let pr_abstract_universe_ctx sigma ?variance ?priv c =
268268
let prqvar u = Termops.pr_evd_qvar sigma u in
269269
let prlev u = Termops.pr_evd_level sigma u in
270270
let pub = (if has_priv then str "Public universes:" ++ fnl() else mt()) ++ v 0 (UVars.pr_abstract_universe_context prqvar prlev ?variance c) in
271-
let priv = if has_priv then fnl() ++ str "Private universes:" ++ fnl() ++ v 0 (Univ.pr_universe_context_set prlev priv) else mt() in
271+
let priv = if has_priv then fnl() ++ str "Private universes:" ++ fnl() ++ v 0 (Univ.ContextSet.pr prlev priv) else mt() in
272272
fnl()++pr_in_comment (pub ++ priv)
273273
else
274274
mt()

vernac/vernacentries.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ let show_universes ~proof =
172172
let ctx = Evd.universe_context_set (Evd.minimize_universes sigma) in
173173
UState.pr (Evd.ustate sigma) ++ fnl () ++
174174
v 1 (str "Normalized constraints:" ++ cut() ++
175-
Univ.pr_universe_context_set (Termops.pr_evd_level sigma) ctx)
175+
Univ.ContextSet.pr (Termops.pr_evd_level sigma) ctx)
176176

177177
(* Simulate the Intro(s) tactic *)
178178
let show_intro ~proof all =

0 commit comments

Comments
 (0)