Skip to content

Commit 04e69d1

Browse files
Merge PR #21424: Reduce the API reliance on PConstraints.ContextSet.t
Reviewed-by: SkySkimmer Co-authored-by: SkySkimmer <[email protected]>
2 parents fc6a92a + 80c2d13 commit 04e69d1

File tree

7 files changed

+37
-32
lines changed

7 files changed

+37
-32
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
overlay elpi https://github.com/ppedrot/coq-elpi chase-pconstraint-context-set 21424

engine/uState.ml

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ let context uctx =
473473
type named_universes_entry = universes_entry * UnivNames.universe_binders
474474

475475
let check_mono_sort_constraints uctx =
476-
let (uvar, (qcst, ucst)) = uctx in
476+
let (uvar, (qcst, ucst)) = uctx.local in
477477
(* This looks very stringent but it passes nonetheless all the tests? *)
478478
let () = assert (Sorts.ElimConstraints.is_empty qcst) in
479479
(uvar, ucst)
@@ -483,7 +483,7 @@ let univ_entry ~poly uctx =
483483
let entry =
484484
if poly then Polymorphic_entry (context uctx)
485485
else
486-
let uctx = check_mono_sort_constraints (context_set uctx) in
486+
let uctx = check_mono_sort_constraints uctx in
487487
Monomorphic_entry uctx
488488
in
489489
entry, binders
@@ -1091,18 +1091,20 @@ let check_template_univ_decl uctx ~template_qvars decl =
10911091
if not (QVar.Set.equal template_qvars (QState.undefined uctx.sort_variables))
10921092
then CErrors.anomaly Pp.(str "Bugged template univ declaration.")
10931093
in
1094+
(* XXX: when the kernel takes template entries closer to the polymorphic ones,
1095+
we should perform some additional checks here. *)
1096+
let () = assert (Sorts.ElimConstraints.is_empty decl.univdecl_elim_constraints) in
10941097
let levels, csts = uctx.local in
10951098
let () =
10961099
let prefix = decl.univdecl_instance in
10971100
if not decl.univdecl_extensible_instance
10981101
then check_universe_context_set ~prefix levels uctx.names
10991102
in
1100-
if decl.univdecl_extensible_constraints then uctx.local
1101-
else begin
1102-
check_implication uctx
1103-
(univ_decl_csts decl) csts;
1104-
levels, (decl.univdecl_elim_constraints,decl.univdecl_univ_constraints)
1105-
end
1103+
if decl.univdecl_extensible_constraints then
1104+
PConstraints.ContextSet.univ_context_set uctx.local
1105+
else
1106+
let () = check_implication uctx (univ_decl_csts decl) csts in
1107+
(levels, decl.univdecl_univ_constraints)
11061108

11071109
let check_mono_univ_decl uctx decl =
11081110
(* Note: if [decl] is [default_univ_decl], behave like [uctx.local] *)
@@ -1117,7 +1119,7 @@ let check_mono_univ_decl uctx decl =
11171119
if not decl.univdecl_extensible_instance
11181120
then check_universe_context_set ~prefix levels uctx.names
11191121
in
1120-
if decl.univdecl_extensible_constraints then check_mono_sort_constraints uctx.local
1122+
if decl.univdecl_extensible_constraints then check_mono_sort_constraints uctx
11211123
else
11221124
let () = assert (Sorts.ElimConstraints.is_empty (fst csts)) in
11231125
let () = check_implication uctx (univ_decl_csts decl) csts in
@@ -1156,12 +1158,10 @@ let check_univ_decl ~poly uctx decl =
11561158
in
11571159
entry, binders
11581160

