| 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 | |
| 12 | (** A structure S is a non recursive inductive type with a single |
| 13 | constructor *) |
| 14 | module Structure : sig |
| 15 | |
| 16 | (** A projection to a structure field *) |
| 17 | type projection = { |
| 18 | proj_name : Names.Name.t; (** field name *) |
| 19 | proj_true : bool; (** false = projection for a defined field (letin) *) |
| 20 | proj_canonical : bool; (** false = not to be used for CS inference *) |
| 21 | proj_body : Names.Constant.t option; (** the projection function *) |
| 22 | } |
| 23 | |
| 24 | type t = { |
| 25 | name : Names.inductive; |
| 26 | projections : projection list; |
| 27 | nparams : int; |
| 28 | } |
| 29 | |
| 30 | val make : Environ.env -> Names.inductive -> projection list -> t |
| 31 | |
| 32 | val register : t -> unit |
| 33 | val subst : Mod_subst.substitution -> t -> t |
| 34 | |
| 35 | (** refreshes nparams, e.g. after section discharging *) |
| 36 | val rebuild : Environ.env -> t -> t |
| 37 | |
| 38 | (** Tells whether the inductive corresponds to a structure. *) |
| 39 | val mem : Environ.env -> Names.inductive -> bool |
| 40 | |
| 41 | (** [find isp] returns the Structure.t associated to the |
| 42 | inductive path [isp] if it corresponds to a structure, otherwise |
| 43 | it fails with [Not_found] *) |
| 44 | val find : Environ.env -> Names.inductive -> t |
| 45 | |
| 46 | (** raise [Not_found] if not a structure projection *) |
| 47 | val find_from_projection : Environ.env -> Names.Constant.t -> t |
| 48 | |
| 49 | (** [lookup_projections isp] returns the projections associated to the |
| 50 | inductive path [isp] if it corresponds to a structure, otherwise |
| 51 | it fails with [Not_found] *) |
| 52 | val find_projections : Environ.env -> Names.inductive -> Names.Constant.t option list |
| 53 | |
| 54 | (** raise [Not_found] if not a projection *) |
| 55 | val projection_nparams : Environ.env -> Names.Constant.t -> int |
| 56 | |
| 57 | val is_projection : Names.Constant.t -> bool |
| 58 | |
| 59 | val projection_number : Environ.env -> Names.Constant.t -> int |
| 60 | (** [projection_number env p] returns the position of the projection p in |
| 61 | the structure it corresponds to, counting from 0. *) |
| 62 | |
| 63 | end |
| 64 | |
| 65 | (** A canonical instance declares "canonical" conversion hints between |
| 66 | the effective components of a structure and the projections of the |
| 67 | structure *) |
| 68 | module Instance : sig |
| 69 | |
| 70 | type t |
| 71 | |
| 72 | (** Process a record instance, checkig it can be registered as canonical. |
| 73 | The record type must be declared as a canonical Structure.t beforehand. *) |
| 74 | val make : Environ.env -> Evd.evar_map -> Names.GlobRef.t -> t |
| 75 | |
| 76 | (** Register an instance as canonical *) |
| 77 | val register : warn:bool -> Environ.env -> Evd.evar_map -> t -> unit |
| 78 | |
| 79 | val subst : Mod_subst.substitution -> t -> t |
| 80 | val repr : t -> Names.GlobRef.t |
| 81 | |
| 82 | end |
| 83 | |
| 84 | |
| 85 | (** A ValuePattern.t characterizes the form of a component of canonical |
| 86 | instance and is used to query the data base of canonical instances *) |
| 87 | module ValuePattern : sig |
| 88 | |
| 89 | type t = |
| 90 | | Const_cs of Names.GlobRef.t |
| 91 | | Proj_cs of Names.Projection.Repr.t |
| 92 | | Prod_cs |
| 93 | | Sort_cs of UnivGen.QualityOrSet.t |
| 94 | | Default_cs |
| 95 | |
| 96 | val equal : Environ.env -> t -> t -> bool |
| 97 | val print : t -> Pp.t |
| 98 | |
| 99 | (** Return the form of the component of a canonical structure *) |
| 100 | val of_constr : Evd.evar_map -> EConstr.t -> t * int option * EConstr.t list |
| 101 | |
| 102 | end |
| 103 | |
| 104 | |
| 105 | (** The canonical solution of a problem (proj,val) is a global |
| 106 | [constant = fun abs : abstractions_ty => body] and |
| 107 | [body = RecodConstructor params canon_values] and the canonical value |
| 108 | corresponding to val is [val cvalue_arguments]. |
| 109 | It is possible that val is one of the [abs] abstractions, eg [Default_cs], |
| 110 | and in that case [cvalue_abstraction = Some i] *) |
| 111 | module CanonicalSolution : sig |
| 112 | |
| 113 | type t = { |
| 114 | constant : EConstr.t; |
| 115 | |
| 116 | abstractions_ty : EConstr.t list; |
| 117 | body : EConstr.t; |
| 118 | |
| 119 | nparams : int; |
| 120 | params : EConstr.t list; |
| 121 | cvalue_abstraction : int option; |
| 122 | cvalue_arguments : EConstr.t list; |
| 123 | } |
| 124 | |
| 125 | (** [find (p,v)] returns a s such that p s = v. |
| 126 | The solution s gets a fresh universe instance and is decomposed into |
| 127 | bits for consumption by evarconv. Can raise [Not_found] on failure *) |
| 128 | val find : |
| 129 | Environ.env -> Evd.evar_map -> (Names.GlobRef.t * ValuePattern.t) -> |
| 130 | Evd.evar_map * t |
| 131 | |
| 132 | (** [is_open_canonical_projection env sigma t] is true if t is a FieldName |
| 133 | applied to term which is not a constructor. Used by evarconv not to |
| 134 | unfold too much and lose a projection too early *) |
| 135 | val is_open_canonical_projection : |
| 136 | ?metas:Reductionops.meta_handler -> |
| 137 | Environ.env -> Evd.evar_map -> EConstr.t -> bool |
| 138 | |
| 139 | val print : Environ.env -> Evd.evar_map -> t -> Pp.t |
| 140 | |
| 141 | end |
| 142 | |
| 143 | (** Low level access to the Canonical Structure database *) |
| 144 | module CSTable : sig |
| 145 | |
| 146 | type entry = { |
| 147 | projection : Names.GlobRef.t; |
| 148 | value : ValuePattern.t; |
| 149 | solution : Names.GlobRef.t; |
| 150 | } |
| 151 | |
| 152 | (** [all] returns the list of tuples { p ; v ; s } |
| 153 | Note: p s = v *) |
| 154 | val entries : unit -> entry list |
| 155 | |
| 156 | (** [entries_for p] returns the list of canonical entries that have |
| 157 | p as their FieldName *) |
| 158 | val entries_for : Environ.env -> projection:Names.GlobRef.t -> entry list |
| 159 | |
| 160 | end |
| 161 | |
| 162 | (** Some extra info for structures which are primitive records *) |
| 163 | module PrimitiveProjections : sig |
| 164 | |
| 165 | (** Sets up the mapping from constants to primitive projections *) |
| 166 | val register : Names.Projection.Repr.t -> Names.Constant.t -> unit |
| 167 | |
| 168 | val mem : Names.Constant.t -> bool |
| 169 | |
| 170 | val find_opt : Names.Constant.t -> Names.Projection.Repr.t option |
| 171 | |
| 172 | val find_opt_with_relevance : Names.Constant.t * EConstr.EInstance.t |
| 173 | -> (Names.Projection.Repr.t * EConstr.ERelevance.t) option |
| 174 | |
| 175 | val is_transparent_constant : TransparentState.t -> Names.Constant.t -> bool |
| 176 | end |