Debian Codegraph @

pretyping/typeclasses.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 Evd
14 open Environ
15
16 (* Core typeclasses hints *)
17 type 'a hint_info_gen =
18 { hint_priority : int option;
19 hint_pattern : 'a option }
20
21 type hint_info = (Id.Set.t * Pattern.constr_pattern) hint_info_gen
22
23 type class_method = {
24 meth_name : Name.t;
25 meth_const : Constant.t option;
26 }
27
28 (** This module defines type-classes *)
29 type typeclass = {
30 cl_univs : UVars.AbstractContext.t;
31 (** The toplevel universe quantification in which the typeclass lives. In
32 particular, [cl_props] and [cl_context] are quantified over it. *)
33
34 cl_impl : GlobRef.t;
35 (** The class implementation: a record parameterized by the context with defs in it or a definition if
36 the class is a singleton. This acts as the class' global identifier. *)
37
38 cl_context : Constr.rel_context;
39 (** Context in which the definitions are typed. *)
40
41 cl_trivial : bool;
42 (** Class declared with "Class Foo params := {}", produces 0 goals in interactive mode. *)
43
44 cl_props : Constr.rel_context;
45 (** Context of definitions and properties on defs, used for "Instance := {}".
46 If [cl_impl] is a record this is the arguments of its constructor (without parameters).
47 Otherwise it is a single [LocalAssum] of type convertible to [cl_impl]. *)
48
49 cl_projs : class_method list;
50 (** The methods implementations of the typeclass as projections.
51 Some may be undefinable due to sorting restrictions or simply undefined if
52 no name is provided. Used for dumpglob in "Instance := {}" and in elpi. *)
53
54 cl_strict : bool;
55 (** Whether we use matching or full unification during resolution *)
56
57 cl_unique : bool;
58 (** Whether we can assume that instances are unique, which allows
59 no backtracking and sharing of resolution. *)
60 }
61
62 type instance = {
63 is_class: GlobRef.t;
64 is_info: hint_info;
65 is_impl: GlobRef.t;
66 }
67
68 val instances : env -> GlobRef.t -> instance list option
69 (** [None] if not a class *)
70
71 val instances_exn : env -> evar_map -> GlobRef.t -> instance list
72 (** raise [TypeClassError] if not a class *)
73
74 val typeclasses : unit -> typeclass list
75 val all_instances : unit -> instance list
76
77 val load_class : env -> typeclass -> unit
78
79 val load_instance : env -> instance -> unit
80 val remove_instance : env -> instance -> unit
81
82 val class_info : env -> GlobRef.t -> typeclass option
83 (** [None] if not a class *)
84
85 val class_info_exn : env -> evar_map -> GlobRef.t -> typeclass
86 (** raise [TypeClassError] if not a class *)
87
88 (** These raise a UserError if not a class.
89 Caution: the typeclass structures is not instantiated w.r.t. the universe instance.
90 This is done separately by typeclass_univ_instance. *)
91 val dest_class_app : env -> evar_map -> EConstr.constr -> (typeclass * EConstr.EInstance.t) * constr list
92
93 (** Just return None if not a class *)
94 val class_of_constr : env -> evar_map -> EConstr.constr ->
95 (EConstr.rel_context * ((typeclass * EConstr.EInstance.t) * constr list)) option
96
97 val instance_impl : instance -> GlobRef.t
98
99 val hint_priority : instance -> int option
100
101 val is_class : env -> GlobRef.t -> bool
102
103 (** Filter which evars to consider for resolution. *)
104 type evar_filter = Evar.t -> Evar_kinds.t Lazy.t -> bool
105 val all_evars : evar_filter
106 val all_goals : evar_filter
107 val no_goals : evar_filter
108 val no_goals_or_obligations : evar_filter
109
110 (** Resolvability.
111 Only undefined evars can be marked or checked for resolvability.
112 They represent type-class search roots.
113
114 A resolvable evar is an evar the type-class engine may try to solve
115 An unresolvable evar is an evar the type-class engine will NOT try to solve
116 *)
117
118 val make_unresolvables : (Evar.t -> bool) -> evar_map -> evar_map
119
120 val is_class_evar : env -> evar_map -> undefined evar_info -> bool
121 val is_class_type : env -> evar_map -> EConstr.types -> bool
122
123 val resolve_typeclasses : ?filter:evar_filter -> ?unique:bool ->
124 ?fail:bool -> env -> evar_map -> evar_map
125
126 val get_filtered_typeclass_evars : evar_filter -> evar_map -> Evar.Set.t
127
128 val error_unresolvable : env -> evar_map -> Evar.Set.t -> 'a
129
130 (** A plugin can override the TC resolution engine by calling these two APIs.
131 Beware this action is not registed in the summary (the Undo system) so
132 it is up to the plugin to do so. *)
133 val set_solve_all_instances : (env -> evar_map -> evar_filter -> bool -> bool -> evar_map) -> unit
134
135 val get_typeclasses_unique_solutions : unit -> bool
136
137 val is_maybe_class_type : env -> evar_map -> EConstr.types -> bool
138
139 (* Deprecated *)
140 val resolve_one_typeclass : ?unique:bool -> env -> evar_map -> EConstr.types -> evar_map * EConstr.constr
141 [@@deprecated "(9.0) Use Class_tactics.resolve_one_typeclass (\"unique\" argument was ignored)"]
142
143 val set_solve_one_instance : (env -> evar_map -> EConstr.types -> evar_map * EConstr.constr) -> unit
144 [@@deprecated "(9.0) For internal use only"]