Debian Codegraph @

pretyping/reductionops.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 Names
12 open Constr
13 open EConstr
14 open Univ
15 open Evd
16 open Environ
17
18 (** Reduction Functions. *)
19
20 exception Elimconst
21
22 type meta_handler = { meta_value : metavariable -> EConstr.t option }
23
24 val debug_RAKAM : CDebug.t
25
26 module CredNative : Primred.RedNative with
27 type elem = EConstr.t and type args = EConstr.t array and type evd = Evd.evar_map
28 and type uinstance = EInstance.t
29
30 (** Machinery to customize the behavior of the reduction *)
31 module ReductionBehaviour : sig
32
33 type t = NeverUnfold | UnfoldWhen of when_flags | UnfoldWhenNoMatch of when_flags
34 and when_flags = { recargs : int list ; nargs : int option }
35
36 module Db : sig
37 type t
38 val get : unit -> t
39 val empty : t
40 val print : t -> Constant.t -> Pp.t
41 val all_never_unfold : t -> Cpred.t
42 end
43
44 val set : local:bool -> Constant.t -> t option -> unit
45 val get_from_db : Db.t -> Constant.t -> t option
46 val get : Constant.t -> t option
47 val print : Constant.t -> Pp.t
48 end
49
50 (** {6 Support for reduction effects } *)
51
52 type effect_name = string
53
54 (* [declare_reduction_effect name f] declares [f] under key [name];
55 [name] must be a unique in "world". *)
56 val declare_reduction_effect : effect_name ->
57 (Environ.env -> Evd.evar_map -> Constr.constr -> unit) -> unit
58
59 (* [set_reduction_effect local cst name] declares effect [name] to be called when [cst] is found *)
60 val set_reduction_effect : Libobject.locality -> Constant.t -> effect_name -> unit
61
62 (* [effect_hook env sigma key term] apply effect associated to [key] on [term] *)
63 val reduction_effect_hook : Environ.env -> Evd.evar_map -> Constant.t ->
64 Constr.constr Lazy.t -> unit
65
66 module Stack : sig
67 type app_node
68
69 val pr_app_node : (EConstr.t -> Pp.t) -> app_node -> Pp.t
70
71 type case_stk
72
73 val mkCaseStk : case_info * EInstance.t * EConstr.t array * EConstr.case_return * EConstr.t pcase_invert * EConstr.case_branch array -> case_stk
74
75 type member =
76 | App of app_node
77 | Case of case_stk
78 | Proj of Projection.t * ERelevance.t
79 | Fix of EConstr.fixpoint * t
80 | Primitive of CPrimitives.t * (Constant.t * EInstance.t) * t * CPrimitives.args_red
81 and t = member list
82
83 val pr : (EConstr.t -> Pp.t) -> t -> Pp.t
84
85 val empty : t
86 val is_empty : t -> bool
87
88 val compare_shape : t -> t -> bool
89
90 exception IncompatibleFold2
91
92 (** [fold2 f x sk1 sk2] folds [f] on any pair of term in [(sk1,sk2)].
93 @return the result and the lifts to apply on the terms
94 @raise IncompatibleFold2 when [sk1] and [sk2] have incompatible shapes *)
95 val fold2 : ('a -> constr -> constr -> 'a) -> 'a -> t -> t -> 'a
96
97 (** [append_app args sk] pushes array of arguments [args] on [sk] *)
98 val append_app : EConstr.t array -> t -> t
99
100 (** [append_app_list args sk] pushes list of arguments [args] on [sk] *)
101 val append_app_list : EConstr.t list -> t -> t
102
103 (** if [strip_app sk] = [(sk1,sk2)], then [sk = sk1 @ sk2] with
104 [sk1] purely applicative and [sk2] does not start with an argument *)
105 val strip_app : t -> t * t
106
107 (** @return (the nth first elements, the (n+1)th element, the remaining stack)
108 if there enough of those *)
109 val strip_n_app : int -> t -> (t * EConstr.t * t) option
110
111 (** [decomp sk] extracts the first argument of reversed stack [sk] is there is some *)
112 val decomp_rev : t -> (EConstr.t * t) option
113
114 (** [not_purely_applicative sk] *)
115 val not_purely_applicative : t -> bool
116
117 (** [list_of_app_stack sk] either returns [Some sk] turned into a list of
118 arguments if [sk] is purely applicative and [None] otherwise *)
119 val list_of_app_stack : t -> constr list option
120
121 (** [args_size sk] returns the number of arguments available at the
122 head of [sk] *)
123 val args_size : t -> int
124
125 (** [zip sigma t sk] *)
126 val zip : evar_map -> constr * t -> constr
127
128 val expand_case : env -> evar_map -> case_stk ->
129 case_info * EInstance.t * constr array * ((rel_context * constr) * ERelevance.t) * (rel_context * constr) array
130 end
131
132 (************************************************************************)
133
134 type reduction_function = env -> evar_map -> constr -> constr
135
136 type e_reduction_function = env -> evar_map -> constr -> evar_map * constr
137
138 type stack_reduction_function =
139 env -> evar_map -> constr -> constr * constr list
140
141 (** {6 Generic Optimized Reduction Function using Closures } *)
142
143 val clos_norm_flags : RedFlags.reds -> reduction_function
144 val clos_whd_flags : RedFlags.reds -> reduction_function
145
146 (** Same as [(strong whd_beta[delta][iota])], but much faster on big terms *)
147 val nf_beta : reduction_function
148 val nf_betaiota : reduction_function
149 val nf_betaiotazeta : reduction_function
150 val nf_zeta : reduction_function
151 val nf_all : reduction_function
152 val nf_evar : evar_map -> constr -> constr
153
154 (** Lazy strategy, weak head reduction *)
155
156 val whd_evar : evar_map -> constr -> constr
157 val whd_nored : ?metas:meta_handler -> reduction_function
158 val whd_beta : reduction_function
159 val whd_betaiota : ?metas:meta_handler -> reduction_function
160 val whd_betaiotazeta : ?metas:meta_handler -> reduction_function
161 val whd_all : ?metas:meta_handler -> reduction_function
162 val whd_allnolet : reduction_function
163 val whd_betalet : reduction_function
164
165 (** Removes cast and put into applicative form *)
166 val whd_nored_stack : ?metas:meta_handler -> stack_reduction_function
167 val whd_beta_stack : ?metas:meta_handler -> stack_reduction_function
168 val whd_betaiota_stack : ?metas:meta_handler -> stack_reduction_function
169 val whd_betaiotazeta_stack : ?metas:meta_handler -> stack_reduction_function
170 val whd_all_stack : ?metas:meta_handler -> stack_reduction_function
171 val whd_allnolet_stack : ?metas:meta_handler -> stack_reduction_function
172 val whd_betalet_stack : ?metas:meta_handler -> stack_reduction_function
173
174 (** {6 Head normal forms } *)
175
176 val whd_const : Constant.t -> reduction_function
177 val whd_delta_stack : ?metas:meta_handler -> stack_reduction_function
178 val whd_delta : reduction_function
179 val whd_betadeltazeta_stack : ?metas:meta_handler -> stack_reduction_function
180 val whd_betadeltazeta : reduction_function
181 val whd_zeta_stack : ?metas:meta_handler -> stack_reduction_function
182 val whd_zeta : reduction_function
183
184 val shrink_eta : evar_map -> constr -> constr
185
186 val whd_stack_gen : RedFlags.reds -> ?metas:meta_handler -> stack_reduction_function
187
188 (** Various reduction functions *)
189
190 val beta_applist : evar_map -> constr * constr list -> constr
191
192 val hnf_prod_app : env -> evar_map -> constr -> constr -> constr
193 val hnf_prod_appvect : env -> evar_map -> constr -> constr array -> constr
194 val hnf_prod_applist : env -> evar_map -> constr -> constr list -> constr
195 val hnf_lam_app : env -> evar_map -> constr -> constr -> constr
196 val hnf_lam_appvect : env -> evar_map -> constr -> constr array -> constr
197 val hnf_lam_applist : env -> evar_map -> constr -> constr list -> constr
198
199 val whd_decompose_prod : env -> evar_map -> types -> (Name.t EConstr.binder_annot * constr) list * types
200 (** Decompose a type into a sequence of products and a non-product conclusion
201 in head normal form, using head-reduction to expose the products *)
202
203 val whd_decompose_lambda : env -> evar_map -> constr -> (Name.t EConstr.binder_annot * constr) list * constr
204 (** Decompose a term into a sequence of lambdas and a non-lambda conclusion
205 in head normal form, using head-reduction to expose the lambdas *)
206
207 val whd_decompose_prod_decls : env -> evar_map -> types -> rel_context * types
208 (** Decompose a type into a context and a conclusion not starting with a product or let-in,
209 using head-reduction without zeta to expose the products and let-ins *)
210
211 val whd_decompose_prod_n : env -> evar_map -> int -> types -> (Name.t EConstr.binder_annot * constr) list * types
212 (** Like [whd_decompose_prod] but limited at [n] products; raises [Invalid_argument] if not enough products *)
213
214 val whd_decompose_lambda_n : env -> evar_map -> int -> constr -> (Name.t EConstr.binder_annot * constr) list * constr
215 (** Like [whd_decompose_lambda] but limited at [n] lambdas; raises [Invalid_argument] if not enough lambdas *)
216
217 val splay_arity : env -> evar_map -> constr -> (Name.t EConstr.binder_annot * constr) list * ESorts.t
218 (** Decompose an arity reducing let-ins; Raises [Reduction.NotArity] *)
219
220 val dest_arity : env -> evar_map -> constr -> rel_context * ESorts.t
221 (** Decompose an arity preserving let-ins; Raises [Reduction.NotArity] *)
222
223 val sort_of_arity : env -> evar_map -> constr -> ESorts.t
224 (** Raises [Reduction.NotArity] *)
225
226 val whd_decompose_prod_n_assum : env -> evar_map -> int -> types -> rel_context * types
227 (** Extract the n first products of a type, preserving let-ins (but not counting them);
228 Raises [Invalid_argument] if not enough products *)
229
230 val whd_decompose_prod_n_decls : env -> evar_map -> int -> types -> rel_context * types
231 (** Extract the n first products of a type, counting and preserving let-ins;
232 Raises [Invalid_argument] if not enough products or let-ins *)
233
234 val whd_decompose_lambda_n_assum : env -> evar_map -> int -> constr -> rel_context * constr
235 (** Extract the n first lambdas of a term, preserving let-ins (but not counting them);
236 Raises [Invalid_argument] if not enough lambdas *)
237
238 val reducible_mind_case : evar_map -> constr -> bool
239
240 val find_conclusion : env -> evar_map -> constr -> (constr, constr, ESorts.t, EInstance.t, ERelevance.t) kind_of_term
241 val is_arity : env -> evar_map -> constr -> bool
242 val is_sort : env -> evar_map -> types -> bool
243
244 val contract_fix : evar_map -> fixpoint -> constr
245 val contract_cofix : evar_map -> cofixpoint -> constr
246
247 (** {6 Querying the kernel conversion oracle: opaque/transparent constants } *)
248 val is_transparent : Environ.env -> Evaluable.t -> bool
249
250 (** {6 Conversion Functions (uses closures, lazy strategy) } *)
251
252 type conversion_test = UnivConstraints.t -> UnivConstraints.t
253
254 val is_conv : ?reds:TransparentState.t -> env -> evar_map -> constr -> constr -> bool
255 val is_conv_leq : ?reds:TransparentState.t -> env -> evar_map -> constr -> constr -> bool
256 val is_fconv : ?reds:TransparentState.t -> conv_pb -> env -> evar_map -> constr -> constr -> bool
257
258 (** [infer_conv] Adds necessary universe constraints to the evar map.
259 pb defaults to CUMUL and ts to a full transparent state.
260 @raise UniverseInconsistency iff catch_incon is set to false,
261 otherwise returns false in that case.
262 *)
263 val infer_conv : ?catch_incon:bool -> ?pb:conv_pb -> ?ts:TransparentState.t ->
264 env -> evar_map -> constr -> constr -> evar_map option
265
266 val infer_conv_ustate : ?catch_incon:bool -> ?pb:conv_pb -> ?ts:TransparentState.t ->
267 env -> evar_map -> constr -> constr -> UnivProblem.Set.t option
268
269 (** Conversion with inference of universe constraints *)
270 val vm_infer_conv : ?pb:conv_pb -> env -> evar_map -> constr -> constr ->
271 evar_map option
272
273 val native_infer_conv : ?pb:conv_pb -> env -> evar_map -> constr -> constr ->
274 evar_map option
275
276 type genconv = {
277 genconv : 'a 'err. conv_pb -> l2r:bool -> Evd.evar_map -> TransparentState.t ->
278 Environ.env -> ('a, 'err) Conversion.generic_conversion_function
279 }
280
281 (** [infer_conv_gen] behaves like [infer_conv] but is parametrized by a
282 conversion function. Used to pretype vm and native casts. *)
283 val infer_conv_gen : genconv ->
284 ?catch_incon:bool -> ?pb:conv_pb -> ?ts:TransparentState.t -> env ->
285 evar_map -> constr -> constr -> evar_map option
286
287 val check_hyps_inclusion : env -> evar_map -> GlobRef.t -> Constr.named_context -> unit
288 (** [Typeops.check_hyps_inclusion] but handles evars in the environment. *)
289
290 (** {6 Heuristic for Conversion with Evar } *)
291
292 type state = constr * Stack.t
293
294 type state_reduction_function =
295 env -> evar_map -> state -> state
296
297 val pr_state : env -> evar_map -> state -> Pp.t
298
299 val whd_nored_state : ?metas:meta_handler -> state_reduction_function
300
301 val whd_betaiota_deltazeta_for_iota_state :
302 TransparentState.t -> ?metas:meta_handler -> state_reduction_function
303
304 exception PatternFailure
305 val apply_rules : (rel_context -> state -> state) -> env -> evar_map -> EInstance.t ->
306 Declarations.machine_rewrite_rule list -> Stack.t -> econstr * Stack.t
307
308 val is_head_evar : env -> evar_map -> constr -> bool
309
310 exception AnomalyInConversion of exn
311
312 (* inferred_universes just gathers the constraints. *)
313 val inferred_universes : (UGraph.t * Univ.UnivConstraints.t, Conversion.graph_inconsistency) Conversion.universe_compare
314
315 val eta_expand : env -> evar_map -> etypes -> etypes -> etypes
316
317 (* Eta expand the instantiation of a context *)
318 val eta_expand_instantiation : env -> evar_map -> constr array -> rel_context -> constr array