Skip to content

Commit 2faba2a

Browse files
Merge PR #19985: Stop using lbound:Prop
Reviewed-by: ppedrot Co-authored-by: ppedrot <[email protected]>
2 parents c763d93 + 189bfaf commit 2faba2a

File tree

17 files changed

+308
-200
lines changed

17 files changed

+308
-200
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
overlay lean_importer https://github.com/SkySkimmer/coq-lean-import cominductive-lbound 19985

engine/evd.ml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,8 +1063,8 @@ let check_univ_decl_early ~poly ~with_obls sigma udecl terms =
10631063
let uctx = UState.restrict uctx vars in
10641064
ignore (UState.check_univ_decl ~poly uctx udecl)
10651065

1066-
let restrict_universe_context ?lbound evd vars =
1067-
{ evd with universes = UState.restrict ?lbound evd.universes vars }
1066+
let restrict_universe_context evd vars =
1067+
{ evd with universes = UState.restrict evd.universes vars }
10681068

10691069
let universe_subst evd =
10701070
UState.subst evd.universes
@@ -1211,10 +1211,13 @@ let collapse_sort_variables evd =
12111211
let universes = UState.collapse_sort_variables evd.universes in
12121212
{ evd with universes }
12131213

1214-
let minimize_universes ?lbound evd =
1215-
let uctx' = UState.collapse_sort_variables evd.universes in
1214+
let minimize_universes ?(collapse_sort_variables=true) evd =
1215+
let uctx' = if collapse_sort_variables
1216+
then UState.collapse_sort_variables evd.universes
1217+
else evd.universes
1218+
in
12161219
let uctx' = UState.normalize_variables uctx' in
1217-
let uctx' = UState.minimize ?lbound uctx' in
1220+
let uctx' = UState.minimize uctx' in
12181221
{evd with universes = uctx'}
12191222

12201223
let universe_of_name evd s = UState.universe_of_name evd.universes s

engine/evd.mli

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ val univ_flexible_alg : rigid
535535

536536
type 'a in_ustate = 'a * UState.t
537537

538-
val restrict_universe_context : ?lbound:UGraph.Bound.t -> evar_map -> Univ.Level.Set.t -> evar_map
538+
val restrict_universe_context : evar_map -> Univ.Level.Set.t -> evar_map
539539

540540
(** Raises Not_found if not a name for a universe in this map. *)
541541
val universe_of_name : evar_map -> Id.t -> Univ.Level.t
@@ -616,8 +616,8 @@ val collapse_sort_variables : evar_map -> evar_map
616616

617617
val fix_undefined_variables : evar_map -> evar_map
618618

619-
(** Universe minimization *)
620-
val minimize_universes : ?lbound:UGraph.Bound.t -> evar_map -> evar_map
619+
(** Universe minimization (collapse_sort_variables is true by default) *)
620+
val minimize_universes : ?collapse_sort_variables:bool -> evar_map -> evar_map
621621

622622
(** Lift [UState.update_sigma_univs] *)
623623
val update_sigma_univs : UGraph.t -> evar_map -> evar_map

engine/uState.ml

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ let empty =
238238
initial_universes = UGraph.initial_universes;
239239
minim_extra = UnivMinim.empty_extra; }
240240

241-
let make ~lbound univs =
241+
let make univs =
242242
{ empty with
243243
universes = univs;
244244
initial_universes = univs }
@@ -313,7 +313,7 @@ let union uctx uctx' =
313313
let newus = Level.Set.diff newus (UnivFlex.domain uctx.univ_variables) in
314314
let extra = UnivMinim.extra_union uctx.minim_extra uctx'.minim_extra in
315315
let declarenew g =
316-
Level.Set.fold (fun u g -> UGraph.add_universe u ~lbound:UGraph.Bound.Set ~strict:false g) newus g
316+
Level.Set.fold (fun u g -> UGraph.add_universe u ~strict:false g) newus g
317317
in
318318
let fail_union s q1 q2 =
319319
if UGraph.type_in_type uctx.universes then s
@@ -944,33 +944,30 @@ let check_univ_decl ~poly uctx decl =
944944
else Monomorphic_entry (check_mono_univ_decl uctx decl) in
945945
entry, binders
946946