1159-
let restrict_universe_context (univs, csts) keep =
1161+
let restrict_universe_context (univs, univ_csts) keep =
11601162
let removed = Level.Set.diff univs keep in
1161-
if Level.Set.is_empty removed then univs, csts
1163+
if Level.Set.is_empty removed then univs, univ_csts
11621164
else
1163-
let elim_csts = PConstraints.qualities csts in
1164-
let univ_csts = PConstraints.univs csts in
11651165
let allunivs = UnivConstraints.fold (fun (u,_,v) all -> Level.Set.add u (Level.Set.add v all)) univ_csts univs in
11661166
let g = UGraph.initial_universes in
11671167
let g = Level.Set.fold (fun v g ->
@@ -1171,17 +1171,21 @@ let restrict_universe_context (univs, csts) keep =
11711171
let allkept = Level.Set.union (UGraph.domain UGraph.initial_universes) (Level.Set.diff allunivs removed) in
11721172
let univ_csts = UGraph.constraints_for ~kept:allkept g in
11731173
let univ_csts = UnivConstraints.filter (fun (l,d,r) -> not (Level.is_set l && d == Le)) univ_csts in
1174-
(Level.Set.inter univs keep, PConstraints.make elim_csts univ_csts)
1174+
(Level.Set.inter univs keep, univ_csts)
1175+
1176+
let restrict_universe_pcontext (us, (qcst, ucst)) keep =
1177+
let (us, ucst) = restrict_universe_context (us, ucst) keep in
1178+
(us, (qcst, ucst))
11751179

11761180
let restrict uctx vars =
11771181
let vars = Id.Map.fold (fun na l vars -> Level.Set.add l vars)
11781182
(snd (fst uctx.names)) vars
11791183
in
1180-
let uctx' = restrict_universe_context uctx.local vars in
1184+
let uctx' = restrict_universe_pcontext uctx.local vars in
11811185
{ uctx with local = uctx' }
11821186

11831187
let restrict_even_binders uctx vars =
1184-
let uctx' = restrict_universe_context uctx.local vars in
1188+
let uctx' = restrict_universe_pcontext uctx.local vars in
11851189
{ uctx with local = uctx' }
11861190

11871191
let restrict_univ_constraints uctx csts =

engine/uState.mli

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ val name_level : Univ.Level.t -> Id.t -> t -> t
155155
the universes in [keep]. The constraints [csts] are adjusted so
156156
that transitive constraints between remaining universes (those in
157157
[keep] and those not in [univs]) are preserved. *)
158-
val restrict_universe_context : PConstraints.ContextSet.t -> Level.Set.t -> PConstraints.ContextSet.t
158+
val restrict_universe_context : Univ.ContextSet.t -> Level.Set.t -> Univ.ContextSet.t
159159

160160
(** [restrict uctx ctx] restricts the local universes of [uctx] to
161161
[ctx] extended by local named universes and side effect universes
@@ -267,9 +267,9 @@ val check_uctx_impl : fail:(Pp.t -> unit) -> t -> t -> unit
267267

268268
val check_mono_univ_decl : t -> universe_decl -> Univ.ContextSet.t
269269

270-
val check_template_univ_decl : t -> template_qvars:QVar.Set.t -> universe_decl -> PConstraints.ContextSet.t
270+
val check_template_univ_decl : t -> template_qvars:QVar.Set.t -> universe_decl -> Univ.ContextSet.t
271271

272-
val check_mono_sort_constraints : PConstraints.ContextSet.t -> Univ.ContextSet.t
272+
val check_mono_sort_constraints : t -> Univ.ContextSet.t
273273

274274
(** {5 TODO: Document me} *)
275275

plugins/ring/ring.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,7 @@ let decl_constant name univs c =
180180
let open Constr in
181181
let vars = CVars.universes_of_constr c in
182182
let univs = UState.restrict_universe_context univs vars in
183-
let () = Global.push_qualities QGraph.Static (PConstraints.ContextSet.sort_context_set univs) in (* XXX *)
184-
let () = Global.push_context_set (PConstraints.ContextSet.univ_context_set univs) in
183+
let () = Global.push_context_set univs in
185184
let types = (Typeops.infer (Global.env ()) c).uj_type in
186185
let univs = UState.Monomorphic_entry Univ.ContextSet.empty, UnivNames.empty_binders in
187186
(* UnsafeMonomorphic: we always do poly:false *)
@@ -236,7 +235,8 @@ let exec_tactic env sigma n f args =
236235
let ((), pv, _, _, _) = Proofview.apply ~name:(Id.of_string "ring") ~poly:false (Global.env ()) tac pv in
237236
let sigma = Evd.minimize_universes (Proofview.return pv) in
238237
let nf c = constr_of sigma c in
239-
Array.map nf !tactic_res, Evd.universe_context_set sigma
238+
let uctx = UState.check_mono_univ_decl (Evd.ustate sigma) UState.default_univ_decl in
239+
Array.map nf !tactic_res, uctx
240240

241241
let gen_constant n = (); fun () -> (EConstr.of_constr (UnivGen.constr_of_monomorphic_global (Global.env ()) (Rocqlib.lib_ref n)))
242242
let gen_reference n = (); fun () -> (Rocqlib.lib_ref n)

vernac/comInductive.ml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -535,15 +535,12 @@ let template_univ_entry sigma udecl ~template_univs pseudo_sort_poly =
535535
let uctx =
536536
UState.check_template_univ_decl (Evd.ustate sigma) ~template_qvars udecl
537537
in
538-
(* XXX: it should be fine to drop the sort constraints but it should be reflected in the API *)
539-
let elim_constraints = PConstraints.ContextSet.elim_constraints uctx in
540-
let uctx = PConstraints.ContextSet.univ_context_set uctx in
541538
let ubinders = UState.Monomorphic_entry uctx, Evd.universe_binders sigma in
542539
let template_univs, global = split_universe_context template_univs uctx in
543540
let uctx =
544541
UVars.UContext.of_context_set
545542
(UState.compute_instance_binders @@ Evd.ustate sigma)
546-
((template_qvars, elim_constraints), template_univs)
543+
((template_qvars, Sorts.ElimConstraints.empty), template_univs)
547544
in
548545
let default_univs =
549546
let inst = UVars.UContext.instance uctx in

vernac/declare.ml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ let instance_of_univs = function
227227

228228
let add_mono_uctx uctx = function
229229
| UState.Monomorphic_entry ctx, ubinders ->
230-
let uctx = UState.check_mono_sort_constraints @@ UState.context_set uctx in
230+
let uctx = UState.check_mono_sort_constraints uctx in
231231
UState.Monomorphic_entry (Univ.ContextSet.union uctx ctx), ubinders
232232
| UState.Polymorphic_entry _, _ as x -> assert (PConstraints.ContextSet.is_empty (UState.context_set uctx)); x
233233

@@ -273,8 +273,11 @@ let make_univs_immediate_private_poly ~uctx ~udecl ~eff ~used_univs body typ =
273273
let utyp = UState.check_univ_decl ~poly:true uctx' udecl in
274274
let ubody =
275275
let uctx = UState.restrict uctx used_univs in
276-
let uctx = PConstraints.ContextSet.diff (UState.context_set uctx) (UState.context_set uctx') in
277-
UState.check_mono_sort_constraints uctx
276+
let uctx = UState.context_set uctx in
277+
let uctx = PConstraints.ContextSet.diff uctx (UState.context_set uctx') in
278+
(* XXX we should have a more principled check somewhere *)
279+
let () = assert (Sorts.ElimConstraints.is_empty @@ PConstraints.ContextSet.elim_constraints uctx) in
280+
PConstraints.ContextSet.univ_context_set uctx
278281
in
279282
uctx', utyp, used_univs, Default { body = body; opaque = Opaque (ubody, eff) }
280283

@@ -1232,7 +1235,7 @@ module ProgramDecl = struct
12321235
else
12331236
(* declare global univs of the main constant before we do obligations *)
12341237
let uctx = UState.collapse_sort_variables uctx in
1235-
let ctx = UState.check_mono_sort_constraints @@ UState.context_set uctx in
1238+
let ctx = UState.check_mono_sort_constraints uctx in
12361239
let () = Global.push_context_set ctx in
12371240
let cst = Constant.make2 (Lib.current_mp()) cinfo.CInfo.name in
12381241
let () = DeclareUniv.declare_univ_binders (ConstRef cst)
@@ -2911,7 +2914,7 @@ let declare_entry ?loc ~name ?scope ~kind ?user_warns ?hook ~impargs ~uctx entry
29112914

29122915
let declare_definition_full ~info ~cinfo ~opaque ~body ?using sigma =
29132916
let c, uctx = declare_definition ~obls:[] ~info ~cinfo ~opaque ~body ?using sigma in
2914-
c, if info.poly then PConstraints.ContextSet.empty else UState.context_set uctx
2917+
c, if info.poly then Univ.ContextSet.empty else PConstraints.ContextSet.univ_context_set @@ UState.context_set uctx
29152918

29162919
let declare_definition ~info ~cinfo ~opaque ~body ?using sigma =
29172920
declare_definition ~obls:[] ~info ~cinfo ~opaque ~body ?using sigma |> fst

vernac/declare.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ val declare_definition_full
465465
-> body:EConstr.t
466466
-> ?using:Vernacexpr.section_subset_expr
467467
-> Evd.evar_map
468-
-> GlobRef.t * PConstraints.ContextSet.t
468+
-> GlobRef.t * Univ.ContextSet.t
469469

470470
(** Declaration messages, for internal use *)
471471

0 commit comments

Comments
 (0)