Debian Codegraph @

engine/termops.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 various utilities for term manipulation that are not
12 needed in the kernel. *)
13
14 open Names
15 open Constr
16 open Environ
17 open EConstr
18
19 (** about contexts *)
20 val push_rel_assum : Name.t EConstr.binder_annot * types -> env -> env
21 val push_rels_assum : (Name.t Constr.binder_annot * Constr.types) list -> env -> env
22 val push_named_rec_types : Name.t Constr.binder_annot array * Constr.types array * 'a -> env -> env
23
24 val lookup_rel_id : Id.t -> ('c, 't, 'r) Context.Rel.pt -> int * 'c option * 't
25 (** Associates the contents of an identifier in a [rel_context]. Raise
26 [Not_found] if there is no such identifier. *)
27
28 (** Functions that build argument lists matching a block of binders or a context.
29 [rel_vect n m] builds [|Rel (n+m);...;Rel(n+1)|]
30 *)
31 val rel_vect : int -> int -> Constr.constr array
32 val rel_list : int -> int -> constr list
33
34 (** Prod/Lambda/LetIn destructors on constr *)
35
36 val it_mkNamedProd_wo_LetIn : Constr.types -> Constr.named_context -> Constr.types
37
38 (* Ad hoc version reinserting letin, assuming the body is defined in
39 the context where the letins are expanded *)
40 val it_mkLambda_or_LetIn_from_no_LetIn : Constr.constr -> Constr.rel_context -> Constr.constr
41
42 (** {6 Generic iterators on constr} *)
43
44 val map_constr_with_binders_left_to_right :
45 Environ.env -> Evd.evar_map ->
46 (rel_declaration -> 'a -> 'a) ->
47 ('a -> constr -> constr) ->
48 'a -> constr -> constr
49 val map_constr_with_full_binders :
50 Environ.env -> Evd.evar_map ->
51 (rel_declaration -> 'a -> 'a) ->
52 ('a -> constr -> constr) -> 'a -> constr -> constr
53
54 val fold_constr_with_full_binders : Environ.env -> Evd.evar_map ->
55 (rel_declaration -> 'a -> 'a) ->
56 ('a -> 'b -> constr -> 'b) ->
57 'a -> 'b -> constr -> 'b
58
59 (**********************************************************************)
60
61 val strip_head_cast : Evd.evar_map -> constr -> constr
62 val drop_extra_implicit_args : Evd.evar_map -> constr -> constr
63
64 (** occur checks *)
65
66 exception Occur
67 val occur_meta : Evd.evar_map -> constr -> bool
68 val occur_existential : Evd.evar_map -> constr -> bool
69 val occur_meta_or_existential : Evd.evar_map -> constr -> bool
70 val occur_metavariable : Evd.evar_map -> metavariable -> constr -> bool
71 val occur_evar : Evd.evar_map -> Evar.t -> constr -> bool
72 val occur_var : env -> Evd.evar_map -> Id.t -> constr -> bool
73 val occur_var_indirectly : env -> Evd.evar_map -> Id.t -> constr -> GlobRef.t option
74 val occur_var_in_decl : env -> Evd.evar_map -> Id.t -> named_declaration -> bool
75 val occur_vars : env -> Evd.evar_map -> Id.Set.t -> constr -> bool
76 val occur_vars_in_decl : env -> Evd.evar_map -> Id.Set.t -> named_declaration -> bool
77
78 (** As {!occur_var} but assume the identifier not to be a section variable *)
79 val local_occur_var : Evd.evar_map -> Id.t -> constr -> bool
80 val local_occur_var_in_decl : Evd.evar_map -> Id.t -> named_declaration -> bool
81
82 val free_rels : Evd.evar_map -> constr -> Int.Set.t
83
84 (* Return the list of unbound rels and unqualified reference (same
85 strategy as in Namegen) *)
86 val free_rels_and_unqualified_refs : Evd.evar_map -> constr -> Int.Set.t * Id.Set.t
87
88 (** [dependent m t] tests whether [m] is a subterm of [t] *)
89 val dependent : Evd.evar_map -> constr -> constr -> bool
90 val dependent_no_evar : Evd.evar_map -> constr -> constr -> bool
91 val dependent_in_decl : Evd.evar_map -> constr -> named_declaration -> bool
92 val count_occurrences : Evd.evar_map -> constr -> constr -> int
93 val collect_metas : Evd.evar_map -> constr -> int list
94 val collect_vars : Evd.evar_map -> constr -> Id.Set.t (** for visible vars only *)
95
96 (* Substitution of metavariables *)
97 type meta_value_map = (metavariable * Constr.constr) list
98 val subst_meta : meta_value_map -> Constr.constr -> Constr.constr
99 val isMetaOf : Evd.evar_map -> metavariable -> constr -> bool
100
101 (** Type assignment for metavariables *)
102 type meta_type_map = (metavariable * Constr.types) list
103
104 (** [pop c] lifts by -1 the positive indexes in [c] *)
105 val pop : constr -> constr
106
107 (** {6 ... } *)
108 (** Substitution of an arbitrary large term. Uses equality modulo
109 reduction of let *)
110
111 (** [replace_term_gen eq arity e c] replaces matching subterms according to
112 [eq] by [e] in [c]. If [arity] is non-zero applications of larger length
113 are handled atomically. *)
114 val replace_term_gen :
115 Evd.evar_map -> (Evd.evar_map -> int -> constr -> bool) ->
116 int -> constr -> constr -> constr
117
118 (** [subst_term d c] replaces [d] by [Rel 1] in [c] *)
119 val subst_term : Evd.evar_map -> constr -> constr -> constr
120
121 (** [replace_term d e c] replaces [d] by [e] in [c] *)
122 val replace_term : Evd.evar_map -> constr -> constr -> constr -> constr
123
124 (** Alternative term equalities *)
125 val base_sort_cmp : Conversion.conv_pb -> Sorts.t -> Sorts.t -> bool
126 val compare_constr_univ : Environ.env -> Evd.evar_map -> (Conversion.conv_pb -> constr -> constr -> bool) ->
127 Conversion.conv_pb -> constr -> constr -> bool
128 val constr_cmp : Environ.env -> Evd.evar_map -> Conversion.conv_pb -> constr -> constr -> bool
129 val eq_constr : Environ.env -> Evd.evar_map -> constr -> constr -> bool (* FIXME rename: erases universes*)
130
131 val eta_reduce_head : Evd.evar_map -> constr -> constr
132
133 (* Eta expand the instantiation of a context *)
134 val eta_expand_instantiation : ?evars:CClosure.evar_handler -> env ->
135 Constr.constr array -> Constr.rel_context -> Constr.constr array
136
137 (** [prod_applist] [forall (x1:B1;...;xn:Bn), B] [a1...an] @return [B[a1...an]] *)
138 val prod_applist : Evd.evar_map -> constr -> constr list -> constr
139
140 (** In [prod_applist_decls n c args], [c] is supposed to have the
141 form [∀Γ.c] with [Γ] of length [m] and possibly with let-ins; it
142 returns [c] with the assumptions of [Γ] instantiated by [args] and
143 the local definitions of [Γ] expanded.
144 Note that [n] counts both let-ins and prods, while the length of [args]
145 only counts prods. In other words, varying [n] changes how many
146 trailing let-ins are expanded. *)
147 val prod_applist_decls : Evd.evar_map -> int -> constr -> constr list -> constr
148
149 (** Remove recursively the casts around a term i.e.
150 [strip_outer_cast (Cast (Cast ... (Cast c, t) ... ))] is [c]. *)
151 val strip_outer_cast : Evd.evar_map -> constr -> constr
152
153 (** [nb_lam sigma t] counts the number of head lambda abstractions in [t], ignoring casts.
154 For instance on [fun x1 x2 x3 => c] (where [c] is not itself a lambda abstraction) it returns 3. *)
155 val nb_lam : Evd.evar_map -> constr -> int
156
157 (** [nb_prod sigma t] counts the number of head products in [t], ignoring casts. *)
158 val nb_prod : Evd.evar_map -> constr -> int
159
160 (** Variant of [nb_prod] which also does zeta-reduction (i.e. reduces let-ins) along the way. *)
161 val nb_prod_modulo_zeta : Evd.evar_map -> constr -> int
162
163 (** [last_arg sigma t] returns the last argument of [t].
164 Fails if [t] is not an application. *)
165 val last_arg : Evd.evar_map -> constr -> constr
166
167 val adjust_app_list_size : constr -> constr list -> constr -> constr list ->
168 (constr * constr list * constr * constr list)
169 val adjust_app_array_size : constr -> constr array -> constr -> constr array ->
170 (constr * constr array * constr * constr array)
171
172 (** name contexts *)
173 type names_context = Name.t list
174 val add_name : Name.t -> names_context -> names_context
175 val lookup_name_of_rel : int -> names_context -> Name.t
176 val lookup_rel_of_name : Id.t -> names_context -> int
177 val empty_names_context : names_context
178 val ids_of_rel_context : ('c, 't, 'r) Context.Rel.pt -> Id.t list
179 val ids_of_named_context : ('c, 't, 'r) Context.Named.pt -> Id.t list
180 val ids_of_context : env -> Id.t list
181 val names_of_rel_context : env -> names_context
182
183 (* [env_rel_context_chop n env] extracts out the [n] top declarations
184 of the rel_context part of [env], counting both local definitions and
185 hypotheses *)
186 val env_rel_context_chop : int -> env -> env * rel_context
187
188 (** Set of local names *)
189 val vars_of_env: env -> Id.Set.t
190 val add_vname : Id.Set.t -> Name.t -> Id.Set.t
191
192 (** other signature iterators *)
193 val process_rel_context : (rel_declaration -> env -> env) -> env -> env
194 val assums_of_rel_context : ('c, 't, 'r) Context.Rel.pt -> ((Name.t,'r) Context.pbinder_annot * 't) list
195
196 val map_rel_context_in_env :
197 (env -> Constr.constr -> Constr.constr) -> env -> Constr.rel_context -> Constr.rel_context
198 val fold_named_context_both_sides :
199 ('a -> Constr.named_declaration -> Constr.named_declaration list -> 'a) ->
200 Constr.named_context -> init:'a -> 'a
201 val mem_named_context_val : Id.t -> named_context_val -> bool
202 val compact_named_context : Evd.evar_map -> EConstr.named_context -> EConstr.compacted_context
203
204 val clear_named_body : Id.t -> env -> env
205
206 val global_vars_set : env -> Evd.evar_map -> constr -> Id.Set.t
207 val global_vars_set_of_decl : env -> Evd.evar_map -> named_declaration -> Id.Set.t
208 val global_app_of_constr : Evd.evar_map -> constr -> (GlobRef.t * EInstance.t) * constr option
209
210 (** Gives an ordered list of hypotheses, closed by dependencies,
211 containing a given set *)
212 val dependency_closure : env -> Evd.evar_map -> named_context -> Id.Set.t -> Id.t list
213
214 (** Test if an identifier is the basename of a global reference *)
215 val is_section_variable : env -> Id.t -> bool
216
217 val is_template_polymorphic_ref : env -> Evd.evar_map -> constr -> bool
218 val is_template_polymorphic_ind : env -> Evd.evar_map -> constr -> bool
219
220 val is_Prop : Evd.evar_map -> constr -> bool
221 val is_Set : Evd.evar_map -> constr -> bool
222 val is_Type : Evd.evar_map -> constr -> bool
223
224 val reference_of_level : Evd.evar_map -> Univ.Level.t -> Libnames.qualid option
225
226 (** {5 Debug pretty-printers} *)
227
228 open Evd
229
230 val pr_global_env : env -> GlobRef.t -> Pp.t
231
232 val pr_existential_key : env -> evar_map -> Evar.t -> Pp.t
233
234 val evar_suggested_name : env -> evar_map -> Evar.t -> Id.t
235
236 val pr_evar_info : env -> evar_map -> 'a evar_info -> Pp.t
237 val pr_evar_constraints : evar_map -> evar_constraint list -> Pp.t
238 val pr_evar_map : ?with_univs:bool -> int option -> env -> evar_map -> Pp.t
239 val pr_evar_map_filter : ?with_univs:bool -> (Evar.t -> any_evar_info -> bool) ->
240 env -> evar_map -> Pp.t
241 val pr_evd_level : evar_map -> Univ.Level.t -> Pp.t
242 val pr_evd_qvar : evar_map -> Sorts.QVar.t -> Pp.t
243
244 module Internal : sig
245
246 (** NOTE: to print terms you always want to use functions in
247 Printer, not these ones which are for very special cases. *)
248
249 (** debug printers: print raw form for terms with evar-substitution. *)
250 val debug_print_constr : evar_map -> constr -> Pp.t
251
252 (** Pretty-printer hook: [print_constr_env env sigma c] will pretty
253 print c if the pretty printing layer has been linked into the Rocq
254 binary. *)
255 val print_constr_env : env -> Evd.evar_map -> constr -> Pp.t
256
257 (** [set_print_constr f] sets f to be the pretty printer *)
258 val set_print_constr : (env -> Evd.evar_map -> constr -> Pp.t) -> unit
259
260 (** Printers for contexts *)
261 val print_named_context : env -> Evd.evar_map -> Pp.t
262 val pr_rel_decl : env -> Evd.evar_map -> Constr.rel_declaration -> Pp.t
263 val print_rel_context : env -> Evd.evar_map -> Pp.t
264 val print_env : env -> Evd.evar_map -> Pp.t
265
266 val print_kconstr : Environ.env -> Evd.evar_map -> Evd.econstr -> Pp.t
267
268 end
269
270 val pr_evar_universe_context : UState.t -> Pp.t
271 [@@deprecated "(9.0) Use [UState.pr] instead"]