Debian Codegraph @

kernel/cClosure.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 Environ
14 open Esubst
15 open RedFlags
16
17 (** Lazy reduction. *)
18
19 (** [fconstr] is the type of frozen constr *)
20
21 type fconstr
22 (** [fconstr] can be accessed by using the function [fterm_of] and by
23 matching on type [fterm] *)
24
25 type finvert
26
27 type evar_repack
28
29 type usubs = fconstr subs UVars.puniverses
30
31 type table_key = Constant.t UVars.puniverses tableKey
32
33 (** Relevances (eg in binder_annot or case_info) have NOT been substituted
34 when there is a usubs field *)
35 type fterm =
36 | FRel of int
37 | FAtom of constr (** Metas and Sorts *)
38 | FFlex of table_key
39 | FInd of pinductive
40 | FConstruct of pconstructor * fconstr array
41 | FApp of fconstr * fconstr array
42 | FProj of Projection.t * Sorts.relevance * fconstr
43 | FFix of fixpoint * usubs
44 | FCoFix of cofixpoint * usubs
45 | FCaseT of case_info * UVars.Instance.t * constr array * case_return * fconstr * case_branch array * usubs (* predicate and branches are closures *)
46 | FCaseInvert of case_info * UVars.Instance.t * constr array * case_return * finvert * fconstr * case_branch array * usubs
47 | FLambda of int * (Name.t binder_annot * constr) list * constr * usubs
48 | FProd of Name.t binder_annot * fconstr * constr * usubs
49 | FLetIn of Name.t binder_annot * fconstr * fconstr * constr * usubs
50 | FEvar of Evar.t * constr list * usubs * evar_repack
51 | FInt of Uint63.t
52 | FFloat of Float64.t
53 | FString of Pstring.t
54 | FArray of UVars.Instance.t * fconstr Parray.t * fconstr
55 | FLIFT of int * fconstr
56 | FCLOS of constr * usubs
57 | FIrrelevant
58 | FLOCKED
59
60 (***********************************************************************
61 s A [stack] is a context of arguments, arguments are pushed by
62 [append_stack] one array at a time *)
63 type 'a next_native_args = (CPrimitives.arg_kind * 'a) list
64
65 type stack_member =
66 | Zapp of fconstr array
67 | ZcaseT of case_info * UVars.Instance.t * constr array * case_return * case_branch array * usubs
68 | Zproj of Projection.Repr.t * Sorts.relevance
69 | Zfix of fconstr * stack
70 | Zprimitive of CPrimitives.t * pconstant * fconstr list * fconstr next_native_args
71 (* operator, constr def, arguments already seen (in rev order), next arguments *)
72 | Zshift of int
73 | Zupdate of fconstr
74
75 and stack = stack_member list
76
77 val empty_stack : stack
78 val append_stack : fconstr array -> stack -> stack
79
80 val check_native_args : CPrimitives.t -> stack -> bool
81 val get_native_args1 : CPrimitives.t -> pconstant -> stack ->
82 fconstr list * fconstr * fconstr next_native_args * stack
83
84 val get_invert : finvert -> fconstr array
85
86 val stack_args_size : stack -> int
87
88 val inductive_subst : Declarations.mutual_inductive_body
89 -> UVars.Instance.t
90 -> fconstr array
91 -> usubs
92
93 val usubs_lift : usubs -> usubs
94 val usubs_liftn : int -> usubs -> usubs
95 val usubs_cons : fconstr -> usubs -> usubs
96
97 (** identity if the first instance is empty *)
98 val usubst_instance : 'a UVars.puniverses -> UVars.Instance.t -> UVars.Instance.t
99
100 val usubst_binder : _ UVars.puniverses -> 'a binder_annot -> 'a binder_annot
101
102 (** To lazy reduce a constr, create a [clos_infos] with
103 [create_clos_infos], inject the term to reduce with [inject]; then use
104 a reduction function *)
105
106 val inject : constr -> fconstr
107
108 val mk_clos : usubs -> constr -> fconstr
109 val mk_clos_vect : usubs -> constr array -> fconstr array
110
111 val zip : fconstr -> stack -> fconstr
112
113 val fterm_of : fconstr -> fterm
114 val term_of_fconstr : fconstr -> constr
115 val term_of_process : fconstr -> stack -> constr
116 val destFLambda :
117 (usubs -> constr -> fconstr) -> fconstr -> Name.t binder_annot * fconstr * fconstr
118
119 (** Global and local constant cache *)
120 type clos_infos
121 type clos_tab
122
123 type 'a evar_expansion =
124 | EvarDefined of 'a
125 | EvarUndefined of Evar.t * 'a list
126
127 type evar_handler = {
128 evar_expand : constr pexistential -> constr evar_expansion;
129 evar_repack : Evar.t * constr list -> constr;
130 evar_irrelevant : constr pexistential -> bool;
131 qvar_irrelevant : Sorts.QVar.t -> bool;
132 qual_equal : Sorts.Quality.t -> Sorts.Quality.t -> bool;
133 abstr_const : Constant.t -> (unit, (unit -> Vmemitcodes.to_patch) Vmemitcodes.pbody_code) Declarations.pconstant_body;
134 }
135
136 val default_evar_handler : env -> evar_handler
137 val lookup_constant_handler : env -> evar_handler -> Constant.t ->
138 (unit, (unit -> Vmemitcodes.to_patch) Vmemitcodes.pbody_code) Declarations.pconstant_body
139
140 val create_conv_infos :
141 ?univs:UGraph.t -> ?evars:evar_handler -> reds -> env -> clos_infos
142 val create_clos_infos :
143 ?univs:UGraph.t -> ?evars:evar_handler -> reds -> env -> clos_infos
144 val oracle_of_infos : clos_infos -> Conv_oracle.oracle
145
146 val create_tab : unit -> clos_tab
147
148 val info_env : clos_infos -> env
149 val info_flags: clos_infos -> reds
150 val info_univs : clos_infos -> UGraph.t
151 val unfold_projection : clos_infos -> Projection.t -> Sorts.relevance -> stack_member option
152
153 val push_relevance : clos_infos -> 'b binder_annot -> clos_infos
154 val push_relevances : clos_infos -> 'b binder_annot array -> clos_infos
155 val set_info_relevances : clos_infos -> Sorts.relevance Range.t -> clos_infos
156
157 val info_relevances : clos_infos -> Sorts.relevance Range.t
158
159 val is_irrelevant : clos_infos -> Sorts.relevance -> bool
160 val eq_quality : clos_infos -> Sorts.Quality.t -> Sorts.Quality.t -> bool
161
162 val infos_with_reds : clos_infos -> reds -> clos_infos
163
164 (** Reduction function *)
165
166 (** [norm_val] is for strong normalization *)
167 val norm_val : clos_infos -> clos_tab -> fconstr -> constr
168
169 (** Same as [norm_val] but for terms *)
170 val norm_term : clos_infos -> clos_tab -> usubs -> Constr.constr -> Constr.constr
171
172 (** [whd_val] is for weak head normalization *)
173 val whd_val : clos_infos -> clos_tab -> fconstr -> constr
174
175 (** [whd_stack] performs weak head normalization in a given stack. It
176 stops whenever a reduction is blocked. *)
177 val whd_stack :
178 clos_infos -> clos_tab -> fconstr -> stack -> fconstr * stack
179
180 val skip_irrelevant_stack : clos_infos -> stack -> stack
181
182 val eta_expand_stack : clos_infos -> Name.t binder_annot -> stack -> stack
183
184 (** [eta_expand_ind_stack env ind c t] computes stacks corresponding
185 to the conversion of the eta expansion of [t], considered as an inhabitant
186 of [ind], and the Constructor [c] of this inductive type containing its arguments.
187 Assumes [t] is a rigid term, and not a constructor. [ind] is the inductive
188 of the constructor term [c].
189 @raise Not_found if the inductive is not a primitive record, or if the
190 constructor is partially applied.
191 *)
192 val eta_expand_ind_stack : env -> pinductive -> fconstr ->
193 (fconstr * stack) -> stack * stack
194
195 (** Conversion auxiliary functions to do step by step normalisation *)
196
197 (** Like [unfold_reference], but handles primitives: if there are not
198 enough arguments, return [None]. Otherwise return [Some] with
199 [ZPrimitive] added to the stack. Produces a [FIrrelevant] when the
200 reference is irrelevant and the infos was created with
201 [create_conv_infos]. *)
202 val unfold_ref_with_args
203 : clos_infos
204 -> clos_tab
205 -> table_key
206 -> stack
207 -> (fconstr * stack) option
208
209 val get_ref_mask : clos_infos -> clos_tab -> table_key -> bool array
210
211 (** Hook for Reduction *)
212 val set_conv : (clos_infos -> clos_tab -> fconstr -> fconstr -> bool) -> unit