947-
let is_bound l lbound = match lbound with
948-
| UGraph.Bound.Prop -> false
949-
| UGraph.Bound.Set -> Level.is_set l
950-
951-
let restrict_universe_context ?(lbound = UGraph.Bound.Set) (univs, csts) keep =
947+
let restrict_universe_context (univs, csts) keep =
952948
let removed = Level.Set.diff univs keep in
953949
if Level.Set.is_empty removed then univs, csts
954950
else
955951
let allunivs = Constraints.fold (fun (u,_,v) all -> Level.Set.add u (Level.Set.add v all)) csts univs in
956952
let g = UGraph.initial_universes in
957-
let g = Level.Set.fold (fun v g -> if Level.is_set v then g else
958-
UGraph.add_universe v ~lbound ~strict:false g) allunivs g in
953+
let g = Level.Set.fold (fun v g ->
954+
if Level.is_set v then g else
955+
UGraph.add_universe v ~strict:false g) allunivs g in
959956
let g = UGraph.merge_constraints csts g in
960957
let allkept = Level.Set.union (UGraph.domain UGraph.initial_universes) (Level.Set.diff allunivs removed) in
961958
let csts = UGraph.constraints_for ~kept:allkept g in
962-
let csts = Constraints.filter (fun (l,d,r) -> not (is_bound l lbound && d == Le)) csts in
959+
let csts = Constraints.filter (fun (l,d,r) -> not (Level.is_set l && d == Le)) csts in
963960
(Level.Set.inter univs keep, csts)
964961

