Debian Codegraph @

kernel/uVars.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 open Univ
12 open PConstraints
13 open Sorts
14
15 (** {6 Support for universe polymorphism } *)
16
17 module Variance :
18 sig
19 (** A universe position in the instance given to a cumulative
20 inductive can be the following. Note there is no Contravariant
21 case because [forall x : A, B <= forall x : A', B'] requires [A =
22 A'] as opposed to [A' <= A]. *)
23 type t = Irrelevant | Covariant | Invariant
24
25 (** [check_subtype x y] holds if variance [y] is also an instance of [x] *)
26 val check_subtype : t -> t -> bool
27
28 val sup : t -> t -> t
29
30 val pr : t -> Pp.t
31
32 val equal : t -> t -> bool
33
34 end
35
36 (** {6 Universe instances} *)
37
38 module Instance :
39 sig
40 type t
41 (** A universe instance represents a vector of argument universes
42 and sort qualities to a polymorphic definition
43 (constant, inductive or constructor). *)
44
45 val empty : t
46 val is_empty : t -> bool
47
48 val of_array : Quality.t array * Level.t array -> t
49 val to_array : t -> Quality.t array * Level.t array
50
51 val abstract_instance : int * int -> t
52 (** Instance of the given size made of QVar/Level.var *)
53
54 val append : t -> t -> t
55 (** To concatenate two instances, used for discharge *)
56
57 val equal : t -> t -> bool
58 (** Equality *)
59
60 val length : t -> int * int
61 (** Instance length *)
62
63 val hcons : t Hashcons.f
64 (** Hash-consing. *)
65
66 val hash : t -> int
67 (** Hash value *)
68
69 val pr : (QVar.t -> Pp.t) -> (Level.t -> Pp.t) -> ?variance:Variance.t array -> t -> Pp.t
70 (** Pretty-printing, no comments *)
71
72 val levels : t -> Quality.Set.t * Level.Set.t
73 (** The set of levels in the instance *)
74
75 val subst_fn
76 : (QVar.t -> Quality.t) * (Level.t -> Level.t)
77 -> t -> t
78
79 type ('q, 'u) mask = 'q Quality.pattern array * 'u array
80
81 val pattern_match : (int option, int option) mask -> t -> ('term, Quality.t, Level.t) Partial_subst.t -> ('term, Quality.t, Level.t) Partial_subst.t option
82 (** Pattern matching, as used by the rewrite rules mechanism *)
83 end
84
85 val eq_sizes : int * int -> int * int -> bool
86 (** Convenient function to compare the result of Instance.length, UContext.size etc *)
87
88 module QPairSet : CSig.SetS with type elt = (Quality.t * Quality.t)
89
90 type 'a pconstraints_function = 'a -> 'a -> QPairSet.t * UnivConstraints.t -> QPairSet.t * UnivConstraints.t
91
92 val enforce_eq_instances : Instance.t pconstraints_function
93
94 val enforce_eq_variance_instances : Variance.t array -> Instance.t pconstraints_function
95 val enforce_leq_variance_instances : Variance.t array -> Instance.t pconstraints_function
96
97 type 'a puniverses = 'a * Instance.t
98 val out_punivs : 'a puniverses -> 'a
99 val in_punivs : 'a -> 'a puniverses
100
101 val eq_puniverses : ('a -> 'a -> bool) -> 'a puniverses -> 'a puniverses -> bool
102
103
104 type bound_names = {
105 quals: Names.Name.t array;
106 univs: Names.Name.t array
107 }
108 val empty_bound_names : bound_names
109
110 (** A vector of universe levels with universe PConstraints.t,
111 representing local universe variables and associated PConstraints.t;
112 the names are user-facing names for printing *)
113
114 module UContext :
115 sig
116 type t
117
118 val make : bound_names -> Instance.t constrained -> t
119
120 val empty : t
121 val is_empty : t -> bool
122
123 val hcons : t -> int * t
124
125 val instance : t -> Instance.t
126 val constraints : t -> PConstraints.t
127 val univ_constraints : t -> UnivConstraints.t
128 val elim_constraints : t -> ElimConstraints.t
129
130 val union : t -> t -> t
131 (** Keeps the order of the instances *)
132
133 val size : t -> int * int
134 (** The number of universes in the context *)
135
136 val names : t -> bound_names
137 (** Return the user names of the universes *)
138
139 val refine_names : bound_names -> t -> t
140 (** Use names to name the possibly yet unnamed universes *)
141
142 val sort_levels : Level.t array -> Level.t array
143 (** Arbitrary choice of linear order of the variables *)
144
145 val sort_qualities : Quality.t array -> Quality.t array
146 (** Arbitrary choice of linear order of the variables *)
147
148 val of_context_set : (Instance.t -> bound_names) -> Sorts.QContextSet.t * Univ.ContextSet.t -> t
149 (** Build a vector of universe levels assuming a function generating names *)
150
151 val to_context_set : t -> Sorts.QContextSet.t * Univ.ContextSet.t
152 (** Discard the names and order of the universes *)
153
154 val pr : (QVar.t -> Pp.t) -> (Level.t -> Pp.t) -> ?variance:Variance.t array -> t -> Pp.t
155 end
156 (** A value in a universe context. *)
157 type 'a in_universe_context = 'a * UContext.t
158
159 module AbstractContext :
160 sig
161 type t
162 (** An abstract context serves to quantify over a graph of universes
163 represented using de Bruijn indices, as in:
164 u0, ..., u(n-1), Var i < Var j, .., Var k <= Var l |- term(Var 0 .. Var (n-1))
165 \-------------/ \-------------------------------/ \---------------------/
166 names for constraints expressed on de Bruijn judgement in abstract
167 printing representation of the n univ vars context expected to
168 use de Bruijn indices
169 *)
170
171 val make : bound_names -> PConstraints.t -> t
172 (** Build an abstract context. PConstraints may be between sorts/universe
173 variables. *)
174
175 val repr : t -> UContext.t
176 (** [repr ctx] is [(Var(0), ... Var(n-1) |= cstr] where [n] is the length of
177 the context and [cstr] the abstracted UnivConstraints.t. *)
178
179 val hcons : t -> int * t
180
181 val empty : t
182 val is_empty : t -> bool
183
184 val is_constant : t -> bool
185 (** Empty instance, but may have constraints *)
186
187 val size : t -> int * int
188
189 val union : t -> t -> t
190 (** The constraints are expected to be relative to the concatenated set of universes *)
191
192 val instantiate : Instance.t -> t -> PConstraints.t
193 (** Generate the set of instantiated PConstraints.t **)
194
195 val names : t -> bound_names
196 (** Return the names of the bound universe variables *)
197
198 val pr : (QVar.t -> Pp.t) -> (Level.t -> Pp.t) -> ?variance:Variance.t array -> t -> Pp.t
199 end
200
201 type 'a univ_abstracted = {
202 univ_abstracted_value : 'a;
203 univ_abstracted_binder : AbstractContext.t;
204 }
205 (** A value with bound universe levels. *)
206
207 val map_univ_abstracted : ('a -> 'b) -> 'a univ_abstracted -> 'b univ_abstracted
208
209 (** {6 Substitution} *)
210
211 type universe_level_subst = Level.t Level.Map.t
212 type sort_level_subst = Quality.t QVar.Map.t * universe_level_subst
213
214 val empty_level_subst : universe_level_subst
215 val is_empty_level_subst : universe_level_subst -> bool
216
217 (** Substitution of universes. *)
218 val subst_univs_level_level : universe_level_subst -> Level.t -> Level.t
219 val subst_univs_level_universe : universe_level_subst -> Universe.t -> Universe.t
220 val subst_univs_constraints : universe_level_subst -> Univ.UnivConstraints.t -> Univ.UnivConstraints.t
221 val subst_poly_constraints : sort_level_subst -> PConstraints.t -> PConstraints.t
222
223 val pr_universe_level_subst : (Level.t -> Pp.t) -> universe_level_subst -> Pp.t
224
225 val pr_quality_level_subst : (QVar.t -> Pp.t) -> Quality.t QVar.Map.t -> Pp.t
226
227 val empty_sort_subst : sort_level_subst
228
229 val is_empty_sort_subst : sort_level_subst -> bool
230
231 val subst_univs_level_abstract_universe_context :
232 sort_level_subst -> AbstractContext.t -> AbstractContext.t
233
234 (** There are no constraints on qualities, so this only needs a subst for univs *)
235
236 val subst_sort_level_instance : sort_level_subst -> Instance.t -> Instance.t
237 (** Level to universe substitutions. *)
238
239 val subst_sort_level_quality : sort_level_subst -> Quality.t -> Quality.t
240
241 val subst_sort_level_sort : sort_level_subst -> Sorts.t -> Sorts.t
242
243 val subst_sort_level_relevance : sort_level_subst -> relevance -> relevance
244
245 (** Substitution of instances *)
246 val subst_instance_instance : Instance.t -> Instance.t -> Instance.t
247 val subst_instance_universe : Instance.t -> Universe.t -> Universe.t
248 val subst_instance_quality : Instance.t -> Quality.t -> Quality.t
249 val subst_instance_sort : Instance.t -> Sorts.t -> Sorts.t
250 val subst_instance_relevance : Instance.t -> relevance -> relevance
251 val subst_instance_sort_level_subst : Instance.t -> sort_level_subst -> sort_level_subst
252
253 val make_instance_subst : Instance.t -> sort_level_subst
254 (** Creates [u(0) ↦ 0; ...; u(n-1) ↦ n - 1] out of [u(0); ...; u(n - 1)] *)
255
256 val abstract_universes : UContext.t -> Instance.t * AbstractContext.t
257 (** TODO: move universe abstraction out of the kernel *)
258
259 val make_abstract_instance : AbstractContext.t -> Instance.t