Debian Codegraph @

engine/uState.mli

raw symbols SCIP
1 (************************************************************************)
2 (* * The Rocq Prover / The Rocq Development Team *)
3 (* v * Copyright INRIA, CNRS and contributors *)
4 (* <O___,, * (see version control and CREDITS file for authors & dates) *)
5 (* \VV/ **************************************************************)
6 (* // * This file is distributed under the terms of the *)
7 (* * GNU Lesser General Public License Version 2.1 *)
8 (* * (see LICENSE file for the text of the license) *)
9 (************************************************************************)
10
11 (** This file defines universe unification states which are part of evarmaps.
12 Most of the API below is reexported in {!Evd}. Consider using higher-level
13 primitives when needed. *)
14
15 open Names
16 open Univ
17 open Sorts
18
19 type universes_entry =
20 | Monomorphic_entry of Univ.ContextSet.t
21 | Polymorphic_entry of UVars.UContext.t
22
23 exception UniversesDiffer
24
25 type t
26 (** Type of universe unification states. They allow the incremental building of
27 universe constraints during an interactive proof. *)
28
29 (** {5 Constructors} *)
30
31 (** Different ways to create a new universe state *)
32
33 val empty : t
34
35 val make : qualities:QGraph.t -> UGraph.t -> t
36 [@@ocaml.deprecated "(8.13) Use from_env"]
37
38 val make_with_initial_binders : qualities:QGraph.t -> UGraph.t -> lident list -> t
39 [@@ocaml.deprecated "(8.13) Use from_env"]
40
41 val from_env : ?binders:lident list -> Environ.env -> t
42 (** Main entry point at the beginning of a declaration declaring the
43 binding names as rigid universes. *)
44
45 val of_names : (UnivNames.universe_binders * UnivNames.rev_binders) -> t
46 (** Main entry point when only names matter, e.g. for printing. *)
47
48
49 (** Misc *)
50
51 val is_empty : t -> bool
52
53 val union : t -> t -> t
54
55 (** {5 Projections and other destructors} *)
56
57 val universe_context_set : t -> Univ.ContextSet.t
58
59 val sort_context_set : t -> UnivGen.sort_context_set
60 (** The local context of the state, i.e. a set of bound variables together
61 with their associated constraints. *)
62
63 type universe_opt_subst = UnivFlex.t
64 (* Reexport because UnivSubst is private *)
65
66 val subst : t -> UnivFlex.t
67 (** The local universes that are unification variables *)
68
69 val nf_universes : t -> Constr.t -> Constr.t
70 (** Apply the local substitution [subst] *)
71
72 val ugraph : t -> UGraph.t
73 (** The current graph extended with the local constraints *)
74
75 val elim_graph : t -> QGraph.t
76 (** The elimination graph for above prop variables *)
77
78 val is_above_prop : t -> Sorts.QVar.t -> bool
79
80 val is_algebraic : Level.t -> t -> bool
81 (** Can this universe be instantiated with an algebraic
82 universe (ie it appears in inferred types only). *)
83
84 val constraints : t -> PConstraints.t
85 (** Shorthand for {!context_set} composed with {!ContextSet.constraints}. *)
86
87 val context : t -> UVars.UContext.t
88 (** Shorthand for {!context_set} with {!Context_set.to_context}. *)
89
90 type named_universes_entry = universes_entry * UnivNames.universe_binders
91
92 val univ_entry : poly:PolyFlags.t -> t -> named_universes_entry
93 (** Pick from {!context} or {!context_set} based on [poly]. *)
94
95 val universe_binders : t -> UnivNames.universe_binders
96 (** Return local names of universes. *)
97
98 val compute_instance_binders : t -> UVars.Instance.t -> UVars.bound_names
99
100 val nf_qvar : t -> QVar.t -> Quality.t
101 (** Returns the normal form of the sort variable. *)
102
103 val nf_quality : t -> Quality.t -> Quality.t
104
105 val nf_instance : t -> UVars.Instance.t -> UVars.Instance.t
106
107 val nf_level : t -> Level.t -> Level.t
108 (** Must not be allowed to be algebraic *)
109
110 val nf_universe : t -> Universe.t -> Universe.t
111
112 val nf_sort : t -> Sorts.t -> Sorts.t
113 (** Returns the normal form of the sort. *)
114
115 val nf_relevance : t -> relevance -> relevance
116 (** Returns the normal form of the relevance. *)
117
118 (** {5 UnivConstraints handling} *)
119
120 type constraint_source =
121 | Internal
122 | Rigid
123 | Static
124 (** On an [Internal] enforcement, checks whether a path is created
125 between two ground/global sorts.
126 The [Rigid] [constraint_source] should be used for constraints entered by
127 the user. It allows to create paths between ground/global sorts, but
128 disables path creation between two ground sorts.
129 No additional check is performed on a [Static] constraint. *)
130
131 val add_univ_constraints : t -> Univ.UnivConstraints.t -> t
132 (**
133 @raise UniversesDiffer when universes differ
134 *)
135
136 val add_poly_constraints : ?src:constraint_source -> t -> PConstraints.t -> t
137
138 val add_constraints : ?src:constraint_source -> t -> UnivProblem.Set.t -> t
139 (**
140 @raise UniversesDiffer when universes differ
141 *)
142
143 val check_elim_constraints : t -> ElimConstraints.t -> bool
144
145 val check_constraints : t -> UnivProblem.Set.t -> bool
146
147 val check_eq_quality : t -> Sorts.Quality.t -> Sorts.Quality.t -> bool
148
149 (** {5 Names} *)
150
151 val quality_of_name : t -> Id.t -> Sorts.QVar.t
152
153 val universe_of_name : t -> Id.t -> Univ.Level.t
154 (** Retrieve the universe associated to the name. *)
155
156
157 val name_level : Univ.Level.t -> Id.t -> t -> t
158 (** Gives a name to the level (making it a binder).
159 Asserts the name is not already used by a level *)
160
161 (** {5 Unification} *)
162
163 (** [restrict_universe_context (univs,csts) keep] restricts [univs] to
164 the universes in [keep]. The constraints [csts] are adjusted so
165 that transitive constraints between remaining universes (those in
166 [keep] and those not in [univs]) are preserved. *)
167 val restrict_universe_context : Univ.ContextSet.t -> Level.Set.t -> Univ.ContextSet.t
168
169 (** [restrict uctx ctx] restricts the local universes of [uctx] to
170 [ctx] extended by local named universes and side effect universes
171 (from [demote_seff_univs]). Transitive constraints between retained
172 universes are preserved. *)
173 val restrict : t -> Univ.Level.Set.t -> t
174
175
176 (** [restrict_even_binders uctx ctx] restricts the local universes of [uctx] to
177 [ctx] extended by side effect universes
178 (from [demote_seff_univs]). Transitive constraints between retained
179 universes are preserved. *)
180 val restrict_even_binders : t -> Univ.Level.Set.t -> t
181
182 type rigid =
183 | UnivRigid
184 | UnivFlexible of bool (** Is substitution by an algebraic ok? *)
185
186 val univ_rigid : rigid
187 val univ_flexible : rigid
188 val univ_flexible_alg : rigid
189
190 val merge_sort_context : ?loc:Loc.t -> ?sort_rigid:bool -> ?src:constraint_source ->
191 sideff:bool -> rigid -> t -> UnivGen.sort_context_set -> t
192 val merge_universe_context : ?loc:Loc.t -> sideff:bool -> rigid -> t -> Univ.ContextSet.t -> t
193
194 val demote_global_univs : Univ.ContextSet.t -> t -> t
195 (** After declaring global universes, call this if you want to keep using the UState.
196
197 Removes from the uctx_local part of the UState the universes
198 that are present in the input constraint set (supposedly the global ones),
199 and adds any new universes and constraints to the UGraph part of the UState.
200 *)
201
202 val demote_global_univ_entry : universes_entry -> t -> t
203 (** After declaring a global, call this with its universe entry
204 if you want to keep using the ustate instead of restarting it
205 with [from_env (Global.env())] or using the slow
206 [update_sigma_univs _ (Environ.universes (Global/env()))].
207
208 Equivalently:
209 - In the monomorphic case, call [demote_global_univs] on the contextset.
210 - In the polymorphic case, do nothing.
211 *)
212
213 val emit_side_effects : Safe_typing.private_constants -> t -> t
214 (** Calls [demote_global_univs] for the private constant universes. *)
215
216 val new_sort_variable : ?loc:Loc.t -> ?sort_rigid:bool -> ?name:Id.t -> t -> t * QVar.t
217 (** Declare a new local sort. *)
218
219 val new_univ_variable : ?loc:Loc.t -> rigid -> Id.t option -> t -> t * Univ.Level.t
220 (** Declare a new local universe; use rigid if a global or bound
221 universe; use flexible for a universe existential variable; use
222 univ_flexible_alg for a universe existential variable allowed to
223 be instantiated with an algebraic universe *)
224
225 val add_forgotten_univ : t -> Univ.Level.t -> t
226 (** Don't use this, it only exists for funind *)
227
228 val make_nonalgebraic_variable : t -> Univ.Level.t -> t
229 (** cf UnivFlex *)
230
231 val make_flexible_nonalgebraic : t -> t
232 (** cf UnivFlex *)
233
234 val normalize_variables : t -> t
235
236 val constrain_variables : Univ.Level.Set.t -> t -> t
237
238 val fix_undefined_variables : t -> t
239 (** cf UnivFlex *)
240
241 (** Universe minimization *)
242 val minimize : t -> t
243
244 val collapse_above_prop_sort_variables : to_prop:bool -> t -> t
245
246 val collapse_sort_variables : ?except:QVar.Set.t -> t -> t
247
248 type ('a, 'b, 'c, 'd) gen_universe_decl = {
249 univdecl_qualities : 'a;
250 univdecl_extensible_qualities : bool;
251 univdecl_elim_constraints : 'b;
252 univdecl_instance : 'c; (* Declared universes *)
253 univdecl_extensible_instance : bool; (* Can new universes be added *)
254 univdecl_univ_constraints : 'd; (* Declared univ constraints *)
255 univdecl_extensible_constraints : bool; (* Can new constraints (elim or univ) be added *) }
256
257 type universe_decl =
258 (QVar.t list, Sorts.ElimConstraints.t, Level.t list, Univ.UnivConstraints.t) gen_universe_decl
259
260 val default_univ_decl : universe_decl
261
262 (** [check_poly_decl ctx decl]
263
264 If non extensible in [decl], check that the local universes (resp.
265 universe constraints) in [ctx] are implied by [decl].
266
267 Return a [universes_entry] containing the local
268 universes of [ctx] and their constraints.
269
270 When polymorphic, the universes corresponding to
271 [decl.univdecl_instance] come first in the order defined by that
272 list. *)
273 val check_univ_decl : poly:PolyFlags.t -> t -> universe_decl -> named_universes_entry
274 val check_univ_decl_rev : t -> universe_decl -> t * UVars.UContext.t
275 val check_uctx_impl : fail:(Pp.t -> unit) -> t -> t -> unit
276
277 val check_mono_univ_decl : t -> universe_decl -> Univ.ContextSet.t
278
279 val check_template_univ_decl : t -> template_qvars:QVar.Set.t -> universe_decl -> Univ.ContextSet.t
280
281 val check_mono_sort_constraints : t -> Univ.ContextSet.t
282
283 (** {5 TODO: Document me} *)
284
285 val update_sigma_univs : t -> UGraph.t -> t
286
287 (** {5 Pretty-printing} *)
288
289 val pr_uctx_level : t -> Univ.Level.t -> Pp.t
290 val pr_uctx_qvar : t -> Sorts.QVar.t -> Pp.t
291 val qualid_of_level : t -> Univ.Level.t -> Libnames.qualid option
292
293 (** Only looks in the local names, not in the nametab. *)
294 val id_of_level : t -> Univ.Level.t -> Id.t option
295
296 val id_of_qvar : t -> Sorts.QVar.t -> Id.t option
297
298 val is_rigid_qvar : t -> Sorts.QVar.t -> bool
299
300 val pr_weak : (Univ.Level.t -> Pp.t) -> t -> Pp.t
301
302 val pr : t -> Pp.t
303
304 val pr_sort_opt_subst : t -> Pp.t
305
306 module Internal :
307 sig
308
309 val reboot : Environ.env -> t -> t
310 (** Madness-inducing hack dedicated to the handling of universes of Program.
311 DO NOT USE OUTSIDE OF DEDICATED AREA. *)
312
313 end
314
315 val add_template_default_univs : Environ.env -> MutInd.t -> unit