Debian Codegraph @

src/rocq_elpi_HOAS.mli

raw symbols SCIP
1 (* rocq-elpi: Coq terms as the object language of elpi *)
2 (* license: GNU Lesser General Public License Version 2.1 or later *)
3 (* ------------------------------------------------------------------------- *)
4
5 open Names
6 open Elpi.API
7 open Data
8 open RawData
9
10 (* Coq's Engine synchronization *)
11 type empty = [ `Options ]
12 type full = [ `Options | `Context ]
13
14 type ppoption = All | Most | Normal
15 type hole_mapping =
16 | Verbatim (* 1:1 correspondence between UVar and Evar *)
17 | Heuristic (* new UVar outside Llam is pruned before being linked to Evar *)
18 | Implicit (* No link, UVar is intepreted as a "hole" constant *)
19 type uinstanceoption =
20 | NoInstance
21 (* the elpi command involved has to generate a fresh instance *)
22 | ConcreteInstance of UVars.Instance.t
23 (* a concrete instance was provided, the command will use it *)
24 | VarInstance of (FlexibleData.Elpi.t * RawData.term list * inv_rel_key)
25 (* a variable was provided, the command will compute the instance to unify with it *)
26
27 [%%if coq = "9.0" || coq = "9.1"]
28 type univ_cst = Univ.univ_constraint
29 type univ_csts = Univ.Constraints.t
30 [%%else]
31 type univ_cst = Univ.UnivConstraint.t
32 type univ_csts = Univ.UnivConstraints.t
33 [%%endif]
34
35 type universe_decl = (Univ.Level.t list * bool) * (univ_csts * bool)
36 type universe_decl_cumul = ((Univ.Level.t * UVars.Variance.t option) list * bool) * (univ_csts * bool)
37
38 type universe_decl_option =
39 | NotUniversePolymorphic
40 | Cumulative of universe_decl_cumul
41 | NonCumulative of universe_decl
42
43 type options = {
44 hoas_holes : hole_mapping option;
45 local : bool option;
46 user_warns : UserWarn.t option;
47 primitive : bool option;
48 failsafe : bool; (* readback is resilient to illformed terms *)
49 ppwidth : int;
50 pp : ppoption;
51 pplevel : Constrexpr.entry_relative_level;
52 using : string option;
53 inline : Declaremods.inline;
54 uinstance : uinstanceoption;
55 universe_decl : universe_decl_option;
56 reversible : bool option;
57 keepunivs : bool option;
58 redflags : RedFlags.reds option;
59 no_tc: bool option;
60 algunivs : bool option;
61 }
62
63 type 'a conv_context = {
64 (* Elpi representation of the context *)
65 section : Names.Id.t list;
66 section_len : int;
67 proof : EConstr.named_context;
68 proof_len : int;
69 local : (int * EConstr.rel_declaration) list;
70 local_len : int;
71
72 (* Coq representation of the context *)
73 env : Environ.env;
74
75 (* Technical mappings *)
76 db2name : Names.Id.t Int.Map.t;
77 name2db : int Names.Id.Map.t;
78 db2rel : int Int.Map.t;
79 names : Id.Set.t;
80
81 (* Options (get-option context entries) *)
82 options : options;
83
84 (* the origin (when read from elpi) *)
85 hyps : hyps;
86 }
87 val empty_conv_context : options:options -> State.t -> empty conv_context
88 val get_options : depth:int -> hyps -> State.t -> options
89 val default_options : unit -> options
90 val upcast : [> `Options ] conv_context -> full conv_context
91
92 val set_initial_sigma : State.t -> Evd.evar_map -> State.t
93 val get_current_env_sigma : depth:int ->
94 Data.hyps -> constraints -> State.t -> State.t * full conv_context * Evd.evar_map * Conversion.extra_goals
95 val set_current_sigma : depth:int -> State.t -> Evd.evar_map -> State.t * Conversion.extra_goals
96 val get_global_env_current_sigma : depth:int ->
97 Data.hyps -> constraints -> State.t -> State.t * empty conv_context * Evd.evar_map * Conversion.extra_goals
98
99 (* HOAS of terms *)
100 val constr2lp :
101 depth:int -> ?calldepth:int -> full conv_context -> constraints -> State.t ->
102 EConstr.t -> State.t * term * Conversion.extra_goals
103
104 (* readback: adds to the evar map universes and evars in the term *)
105 val lp2constr :
106 depth:int -> full conv_context -> constraints -> State.t ->
107 term -> State.t * EConstr.t * Conversion.extra_goals
108
109 (* variants in the global context *)
110 val constr2lp_closed : depth:int -> ?calldepth:int -> empty conv_context -> constraints -> State.t ->
111 EConstr.t -> State.t * term * Conversion.extra_goals
112 val lp2constr_closed : depth:int -> empty conv_context -> constraints -> State.t ->
113 term -> State.t * EConstr.t * Conversion.extra_goals
114 val constr2lp_closed_ground : depth:int -> ?calldepth:int -> empty conv_context -> constraints -> State.t ->
115 EConstr.t -> State.t * term * Conversion.extra_goals
116 val lp2constr_closed_ground : depth:int -> empty conv_context -> constraints -> State.t ->
117 term -> State.t * EConstr.t * Conversion.extra_goals
118
119 (* another variant, to call the pretyper *)
120 val lp2skeleton :
121 depth:int -> full conv_context -> constraints -> State.t ->
122 term -> State.t * Glob_term.glob_constr * Conversion.extra_goals
123
124 type coercion_status = Regular | Off | Reversible
125 type record_field_spec = { name : Name.t; is_coercion : coercion_status; is_canonical : bool }
126
127 [%%if coq = "9.0"]
128 val lp2inductive_entry :
129 depth:int -> empty conv_context -> constraints -> State.t -> term ->
130 State.t * (DeclareInd.default_dep_elim list * Entries.mutual_inductive_entry * Univ.ContextSet.t * UnivNames.universe_binders * (bool * record_field_spec list) option * DeclareInd.one_inductive_impls list) * Conversion.extra_goals
131 [%%else]
132 val lp2inductive_entry :
133 depth:int -> empty conv_context -> constraints -> State.t -> term ->
134 State.t * (DeclareInd.default_dep_elim list * Entries.mutual_inductive_entry * Univ.ContextSet.t * UState.named_universes_entry * (bool * record_field_spec list) option * DeclareInd.one_inductive_impls list) * Conversion.extra_goals
135 [%%endif]
136
137 [%%if coq = "9.0"]
138 val lp2record_field_spec : record_field_spec -> Name.t * Record.Internal.projection_flags
139 [%%else]
140 val lp2record_field_spec : record_field_spec -> Name.t * Record.Data.projection_flags
141 [%%endif]
142
143 val inductive_decl2lp :
144 depth:int -> empty conv_context -> constraints -> State.t -> (Names.MutInd.t * UVars.Instance.t * Declarations.mutual_inductive_body * (Glob_term.binding_kind list list * Glob_term.binding_kind list list list)) ->
145 State.t * term * Conversion.extra_goals
146
147 val inductive_entry2lp :
148 depth:int -> empty conv_context -> constraints -> State.t -> loose_udecl:bool -> ComInductive.Mind_decl.t ->
149 State.t * term * Conversion.extra_goals
150
151 val record_entry2lp :
152 depth:int -> empty conv_context -> constraints -> State.t -> loose_udecl:bool ->Record.Record_decl.t ->
153 State.t * term * Conversion.extra_goals
154 type annot_name = (Name.t,EConstr.ERelevance.t) Context.pbinder_annot
155
156 val in_elpi_id : Names.Name.t -> term
157 val in_elpi_bool : State.t -> bool -> term
158 val in_elpi_arity_parameter : annot_name -> imp:term -> term -> term -> term
159 val in_elpi_inductive_parameter : annot_name -> imp:term -> term -> term -> term
160 val in_elpi_arity : term -> term
161 val in_elpi_indtdecl_record : Names.Name.t -> term -> Names.Name.t -> term -> term
162 val in_elpi_indtdecl_endrecord : unit -> term
163 val in_elpi_indtdecl_field : depth:int -> State.t -> record_field_spec -> term -> term -> State.t * term
164 val in_elpi_indtdecl_inductive : State.t -> Declarations.recursivity_kind -> Names.Name.t -> term -> term list -> term
165 val in_elpi_indtdecl_constructor : Names.Name.t -> term -> term
166
167 val sealed_goal2lp : depth:int -> State.t -> Evar.t -> State.t * term * Conversion.extra_goals
168 val sealed_maybe_solved_goal2lp : depth:int -> State.t -> Evar.t -> State.t * term * Conversion.extra_goals
169 val lp2goal : depth:int -> hyps -> constraints -> State.t -> term ->
170 State.t * (full conv_context * Evar.t * term list) * Conversion.extra_goals
171
172 (* checks the evar context is the same as the one in input *)
173 val goal2lp : depth:int -> constraints -> State.t -> full conv_context -> Evar.t ->
174 (State.t * term * Conversion.extra_goals,EConstr.named_context) Result.t
175
176 (* *** Low level API to reuse parts of the embedding *********************** *)
177 val unspec2opt : 'a Elpi.Builtin.unspec -> 'a option
178 val opt2unspec : 'a option -> 'a Elpi.Builtin.unspec
179
180 val in_elpi_gr : depth:int -> State.t -> Names.GlobRef.t -> term
181 val in_elpi_poly_gr : depth:int -> State.t -> Names.GlobRef.t -> term -> term
182 val in_elpi_poly_gr_instance : depth:int -> State.t -> Names.GlobRef.t -> UVars.Instance.t -> term
183 val in_elpi_flex_sort : term -> term
184 val in_elpi_sort : depth:int -> 'a conv_context -> constraints -> state -> Sorts.t -> state * term * Conversion.extra_goals
185 val in_elpi_prod : annot_name -> term -> term -> term
186 val in_elpi_lam : annot_name -> term -> term -> term
187 val in_elpi_let : annot_name -> term -> term -> term -> term
188 val in_elpi_appl : depth:int -> term -> term list -> term
189 val in_elpi_match : term -> term -> term list -> term
190 val in_elpi_fix : annot_name -> int -> term -> term -> term
191 val in_elpi_mfix : (annot_name * int * term) list -> int -> term list -> term
192 val in_elpi_name : annot_name -> term
193
194 val set_coq : Elpi.API.Ast.Scope.language -> unit
195
196 (* gref *)
197 val in_elpiast_gref : loc:Ast.Loc.t -> Names.GlobRef.t -> Ast.Term.t
198 (* term *)
199 val in_elpiast_gr : loc:Ast.Loc.t -> Names.GlobRef.t -> Ast.Term.t
200 val in_elpiast_poly_gr : loc:Ast.Loc.t -> Names.GlobRef.t -> Ast.Term.t -> Ast.Term.t
201 val in_elpiast_poly_gr_instance : loc:Ast.Loc.t -> Names.GlobRef.t -> UVars.Instance.t -> Ast.Term.t
202 val in_elpiast_flex_sort : loc:Ast.Loc.t -> Ast.Term.t -> Ast.Term.t
203 val in_elpiast_sort : loc:Ast.Loc.t -> state -> Sorts.t -> Ast.Term.t
204 val in_elpiast_prod : loc:Ast.Loc.t -> annot_name -> Ast.Term.t -> Ast.Term.t -> Ast.Term.t
205 val in_elpiast_lam : loc:Ast.Loc.t -> annot_name -> Ast.Term.t -> Ast.Term.t -> Ast.Term.t
206 val in_elpiast_let : loc:Ast.Loc.t -> annot_name -> ty:Ast.Term.t -> bo:Ast.Term.t -> Ast.Term.t -> Ast.Term.t
207 val in_elpiast_appl : loc:Ast.Loc.t -> Ast.Term.t -> Ast.Term.t list -> Ast.Term.t
208 val in_elpiast_match : loc:Ast.Loc.t -> Ast.Term.t -> Ast.Term.t -> Ast.Term.t list -> Ast.Term.t
209 val in_elpiast_fix : loc:Ast.Loc.t -> annot_name -> int -> Ast.Term.t -> Ast.Term.t -> Ast.Term.t
210 val in_elpiast_mfix : loc:Ast.Loc.t -> (annot_name * int * Ast.Term.t) list -> int -> Ast.Term.t list -> Ast.Term.t
211 val in_elpiast_name : loc:Ast.Loc.t -> annot_name -> Ast.Term.t
212 val in_elpiast_decl : loc:Ast.Loc.t -> v:Ast.Term.t -> annot_name -> ty:Ast.Term.t -> Ast.Term.t
213 val in_elpiast_def : loc:Ast.Loc.t -> v:Ast.Term.t -> annot_name -> ty:Ast.Term.t -> bo:Ast.Term.t -> Ast.Term.t
214
215 val mk_coq_name : State.t -> Names.Id.t -> State.t * annot_name
216 val mk_coq_annot : State.t -> Names.Name.t -> State.t * annot_name
217
218 val in_coq_name : depth:int -> State.t -> term -> State.t * annot_name * Conversion.extra_goals
219 val is_coq_name : depth:int -> term -> bool
220
221 val in_coq_imp : depth:int -> State.t -> term -> State.t * Glob_term.binding_kind
222 val in_elpi_imp : depth:int -> State.t -> Glob_term.binding_kind -> State.t * term
223
224 (* for quotations *)
225 val in_elpi_app_Arg : depth:int -> term -> term list -> term
226
227 type global_constant = Variable of Names.Id.t | Constant of Names.Constant.t
228 val gref : Names.GlobRef.t Conversion.t
229 val inductive : inductive Conversion.t
230 val constructor : constructor Conversion.t
231 val constant : global_constant Conversion.t
232 val sort : (Sorts.t,'a conv_context,constraints) ContextualConversion.t
233 val global_constant_of_globref : Names.GlobRef.t -> global_constant
234 val abbreviation : Globnames.abbreviation Conversion.t
235 val implicit_kind : Glob_term.binding_kind Conversion.t
236 val collect_term_variables : depth:int -> term -> Names.Id.t list
237 val subst_cdata : Mod_subst.substitution -> Elpi.API.RawOpaqueData.t -> Elpi.API.RawOpaqueData.t
238 type pstring = Pstring.t
239 type primitive_value =
240 | Uint63 of Uint63.t
241 | Float64 of Float64.t
242 | Pstring of pstring
243 | Projection of Projection.t
244 val primitive_value : primitive_value Conversion.t
245 val in_elpi_primitive : depth:int -> state -> primitive_value -> state * term
246 val in_elpiast_primitive : loc:Ast.Loc.t -> primitive_value -> Ast.Term.t
247
248 val uinstance : UVars.Instance.t Conversion.t
249
250 [%%if coq = "9.0" || coq = "9.1"]
251 val universe_constraint : Univ.univ_constraint Conversion.t
252 [%%else]
253 val universe_constraint : Univ.UnivConstraint.t Conversion.t
254 [%%endif]
255
256 val universe_variance : (Univ.Level.t * UVars.Variance.t option) Conversion.t
257 type any_universe_decl =
258 | NonCumul of universe_decl
259 | Cumul of universe_decl_cumul
260 val universe_decl : any_universe_decl Conversion.t
261
262 module GRMap : Elpi.API.Utils.Map.S with type key = Names.GlobRef.t
263 module GRSet : Elpi.API.Utils.Set.S with type elt = Names.GlobRef.t
264
265 module UnivMap : Elpi.API.Utils.Map.S with type key = Univ.Universe.t
266 module UnivSet : Elpi.API.Utils.Set.S with type elt = Univ.Universe.t
267
268 module UnivLevelMap : Elpi.API.Utils.Map.S with type key = Univ.Level.t
269 module UnivLevelSet : Elpi.API.Utils.Set.S with type elt = Univ.Level.t
270
271
272 val compute_with_uinstance :
273 depth:int -> options -> state ->
274 (state -> 'a -> UVars.Instance.t option -> state * 'c * UVars.Instance.t option) ->
275 'a ->
276 UVars.Instance.t option ->
277 state * 'c * UVars.Instance.t option * Conversion.extra_goals
278
279 (* CData relevant for other modules, e.g the one exposing Coq's API *)
280 val universe_level_variable : Univ.Level.t Conversion.t
281 val univ : Univ.Universe.t Conversion.t
282 val isuniv : RawOpaqueData.t -> bool
283 val univout : RawOpaqueData.t -> Univ.Universe.t
284
285 val is_sort : depth:int -> term -> bool
286 val is_prod : depth:int -> term -> (term * term) option (* ty, bo @ depth+1 *)
287 val is_let : depth:int -> term -> (term * term * term) option (* ty, d, bo @ depth+1 *)
288 val is_lam : depth:int -> term -> (term * term) option (* ty, bo @ depth+1 *)
289
290 val isname : RawOpaqueData.t -> bool
291 val nameout : RawOpaqueData.t -> annot_name
292 val name : annot_name Conversion.t
293
294 type global_or_pglobal =
295 | Global of term option
296 | PGlobal of term option * UVars.Instance.t option
297 | NotGlobal
298 | Var
299 val is_global_or_pglobal : depth:int -> term -> global_or_pglobal
300
301 val in_elpi_modpath : ty:bool -> Names.ModPath.t -> term
302 val is_modpath : depth:int -> term -> bool
303 val is_modtypath : depth:int -> term -> bool
304 val in_coq_modpath : depth:int -> term -> Names.ModPath.t
305 val modpath : Names.ModPath.t Conversion.t
306 val modtypath : Names.ModPath.t Conversion.t
307 val module_inline_default : Declaremods.inline Conversion.t
308 val reduction_flags : RedFlags.reds Conversion.t
309
310 type module_item =
311 | Module of Names.ModPath.t * module_item list
312 | ModuleType of Names.ModPath.t
313 | Gref of Names.GlobRef.t
314 | Functor of Names.ModPath.t * Names.ModPath.t list
315 | FunctorType of Names.ModPath.t * Names.ModPath.t list
316
317 [%%if coq = "9.0"]
318 val in_elpi_module : depth:int -> State.t -> ModPath.t -> Declarations.module_body -> module_item list
319 val in_elpi_module_type : Declarations.module_type_body -> string list
320 [%%else]
321 val in_elpi_module : depth:int -> State.t -> ModPath.t -> Mod_declarations.module_body -> module_item list
322 val in_elpi_module_type : Mod_declarations.module_type_body -> string list
323 [%%endif]
324
325 val coercion_status : coercion_status Conversion.t
326 type record_field_att =
327 | Coercion of coercion_status
328 | Canonical of bool
329 val record_field_att : record_field_att Conversion.t
330
331 val add_constraints : State.t -> UnivProblem.Set.t -> State.t
332 val mk_global : State.t -> Names.GlobRef.t -> UVars.Instance.t option ->
333 State.t * EConstr.t * UVars.Instance.t option
334 val poly_ctx_size_of_gref : Environ.env -> Names.GlobRef.t -> int * int
335 val body_of_constant :
336 State.t -> Names.Constant.t -> UVars.Instance.t option ->
337 State.t * EConstr.t option * UVars.Instance.t option
338
339 val grab_global_env_drop_univs_and_sigma : State.t -> State.t
340 val grab_global_env_drop_sigma : State.t -> State.t
341
342 val grab_global_env : uctx:Univ.ContextSet.t -> State.t -> State.t
343 val grab_global_env_drop_sigma_keep_univs : uctx:Univ.ContextSet.t -> State.t -> State.t
344 val mk_decl : depth:int -> annot_name -> ty:term -> term
345 (* Adds an Arg for the normal form with ctx_len context entry vars in scope *)
346
347 val mk_def :
348 depth:int -> annot_name -> bo:term -> ty:term -> term
349
350 val get_global_env : State.t -> Environ.env
351 val get_sigma : State.t -> Evd.evar_map
352 val update_sigma : State.t -> (Evd.evar_map -> Evd.evar_map) -> State.t
353
354 val solvegoals2query :
355 Evd.evar_map -> Evar.t list -> Elpi.API.Ast.Loc.t -> main:'a list ->
356 in_elpi_tac_arg:(base:'base -> depth:int -> ?calldepth:int -> 'b conv_context -> hyp list -> Evd.evar_map -> State.t -> 'a -> State.t * term list * Conversion.extra_goals) ->
357 depth:int -> base:'base -> State.t -> State.t * term * Conversion.extra_goals
358 val txtgoals2query :
359 Evd.evar_map -> Evar.t list -> Elpi.API.Ast.Loc.t -> main:string ->
360 depth:int -> base:Elpi.API.Compile.program -> State.t -> State.t * term * Conversion.extra_goals
361
362 val tclSOLUTION2EVD : eta_contract_solution:bool -> Evd.evar_map -> Elpi.API.Data.solution -> Evar.t list -> unit Proofview.tactic
363 val solution2evd : eta_contract_solution:bool -> Evd.evar_map -> Elpi.API.Data.solution -> Evar.Set.t -> Evd.evar_map * Evar.t list * Evar.t list
364 val sealed_goals2ev : depth:int -> constraints -> state -> Elpi.API.Data.pretty_printer_context -> term -> Evar.t list option
365
366 val show_coq_engine : ?with_univs:bool -> State.t -> string
367 val show_coq_elpi_engine_mapping : State.t -> string
368
369 val type_of_global : state -> GlobRef.t -> UVars.Instance.t option -> state * (EConstr.t * UVars.Instance.t)
370 val minimize_universes : state -> state
371 val new_univ_level_variable : ?flexible:bool -> state -> state * (Univ.Level.t * Univ.Universe.t)
372 val constraint_eq : Sorts.t -> Sorts.t -> UnivProblem.t
373 val constraint_leq : Sorts.t -> Sorts.t -> UnivProblem.t
374 val add_universe_constraint : state -> UnivProblem.t -> state
375 val force_level_of_universe : state -> Univ.Universe.t -> state * Univ.Level.t * Univ.Universe.t * Sorts.t
376 val purge_algebraic_univs_sort : state -> EConstr.ESorts.t -> state * Sorts.t
377 val ideclc : constant
378 val uideclc : constant
379 val merge_universe_context : state -> UState.t -> state
380 val restricted_sigma_of : Univ.Level.Set.t -> state -> Evd.evar_map
381 val universes_of_term : state -> EConstr.t -> Univ.Level.Set.t
382
383 val poly_cumul_udecl_variance_of_options : state -> options -> state * bool * bool * UState.universe_decl * Entries.variance_entry
384 val universes_of_udecl : state -> UState.universe_decl -> Univ.Level.Set.t
385
386 val mind_record : Declarations.mind_specif -> Declarations.record_info
387
388 val univ_of_sort : Sorts.t -> Univ.Universe.t