| 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 EConstr |
| 12 | open Evd |
| 13 | open Environ |
| 14 | |
| 15 | type alias |
| 16 | |
| 17 | val of_alias : alias -> EConstr.t |
| 18 | |
| 19 | module AllowedEvars : sig |
| 20 | |
| 21 | type t |
| 22 | (** Represents the set of evars that can be defined by the pretyper *) |
| 23 | |
| 24 | val all : t |
| 25 | (** All evars can be defined *) |
| 26 | |
| 27 | val mem : t -> Evar.t -> bool |
| 28 | (** [mem allowed evk] is true iff evk can be defined *) |
| 29 | |
| 30 | val from_pred : (Evar.t -> bool) -> t |
| 31 | (** [from_pred p] means evars satisfying p can be defined *) |
| 32 | |
| 33 | val except : Evar.Set.t -> t |
| 34 | (** [except evars] means all evars can be defined except the ones in [evars] *) |
| 35 | |
| 36 | val remove : Evar.t -> t -> t |
| 37 | (** [remove evk allowed] removes [evk] from the set of evars allowed by [allowed] *) |
| 38 | |
| 39 | end |
| 40 | |
| 41 | type unify_flags = { |
| 42 | modulo_betaiota : bool; |
| 43 | (* Enable beta-iota reductions during unification *) |
| 44 | open_ts : TransparentState.t; |
| 45 | (* Enable delta reduction according to open_ts for open terms *) |
| 46 | closed_ts : TransparentState.t; |
| 47 | (* Enable delta reduction according to closed_ts for closed terms (when calling conversion) *) |
| 48 | subterm_ts : TransparentState.t; |
| 49 | (* Enable delta reduction according to subterm_ts for selection of subterms during higher-order |
| 50 | unifications. *) |
| 51 | allowed_evars : AllowedEvars.t; |
| 52 | (* Disallowed evars are treated like rigid variables during unification: they can not be instantiated. *) |
| 53 | with_cs : bool |
| 54 | (* Enable canonical structure resolution during unification *) |
| 55 | } |
| 56 | |
| 57 | type unification_result = |
| 58 | | Success of evar_map |
| 59 | | UnifFailure of evar_map * Pretype_errors.unification_error |
| 60 | |
| 61 | val is_success : unification_result -> bool |
| 62 | |
| 63 | val is_evar_allowed : unify_flags -> Evar.t -> bool |
| 64 | |
| 65 | val allow_all_but_rrpat_evars : evar_map -> AllowedEvars.t |
| 66 | |
| 67 | (** Replace the vars and rels that are aliases to other vars and rels by |
| 68 | their representative that is most ancient in the context *) |
| 69 | val expand_vars_in_term : env -> evar_map -> constr -> constr |
| 70 | |
| 71 | (** One might want to use different conversion strategies for types and terms: |
| 72 | e.g. preventing delta reductions when doing term unifications but allowing |
| 73 | arbitrary delta conversion when checking the types of evar instances. *) |
| 74 | |
| 75 | type unification_kind = |
| 76 | | TypeUnification |
| 77 | | TermUnification |
| 78 | |
| 79 | (** A unification function parameterized by: |
| 80 | - unification flags |
| 81 | - the kind of unification |
| 82 | - environment |
| 83 | - sigma |
| 84 | - conversion problem |
| 85 | - the two terms to unify. *) |
| 86 | type unifier = unify_flags -> unification_kind -> |
| 87 | env -> evar_map -> conv_pb -> constr -> constr -> unification_result |
| 88 | |
| 89 | (** A conversion function: parameterized by the kind of unification, |
| 90 | environment, sigma, conversion problem and the two terms to convert. |
| 91 | Conversion is not allowed to instantiate evars contrary to unification. *) |
| 92 | type conversion_check = unify_flags -> unification_kind -> |
| 93 | env -> evar_map -> conv_pb -> constr -> constr -> bool |
| 94 | |
| 95 | (** [instantiate_evar unify flags env sigma ev c] defines the evar [ev] with [c], |
| 96 | checking that the type of [c] is unifiable with [ev]'s declared type first. |
| 97 | |
| 98 | Preconditions: |
| 99 | - [ev] does not occur in [c]. |
| 100 | - [c] does not contain any Meta(_) |
| 101 | |
| 102 | If [ev] and [c] have non inferably convertible types, an exception |
| 103 | [IllTypedInstance] is raised *) |
| 104 | |
| 105 | val instantiate_evar : unifier -> unify_flags -> env -> evar_map -> |
| 106 | Evar.t -> constr -> evar_map |
| 107 | |
| 108 | (** [evar_define choose env ev c] try to instantiate [ev] with [c] (typed in [env]), |
| 109 | possibly solving related unification problems, possibly leaving open |
| 110 | some problems that cannot be solved in a unique way (except if choose is |
| 111 | true); fails if the instance is not valid for the given [ev]; |
| 112 | If [ev] and [c] have non inferably convertible types, an exception |
| 113 | [IllTypedInstance] is raised *) |
| 114 | |
| 115 | val evar_define : unifier -> unify_flags -> ?choose:bool -> ?imitate_defs:bool -> |
| 116 | env -> evar_map -> bool option -> existential -> constr -> evar_map |
| 117 | |
| 118 | |
| 119 | val refresh_universes : |
| 120 | ?allowed_evars:AllowedEvars.t -> (* Don't refresh disallowed evars *) |
| 121 | ?status:Evd.rigid -> |
| 122 | ?onlyalg:bool (* Only algebraic universes *) -> |
| 123 | ?refreshset:bool -> |
| 124 | (* Also refresh Prop and Set universes, so that the returned type can be any supertype |
| 125 | of the original type *) |
| 126 | bool option (* direction: true for levels lower than the existing levels *) -> |
| 127 | env -> evar_map -> types -> evar_map * types |
| 128 | |
| 129 | val solve_refl : ?can_drop:bool -> conversion_check -> unify_flags -> env -> evar_map -> |
| 130 | bool option -> Evar.t -> constr SList.t -> constr SList.t -> evar_map |
| 131 | |
| 132 | val solve_evar_evar : ?force:bool -> |
| 133 | (env -> evar_map -> bool option -> existential -> constr -> evar_map) -> |
| 134 | unifier -> unify_flags -> |
| 135 | env -> evar_map -> bool option -> existential -> existential -> evar_map |
| 136 | (** The two evars are expected to be in inferably convertible types; |
| 137 | if not, an exception IllTypedInstance is raised *) |
| 138 | |
| 139 | (* [solve_simple_eqn unifier flags env evd (direction,?ev[inst],t)] |
| 140 | makes progresses on problems of the form [?ev[inst] := t] (or |
| 141 | [?ev[inst] :<= t], or [?ev[inst] :>= t]). It uses imitation and a |
| 142 | limited form of projection. At the time of writing this comment, |
| 143 | only rels/vars (possibly indirectly via a chain of evars) and |
| 144 | constructors are used for projection. For instance |
| 145 | [?e[x,S 0] := x + S 0] will be solved by imitating [+] and |
| 146 | projecting [x] and [S 0] (so that [?e[a,b]:=a+b]) but in |
| 147 | [?e[0+0] := 0+0], the possible imitation will not be seen. |
| 148 | |
| 149 | [choose] tells to make an irreversible choice when two valid |
| 150 | projections are competing. It is to be used when no more reversible |
| 151 | progress can be done. It is [false] by default. |
| 152 | |
| 153 | [imitate_defs] tells to expand local definitions if they cannot be |
| 154 | projected. It is [true] by default. |
| 155 | *) |
| 156 | |
| 157 | val solve_simple_eqn : unifier -> unify_flags -> ?choose:bool -> ?imitate_defs:bool -> env -> evar_map -> |
| 158 | bool option * existential * constr -> unification_result |
| 159 | |
| 160 | val reconsider_unif_constraints : unifier -> unify_flags -> evar_map -> unification_result |
| 161 | |
| 162 | val is_unification_pattern_evar : env -> evar_map -> existential -> constr list -> |
| 163 | constr -> alias list option |
| 164 | |
| 165 | val is_unification_pattern : env * int -> evar_map -> constr -> constr list -> |
| 166 | constr -> alias list option |
| 167 | |
| 168 | val solve_pattern_eqn : env -> evar_map -> alias list -> constr -> constr |
| 169 | |
| 170 | val noccur_evar : env -> evar_map -> Evar.t -> constr -> bool |
| 171 | |
| 172 | exception IllTypedInstance of env * evar_map * types option * types |
| 173 | |
| 174 | val check_evar_instance : unifier -> unify_flags -> |
| 175 | env -> evar_map -> Evar.t -> constr -> evar_map |
| 176 | (** May raise IllTypedInstance if types are not convertible *) |
| 177 | |
| 178 | val remove_instance_local_defs : |
| 179 | evar_map -> Evar.t -> 'a list -> 'a list |
| 180 | |
| 181 | val get_type_of_refresh : |
| 182 | ?lax:bool -> env -> evar_map -> constr |
| 183 | -> evar_map * types |
| 184 | |
| 185 | val checked_appvect_hook : (env -> evar_map -> constr -> constr array -> evar_map * constr) Hook.t |