Debian Codegraph @

plugins/extraction/miniml.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 (*s Target language for extraction: a core ML called MiniML. *)
12
13 open Names
14
15 (* Informativity data for sort polymorphism *)
16 module InfvInst :
17 sig
18 type t
19 val compare : t -> t -> int
20 val equal : t -> t -> bool
21
22 val empty : t
23 (** No bound sort variables *)
24
25 val generate : UVars.AbstractContext.t -> t list
26 (** 2^n possible instances for this context *)
27
28 val default : UVars.AbstractContext.t -> t
29 (** All sorts informative *)
30
31 val ground : UVars.Instance.t -> t
32 (** From a ground instance returns an informativity instance *)
33
34 val instantiate : UVars.AbstractContext.t -> t -> UVars.Instance.t
35 (** The other way around *)
36
37 val encode : t -> string option
38 (** A string that can be used as an identifier suffix, guaranteed to be
39 injective for instances of the same length. *)
40
41 end
42
43 type global = { glob : GlobRef.t; inst : InfvInst.t }
44
45 (* The [signature] type is used to know how many arguments a CIC
46 object expects, and what these arguments will become in the ML
47 object. *)
48
49 (* We eliminate from terms:
50 1) types
51 2) logical parts
52 3) user-declared implicit arguments of a constant of constructor
53 *)
54
55 type kill_reason =
56 | Ktype
57 | Kprop
58 | Kimplicit of global * int (* n-th arg of a cst or construct *)
59
60 type sign = Keep | Kill of kill_reason
61
62
63 (* Convention: outmost lambda/product gives the head of the list. *)
64
65 type signature = sign list
66
67 (*s ML type expressions. *)
68
69 type ml_type =
70 | Tarr of ml_type * ml_type
71 | Tglob of global * ml_type list
72 | Tvar of int
73 | Tvar' of int (* same as Tvar, used to avoid clash *)
74 | Tmeta of ml_meta (* used during ML type reconstruction *)
75 | Tdummy of kill_reason
76 | Tunknown
77 | Taxiom
78
79 and ml_meta = { id : int; mutable contents : ml_type option }
80
81 (* ML type schema.
82 The integer is the number of variable in the schema. *)
83
84 type ml_schema = int * ml_type
85
86 (*s ML inductive types. *)
87
88 type inductive_kind =
89 | Singleton
90 | Coinductive
91 | Standard
92 | Record of global option list (* None for anonymous field *)
93
94 (* A [ml_ind_packet] is the miniml counterpart of a [one_inductive_body].
95 If the inductive is logical ([ip_logical = false]), then all other fields
96 are unused. Otherwise,
97 [ip_sign] is a signature concerning the arguments of the inductive,
98 [ip_vars] contains the names of the type variables surviving in ML,
99 [ip_types] contains the ML types of all constructors.
100 *)
101
102 type ml_ind_packet = {
103 ip_typename : Id.t;
104 ip_typename_ref : global;
105 ip_consnames : Id.t array;
106 ip_consnames_ref : global array;
107 ip_logical : bool;
108 ip_sign : signature;
109 ip_vars : Id.t list;
110 ip_types : (ml_type list) array
111 }
112
113 (* [ip_nparams] contains the number of parameters. *)
114
115 type equiv =
116 | NoEquiv
117 | Equiv of KerName.t
118 | RenEquiv of string
119
120 type ml_ind = {
121 ind_kind : inductive_kind;
122 ind_nparams : int;
123 ind_packets : ml_ind_packet array;
124 ind_equiv : equiv
125 }
126
127 (*s ML terms. *)
128
129 type ml_ident =
130 | Dummy
131 | Id of Id.t
132 | Tmp of Id.t
133
134 (** We now store some typing information on constructors
135 and cases to avoid type-unsafe optimisations. This will be
136 either the type of the applied constructor or the type
137 of the head of the match.
138 *)
139
140 (** Nota : the constructor [MLtuple] and the extension of [MLcase]
141 to general patterns have been proposed by P.N. Tollitte for
142 his Relation Extraction plugin. [MLtuple] is currently not
143 used by the main extraction, as well as deep patterns. *)
144
145 type ml_branch = ml_ident list * ml_pattern * ml_ast
146
147 and ml_ast =
148 | MLrel of int
149 | MLapp of ml_ast * ml_ast list
150 | MLlam of ml_ident * ml_ast
151 | MLletin of ml_ident * ml_ast * ml_ast
152 | MLglob of global
153 | MLcons of ml_type * global * ml_ast list
154 | MLtuple of ml_ast list
155 | MLcase of ml_type * ml_ast * ml_branch array
156 | MLfix of int * Id.t array * ml_ast array
157 | MLexn of string
158 | MLdummy of kill_reason
159 | MLaxiom of string
160 | MLmagic of ml_ast
161 | MLuint of Uint63.t
162 | MLfloat of Float64.t
163 | MLstring of Pstring.t
164 | MLparray of ml_ast array * ml_ast
165
166 and ml_pattern =
167 | Pcons of global * ml_pattern list
168 | Ptuple of ml_pattern list
169 | Prel of int (** Cf. the idents in the branch. [Prel 1] is the last one. *)
170 | Pwild
171 | Pusual of global (** Shortcut for Pcons (r,[Prel n;...;Prel 1]) **)
172
173 (*s ML declarations. *)
174
175 type ml_decl =
176 | Dind of ml_ind
177 | Dtype of global * Id.t list * ml_type
178 | Dterm of global * ml_ast * ml_type
179 | Dfix of global array * ml_ast array * ml_type array
180
181 type ml_spec =
182 | Sind of ml_ind
183 | Stype of global * Id.t list * ml_type option
184 | Sval of global * ml_type
185
186 type ml_specif =
187 | Spec of ml_spec
188 | Smodule of ml_module_type
189 | Smodtype of ml_module_type
190
191 and ml_module_type =
192 | MTident of ModPath.t
193 | MTfunsig of MBId.t * ml_module_type * ml_module_type
194 | MTsig of ModPath.t * ml_module_sig
195 | MTwith of ml_module_type * ml_with_declaration
196
197 and ml_with_declaration =
198 | ML_With_type of InfvInst.t * Id.t list * Id.t list * ml_type
199 | ML_With_module of Id.t list * ModPath.t
200
201 and ml_module_sig = (Id.t * ml_specif) list
202
203 type ml_structure_elem =
204 | SEdecl of ml_decl
205 | SEmodule of ml_module
206 | SEmodtype of ml_module_type
207
208 and ml_module_expr =
209 | MEident of ModPath.t
210 | MEfunctor of MBId.t * ml_module_type * ml_module_expr
211 | MEstruct of ModPath.t * ml_module_structure
212 | MEapply of ml_module_expr * ml_module_expr
213
214 and ml_module_structure = (Id.t * ml_structure_elem) list
215
216 and ml_module =
217 { ml_mod_expr : ml_module_expr;
218 ml_mod_type : ml_module_type }
219
220 (* NB: we do not translate the [mod_equiv] field, since [mod_equiv = mp]
221 implies that [mod_expr = MEBident mp]. Same with [msb_equiv]. *)
222
223 type ml_structure = (ModPath.t * ml_module_structure) list
224
225 type ml_signature = (ModPath.t * ml_module_sig) list
226
227 type unsafe_needs = {
228 mldummy : bool;
229 tdummy : bool;
230 tunknown : bool;
231 magic : bool
232 }
233
234 type 's language_descr = {
235 keywords : Id.Set.t;
236
237 (* Concerning the source file *)
238 file_suffix : string;
239 file_naming : 's -> DirPath.t -> string;
240 (* the second argument is a comment to add to the preamble *)
241 preamble :
242 's -> Id.t -> Pp.t option -> DirPath.Set.t -> unsafe_needs ->
243 Pp.t;
244 pp_struct : 's -> ml_structure -> Pp.t;
245
246 (* Concerning a possible interface file *)
247 sig_suffix : string option;
248 (* the second argument is a comment to add to the preamble *)
249 sig_preamble :
250 's -> Id.t -> Pp.t option -> DirPath.Set.t -> unsafe_needs ->
251 Pp.t;
252 pp_sig : 's -> ml_signature -> Pp.t;
253
254 (* for an isolated declaration print *)
255 pp_decl : 's -> ml_decl -> Pp.t;
256
257 }