Debian Codegraph @

pretyping/pretyping.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 implements type inference. It maps [glob_constr]
12 (i.e. untyped terms whose names are located) to [constr]. In
13 particular, it drives complex pattern-matching problems ("match")
14 into elementary ones, insertion of coercions and resolution of
15 implicit arguments. *)
16
17 open Names
18 open Environ
19 open Evd
20 open EConstr
21 open Glob_term
22 open Ltac_pretype
23
24 val add_bidirectionality_hint : env -> GlobRef.t -> int -> unit
25 (** A bidirectionality hint `n` for a global `g` tells the pretyper to use
26 typing information from the context after typing the `n` for arguments of an
27 application of `g`. *)
28
29 val get_bidirectionality_hint : env -> GlobRef.t -> int option
30
31 val clear_bidirectionality_hint : env -> GlobRef.t -> unit
32
33 (** An auxiliary function for searching for fixpoint guard indices *)
34
35 (* Tells the possible indices liable to guard a fixpoint *)
36 type possible_fix_indices = int list list
37
38 (* Tells if possibly a cofixpoint or a fixpoint over the given list of possible indices *)
39 type possible_guard = {
40 possibly_cofix : bool;
41 possible_fix_indices : possible_fix_indices;
42 } (* Note: if no fix indices are given, it has to be a cofix *)
43
44 val search_guard :
45 ?loc:Loc.t -> ?evars:CClosure.evar_handler ->
46 ?elim_to:(Sorts.Quality.t -> Sorts.Quality.t -> bool) -> env ->
47 possible_guard -> Constr.rec_declaration -> int array option
48
49 val search_fix_guard : (* For Fixpoints only *)
50 ?loc:Loc.t -> ?evars:CClosure.evar_handler -> env ->
51 possible_fix_indices -> Constr.rec_declaration -> int array
52
53 val esearch_guard :
54 ?loc:Loc.t -> env -> evar_map -> possible_guard ->
55 EConstr.rec_declaration -> int array option
56
57 val esearch_fix_guard : (* For Fixpoints only *)
58 ?loc:Loc.t -> env -> evar_map -> possible_fix_indices ->
59 EConstr.rec_declaration -> int array
60
61 val esearch_cofix_guard : ?loc:Loc.t -> env -> evar_map -> EConstr.rec_declaration -> unit
62
63 type typing_constraint =
64 | IsType (** Necessarily a type *)
65 | OfType of types (** A term of the expected type *)
66 | WithoutTypeConstraint (** A term of unknown expected type *)
67
68 type use_typeclasses = NoUseTC | UseTCForConv | UseTC
69 (** Typeclasses are used in 2 ways:
70
71 - through the "Typeclass Resolution For Conversion" option, if a
72 conversion problem fails we try again after resolving typeclasses
73 (UseTCForConv and UseTC)
74 - after pretyping we resolve typeclasses (UseTC) (in [solve_remaining_evars])
75 *)
76
77 type inference_flags = {
78 use_coercions : bool;
79 use_typeclasses : use_typeclasses;
80 solve_unification_constraints : bool;
81 fail_evar : bool;
82 expand_evars : bool;
83 program_mode : bool;
84 poly : PolyFlags.t;
85 undeclared_evars_rr : bool;
86 unconstrained_sorts : bool;
87 }
88
89 val default_inference_flags : bool -> inference_flags
90
91 val no_classes_no_fail_inference_flags : inference_flags
92
93 val all_no_fail_flags : inference_flags
94
95 val all_and_fail_flags : inference_flags
96
97 (** Generic calls to the interpreter from glob_constr to open_constr;
98 by default, inference_flags tell to use type classes and
99 heuristics (but no external tactic solver hooks), as well as to
100 ensure that conversion problems are all solved and expand evars,
101 but unresolved evars can remain. The difference is in whether the
102 evar_map is modified explicitly or by side-effect. *)
103
104 val understand_tcc : ?flags:inference_flags -> env -> evar_map ->
105 ?expected_type:typing_constraint -> glob_constr -> evar_map * constr
106
107 (** As [understand_tcc] but also returns the type of the elaborated term.
108 The [expand_evars] flag is not applied to the type (only to the term). *)
109 val understand_tcc_ty : ?flags:inference_flags -> env -> evar_map ->
110 ?expected_type:typing_constraint -> glob_constr -> evar_map * constr * types
111
112 (** More general entry point with evars from ltac *)
113
114 (** Generic call to the interpreter from glob_constr to constr
115
116 In [understand_ltac flags sigma env ltac_env constraint c],
117
118 flags: tell how to manage evars
119 sigma: initial set of existential variables (typically current goals)
120 ltac_env: partial substitution of variables (used for the tactic language)
121 constraint: tell if interpreted as a possibly constrained term or a type
122 *)
123
124 val understand_ltac : inference_flags ->
125 env -> evar_map -> ltac_var_map ->
126 typing_constraint -> glob_constr -> evar_map * EConstr.t
127
128 val understand_ltac_ty : inference_flags ->
129 env -> evar_map -> ltac_var_map ->
130 typing_constraint -> glob_constr -> evar_map * EConstr.t * EConstr.types
131
132 (** Standard call to get a constr from a glob_constr, resolving
133 implicit arguments and coercions, and compiling pattern-matching;
134 the default inference_flags tells to use type classes and
135 heuristics (but no external tactic solver hook), as well as to
136 ensure that conversion problems are all solved and that no
137 unresolved evar remains, expanding evars. *)
138 val understand : ?flags:inference_flags -> ?expected_type:typing_constraint ->
139 env -> evar_map -> glob_constr -> constr Evd.in_ustate
140
141 val understand_uconstr :
142 ?flags:inference_flags -> ?expected_type:typing_constraint ->
143 env -> evar_map -> Ltac_pretype.closed_glob_constr -> evar_map * EConstr.t
144
145 (** [hook env sigma ev] returns [Some (sigma', term)] if [ev] can be
146 instantiated with a solution, [None] otherwise. Used to extend
147 [solve_remaining_evars] below. *)
148 type inference_hook = env -> evar_map -> Evar.t -> (evar_map * constr) option
149
150 (** Trying to solve remaining evars and remaining conversion problems
151 possibly using type classes, heuristics, external tactic solver
152 hook depending on given flags. *)
153 (* For simplicity, it is assumed that current map has no other evars
154 with candidate and no other conversion problems that the one in
155 [pending], however, it can contain more evars than the pending ones. *)
156 val solve_remaining_evars : ?hook:inference_hook -> inference_flags ->
157 env -> ?initial:evar_map -> (* current map *) evar_map -> evar_map
158
159 (** Checking evars and pending conversion problems are all solved,
160 reporting an appropriate error message *)
161
162 val check_evars_are_solved :
163 program_mode:bool -> env -> ?initial:evar_map -> (* current map: *) evar_map -> unit
164
165 (** [check_evars env ?initial sigma c] fails if some unresolved evar
166 remains in [c] which isn't in [initial] (any unresolved evar if
167 [initial] not provided) *)
168 val check_evars : env -> ?initial:evar_map -> evar_map -> constr -> unit
169
170 (**/**)
171 (** Internal of Pretyping... *)
172 val ise_pretype_gen :
173 inference_flags -> env -> evar_map ->
174 ltac_var_map -> typing_constraint -> glob_constr -> evar_map * constr * types
175
176 (** {6 Open-recursion style pretyper} *)
177
178 type pretype_flags = {
179 poly: PolyFlags.t;
180 resolve_tc : bool;
181 program_mode : bool;
182 use_coercions : bool;
183 undeclared_evars_rr : bool;
184 unconstrained_sorts : bool;
185 }
186
187 type 'a pretype_fun = ?loc:Loc.t -> flags:pretype_flags -> Evardefine.type_constraint -> GlobEnv.t -> evar_map -> evar_map * 'a
188
189 type pretyper = {
190 pretype_ref : pretyper -> GlobRef.t * glob_instance option -> unsafe_judgment pretype_fun;
191 pretype_var : pretyper -> Id.t -> unsafe_judgment pretype_fun;
192 pretype_evar : pretyper -> existential_name CAst.t * (lident * glob_constr) list -> unsafe_judgment pretype_fun;
193 pretype_patvar : pretyper -> Evar_kinds.matching_var_kind -> unsafe_judgment pretype_fun;
194 pretype_app : pretyper -> glob_constr * glob_constr list -> unsafe_judgment pretype_fun;
195 pretype_proj : pretyper -> (Constant.t * glob_instance option) * glob_constr list * glob_constr -> unsafe_judgment pretype_fun;
196 pretype_lambda : pretyper -> Name.t * binding_kind * glob_constr * glob_constr -> unsafe_judgment pretype_fun;
197 pretype_prod : pretyper -> Name.t * binding_kind * glob_constr * glob_constr -> unsafe_judgment pretype_fun;
198 pretype_letin : pretyper -> Name.t * glob_constr * glob_constr option * glob_constr -> unsafe_judgment pretype_fun;
199 pretype_cases : pretyper -> Constr.case_style * glob_constr option * tomatch_tuples * cases_clauses -> unsafe_judgment pretype_fun;
200 pretype_lettuple : pretyper -> Name.t list * (Name.t * glob_constr option) * glob_constr * glob_constr -> unsafe_judgment pretype_fun;
201 pretype_if : pretyper -> glob_constr * (Name.t * glob_constr option) * glob_constr * glob_constr -> unsafe_judgment pretype_fun;
202 pretype_rec : pretyper -> glob_fix_kind * Id.t array * glob_decl list array * glob_constr array * glob_constr array -> unsafe_judgment pretype_fun;
203 pretype_sort : pretyper -> glob_sort -> unsafe_judgment pretype_fun;
204 pretype_hole : pretyper -> Evar_kinds.glob_evar_kind -> unsafe_judgment pretype_fun;
205 pretype_genarg : pretyper -> Genarg.glob_generic_argument -> unsafe_judgment pretype_fun;
206 pretype_cast : pretyper -> glob_constr * Constr.cast_kind option * glob_constr -> unsafe_judgment pretype_fun;
207 pretype_int : pretyper -> Uint63.t -> unsafe_judgment pretype_fun;
208 pretype_float : pretyper -> Float64.t -> unsafe_judgment pretype_fun;
209 pretype_string : pretyper -> Pstring.t -> unsafe_judgment pretype_fun;
210 pretype_array : pretyper -> glob_instance option * glob_constr array * glob_constr * glob_constr -> unsafe_judgment pretype_fun;
211 pretype_type : pretyper -> glob_constr -> unsafe_type_judgment pretype_fun;
212 }
213 (** Type of pretyping algorithms in open-recursion style. A typical way to
214 implement a pretyping variant is to inherit from some pretyper using
215 record inheritance and replacing particular fields with the [where] clause.
216 Recursive calls to the subterms should call the [pretyper] provided as the
217 first argument to the function. This object can be turned in an actual
218 pretyping function through the {!eval_pretyper} function below. *)
219
220 val default_pretyper : pretyper
221 (** Rocq vanilla pretyper. *)
222
223 val eval_pretyper : pretyper -> flags:pretype_flags -> Evardefine.type_constraint -> GlobEnv.t -> evar_map -> glob_constr -> evar_map * unsafe_judgment