965-
let restrict ?lbound uctx vars =
962+
let restrict uctx vars =
966963
let vars = Id.Map.fold (fun na l vars -> Level.Set.add l vars)
967964
(snd (fst uctx.names)) vars
968965
in
969-
let uctx' = restrict_universe_context ?lbound uctx.local vars in
966+
let uctx' = restrict_universe_context uctx.local vars in
970967
{ uctx with local = uctx' }
971968

972-
let restrict_even_binders ?lbound uctx vars =
973-
let uctx' = restrict_universe_context ?lbound uctx.local vars in
969+
let restrict_even_binders uctx vars =
970+
let uctx' = restrict_universe_context uctx.local vars in
974971
{ uctx with local = uctx' }
975972

976973
let restrict_constraints uctx csts =
@@ -994,7 +991,7 @@ let merge ?loc ~sideff rigid uctx uctx' =
994991
let local = ContextSet.append uctx' uctx.local in
995992
let declare g =
996993
Level.Set.fold (fun u g ->
997-
try UGraph.add_universe ~lbound:UGraph.Bound.Set ~strict:false u g
994+
try UGraph.add_universe ~strict:false u g
998995
with UGraph.AlreadyDeclared when sideff -> g)
999996
levels g
1000997
in
@@ -1055,7 +1052,7 @@ let demote_global_univs (lvl_set,csts_set) uctx =
10551052
let univ_variables = Level.Set.fold UnivFlex.remove lvl_set uctx.univ_variables in
10561053
let update_ugraph g =
10571054
let g = Level.Set.fold (fun u g ->
1058-
try UGraph.add_universe u ~lbound:Set ~strict:true g
1055+
try UGraph.add_universe u ~strict:true g
10591056
with UGraph.AlreadyDeclared -> g)
10601057
lvl_set
10611058
g
@@ -1080,7 +1077,7 @@ let merge_seff uctx uctx' =
10801077
let levels = ContextSet.levels uctx' in
10811078
let declare g =
10821079
Level.Set.fold (fun u g ->
1083-
try UGraph.add_universe ~lbound:UGraph.Bound.Set ~strict:false u g
1080+
try UGraph.add_universe ~strict:false u g
10841081
with UGraph.AlreadyDeclared -> g)
10851082
levels g
10861083
in
@@ -1122,9 +1119,8 @@ let add_loc l loc (names, (qnames_rev,unames_rev) as orig) =
11221119
| Some _ -> (names, (qnames_rev, Level.Map.add l { uname = None; uloc = loc } unames_rev))
11231120

11241121
let add_universe ?loc name strict uctx u =
1125-
let lbound = UGraph.Bound.Set in
1126-
let initial_universes = UGraph.add_universe ~lbound ~strict u uctx.initial_universes in
1127-
let universes = UGraph.add_universe ~lbound ~strict u uctx.universes in
1122+
let initial_universes = UGraph.add_universe ~strict u uctx.initial_universes in
1123+
let universes = UGraph.add_universe ~strict u uctx.universes in
11281124
let local = ContextSet.add_universe u uctx.local in
11291125
let names =
11301126
match name with
@@ -1159,15 +1155,15 @@ let new_univ_variable ?loc rigid name uctx =
11591155

11601156
let add_forgotten_univ uctx u = add_universe None true uctx u
11611157

1162-
let make_with_initial_binders ~lbound univs binders =
1163-
let uctx = make ~lbound univs in
1158+
let make_with_initial_binders univs binders =
1159+
let uctx = make univs in
11641160
List.fold_left
11651161
(fun uctx { CAst.loc; v = id } ->
11661162
fst (new_univ_variable ?loc univ_rigid (Some id) uctx))
11671163
uctx binders
11681164

11691165
let from_env ?(binders=[]) env =
1170-
make_with_initial_binders ~lbound:UGraph.Bound.Set (Environ.universes env) binders
1166+
make_with_initial_binders (Environ.universes env) binders
11711167

11721168
let make_nonalgebraic_variable uctx u =
11731169
{ uctx with univ_variables = UnivFlex.make_nonalgebraic_variable uctx.univ_variables u }
@@ -1198,10 +1194,10 @@ let collapse_above_prop_sort_variables ~to_prop uctx =
11981194
let collapse_sort_variables uctx =
11991195
{ uctx with sort_variables = QState.collapse uctx.sort_variables }
12001196

1201-
let minimize ?(lbound = UGraph.Bound.Set) uctx =
1197+
let minimize uctx =
12021198
let open UnivMinim in
12031199
let (vars', us') =
1204-
normalize_context_set ~lbound uctx.universes uctx.local uctx.univ_variables
1200+
normalize_context_set uctx.universes uctx.local uctx.univ_variables
12051201
uctx.minim_extra
12061202
in
12071203
if ContextSet.equal us' uctx.local then uctx

engine/uState.mli

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ type t
3232

3333
val empty : t
3434

35-
val make : lbound:UGraph.Bound.t -> UGraph.t -> t
35+
val make : UGraph.t -> t
3636
[@@ocaml.deprecated "(8.13) Use from_env"]
3737

38-
val make_with_initial_binders : lbound:UGraph.Bound.t -> UGraph.t -> lident list -> t
38+
val make_with_initial_binders : UGraph.t -> lident list -> t
3939
[@@ocaml.deprecated "(8.13) Use from_env"]
4040

4141
val from_env : ?binders:lident list -> Environ.env -> t
@@ -143,24 +143,24 @@ val name_level : Univ.Level.t -> Id.t -> t -> t
143143

144144
(** {5 Unification} *)
145145

146-
(** [restrict_universe_context lbound (univs,csts) keep] restricts [univs] to
146+
(** [restrict_universe_context (univs,csts) keep] restricts [univs] to
147147
the universes in [keep]. The constraints [csts] are adjusted so
148148
that transitive constraints between remaining universes (those in
149149
[keep] and those not in [univs]) are preserved. *)
150-
val restrict_universe_context : ?lbound:UGraph.Bound.t -> ContextSet.t -> Level.Set.t -> ContextSet.t
150+
val restrict_universe_context : ContextSet.t -> Level.Set.t -> ContextSet.t
151151

152152
(** [restrict uctx ctx] restricts the local universes of [uctx] to
153153
[ctx] extended by local named universes and side effect universes
154154
(from [demote_seff_univs]). Transitive constraints between retained
155155
universes are preserved. *)
156-
val restrict : ?lbound:UGraph.Bound.t -> t -> Univ.Level.Set.t -> t
156+
val restrict : t -> Univ.Level.Set.t -> t
157157

158158

159159
(** [restrict_even_binders uctx ctx] restricts the local universes of [uctx] to
160160
[ctx] extended by side effect universes
161161
(from [demote_seff_univs]). Transitive constraints between retained
162162
universes are preserved. *)
163-
val restrict_even_binders : ?lbound:UGraph.Bound.t -> t -> Univ.Level.Set.t -> t
163+
val restrict_even_binders : t -> Univ.Level.Set.t -> t
164164

165165
type rigid =
166166
| UnivRigid
@@ -222,7 +222,7 @@ val fix_undefined_variables : t -> t
222222
(** cf UnivFlex *)
223223

224224
(** Universe minimization *)
225-
val minimize : ?lbound:UGraph.Bound.t -> t -> t
225+
val minimize : t -> t
226226

227227
val collapse_above_prop_sort_variables : to_prop:bool -> t -> t
228228

engine/univMinim.ml

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ let extra_union a b = {
306306
above_prop = Level.Set.union a.above_prop b.above_prop;
307307
}
308308

309-
let normalize_context_set ~lbound g ctx (us:UnivFlex.t) {weak_constraints=weak;above_prop} =
309+
let normalize_context_set g ctx (us:UnivFlex.t) {weak_constraints=weak;above_prop} =
310310
let (ctx, csts) = ContextSet.levels ctx, ContextSet.constraints ctx in
311311
(* Keep the Set <= i constraints separate *)
312312
let smallles, csts =
@@ -338,11 +338,9 @@ let normalize_context_set ~lbound g ctx (us:UnivFlex.t) {weak_constraints=weak;a
338338
else acc)
339339
weak (smallles, csts, g)
340340
in
341-
let smallles = match (lbound : UGraph.Bound.t) with
342-
| Prop -> smallles
343-
| Set when get_set_minimization () ->
341+
let smallles = if get_set_minimization () then
344342
Constraints.filter (fun (l,d,r) -> UnivFlex.mem r us) smallles
345-
| Set -> Constraints.empty (* constraints Set <= u may be dropped *)
343+
else Constraints.empty (* constraints Set <= u may be dropped *)
346344
in
347345
let smallles = if get_set_minimization() then
348346
let fold u accu = if UnivFlex.mem u us then Constraints.add (Level.set, Le, u) accu else accu in
@@ -354,12 +352,12 @@ let normalize_context_set ~lbound g ctx (us:UnivFlex.t) {weak_constraints=weak;a
354352
to equalities. *)
355353
let g = UGraph.initial_universes_with g in
356354
(* use lbound:Set to collapse [u <= v <= Set] into [u = v = Set] *)
357-
let g = Level.Set.fold (fun v g -> UGraph.add_universe ~lbound:Set ~strict:false v g)
355+
let g = Level.Set.fold (fun v g -> UGraph.add_universe ~strict:false v g)
358356
ctx g
359357
in
360358
let add_soft u g =
361359
if not (Level.is_set u || Level.Set.mem u ctx)
362-
then try UGraph.add_universe ~lbound:Set ~strict:false u g with UGraph.AlreadyDeclared -> g
360+
then try UGraph.add_universe ~strict:false u g with UGraph.AlreadyDeclared -> g
363361
else g
364362
in
365363
let g = Constraints.fold

engine/univMinim.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ val extra_union : extra -> extra -> extra
3333
(a global one if there is one) and transitively saturate
3434
the constraints w.r.t to the equalities. *)
3535

36-
val normalize_context_set : lbound:UGraph.Bound.t -> UGraph.t -> ContextSet.t ->
36+
val normalize_context_set : UGraph.t -> ContextSet.t ->
3737
UnivFlex.t (* The defined and undefined variables *) ->
3838
extra ->
3939
UnivFlex.t in_universe_context_set

kernel/declareops.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ let map_decl_arity f g = function
4949
| TemplateArity a -> TemplateArity (g a)
5050

5151
let hcons_template_arity ar =
52-
{ template_level = Sorts.hcons ar.template_level; }
52+
{ template_level = Sorts.hcons ar.template_level;
53+
}
5354

5455
let hcons_template_universe ar =
5556
{ template_param_arguments = ar.template_param_arguments;

kernel/environ.ml

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -459,10 +459,10 @@ let add_constraints c env =
459459
let check_constraints c env =
460460
UGraph.check_constraints c env.env_universes
461461

462-
let add_universes ~lbound ~strict ctx g =
462+
let add_universes ~strict ctx g =
463463
let _qs, us = UVars.Instance.to_array (UVars.UContext.instance ctx) in
464464
let g = Array.fold_left
465-
(fun g v -> UGraph.add_universe ~lbound ~strict v g)
465+
(fun g v -> UGraph.add_universe ~strict v g)
466466
g us
467467
in
468468
UGraph.merge_constraints (UVars.UContext.constraints ctx) g
@@ -482,24 +482,21 @@ let add_qualities qs known =
482482
let push_context ?(strict=false) ctx env =
483483
let qs, _us = UVars.Instance.to_array (UVars.UContext.instance ctx) in
484484
let env = { env with env_qualities = add_qualities qs env.env_qualities } in
485-
map_universes (add_universes ~lbound:UGraph.Bound.Set ~strict ctx) env
485+
map_universes (add_universes ~strict ctx) env
486486

487-
let add_universes_set ~lbound ~strict ctx g =
487+
let add_universes_set ~strict ctx g =
488488
let g = Univ.Level.Set.fold
489489
(* Be lenient, module typing reintroduces universes and constraints due to includes *)
490-
(fun v g -> try UGraph.add_universe ~lbound ~strict v g with UGraph.AlreadyDeclared -> g)
490+
(fun v g -> try UGraph.add_universe ~strict v g with UGraph.AlreadyDeclared -> g)
491491
(Univ.ContextSet.levels ctx) g
492492
in UGraph.merge_constraints (Univ.ContextSet.constraints ctx) g
493493

494494
let push_context_set ?(strict=false) ctx env =
495-
map_universes (add_universes_set ~lbound:UGraph.Bound.Set ~strict ctx) env
496-
497-
let push_floating_context_set ctx env =
498-
map_universes (add_universes_set ~lbound:UGraph.Bound.Prop ~strict:false ctx) env
495+
map_universes (add_universes_set ~strict ctx) env
499496

500497
let push_subgraph (levels,csts) env =
501498
let add_subgraph g =
502-
let newg = Univ.Level.Set.fold (fun v g -> UGraph.add_universe ~lbound:UGraph.Bound.Set ~strict:false v g) levels g in
499+
let newg = Univ.Level.Set.fold (fun v g -> UGraph.add_universe ~strict:false v g) levels g in
503500
let newg = UGraph.merge_constraints csts newg in
504501
(if not (Univ.Constraints.is_empty csts) then
505502
let restricted = UGraph.constraints_for ~kept:(UGraph.domain g) newg in

kernel/environ.mli

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -372,9 +372,6 @@ val push_context_set : ?strict:bool -> ContextSet.t -> env -> env
372372
context set to the environment. It does not fail even if one of the
373373
universes is already declared. *)
374374

375-
val push_floating_context_set : ContextSet.t -> env -> env
376-
(** Same as above but keep the universes floating for template. Do not use. *)
377-
378375
val push_subgraph : ContextSet.t -> env -> env
379376
(** [push_subgraph univs env] adds the universes and constraints in
380377
[univs] to [env] as [push_context_set ~strict:false univs env], and

0 commit comments

Comments
 (0)