1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
|
(************************************************************************)
(* * The Coq Proof Assistant / The Coq Development Team *)
(* v * INRIA, CNRS and contributors - Copyright 1999-2018 *)
(* <O___,, * (see CREDITS file for the list of authors) *)
(* \VV/ **************************************************************)
(* // * This file is distributed under the terms of the *)
(* * GNU Lesser General Public License Version 2.1 *)
(* * (see LICENSE file for the text of the license) *)
(************************************************************************)
(** Abstract representations of values in a vo *)
(** NB: UPDATE THIS FILE EACH TIME cic.mli IS MODIFIED !
To ensure this file is up-to-date, 'make' now compares the md5 of cic.mli
with a copy we maintain here:
MD5 2c3436106636784886f122c8ab578098 checker/cic.mli
*)
(** We reify here the types of values present in a vo (see cic.mli),
in order to validate its structure. Maybe this reification
could become automatically generated someday ?
- [Any] stands for a value that we won't check,
- [Fail] means a value that shouldn't be there at all,
- [Tuple] provides a name and sub-values in this block
- [Sum] provides a name, a number of constant constructors,
and sub-values at each position of each possible constructed
variant
- [List] and [Opt] could have been defined via [Sum], but
having them here helps defining some recursive values below
- [Annot] is a no-op, just there for improving debug messages *)
type value =
| Any
| Fail of string
| Tuple of string * value array
| Sum of string * int * value array array
| Array of value
| List of value
| Opt of value
| Int
| String
| Annot of string * value
| Dyn
(** Some pseudo-constructors *)
let v_tuple name v = Tuple(name,v)
let v_sum name cc vv = Sum(name,cc,vv)
let v_enum name n = Sum(name,n,[||])
(** Ocaml standard library *)
let v_pair v1 v2 = v_tuple "*" [|v1; v2|]
let v_bool = v_enum "bool" 2
let v_unit = v_enum "unit" 1
let v_ref v = v_tuple "ref" [|v|]
let v_set v =
let rec s = Sum ("Set.t",1,
[|[|s; Annot("elem",v); s; Annot("bal",Int)|]|])
in s
let v_map vk vd =
let rec m = Sum ("Map.t",1,
[|[|m; Annot("key",vk); Annot("data",vd); m; Annot("bal",Int)|]|])
in m
let v_hset v = v_map Int (v_set v)
let v_hmap vk vd = v_map Int (v_map vk vd)
let v_pred v = v_pair v_bool (v_set v)
(* lib/future *)
let v_computation f =
Annot ("Future.computation",
v_ref
(v_sum "Future.comput" 0
[| [| Fail "Future.ongoing" |]; [| f |] |]))
(** kernel/names *)
let v_id = String
let v_dp = Annot ("dirpath", List v_id)
let v_name = v_sum "name" 1 [|[|v_id|]|]
let v_uid = v_tuple "uniq_ident" [|Int;String;v_dp|]
let rec v_mp = Sum("module_path",0,
[|[|v_dp|];
[|v_uid|];
[|v_mp;v_id|]|])
let v_kn = v_tuple "kernel_name" [|Any;v_mp;v_dp;v_id;Int|]
let v_cst = v_sum "cst|mind" 0 [|[|v_kn|];[|v_kn;v_kn|]|]
let v_ind = v_tuple "inductive" [|v_cst;Int|]
let v_cons = v_tuple "constructor" [|v_ind;Int|]
(** kernel/univ *)
let v_raw_level = v_sum "raw_level" 2 (* Prop, Set *)
[|(*Level*)[|Int;v_dp|]; (*Var*)[|Int|]|]
let v_level = v_tuple "level" [|Int;v_raw_level|]
let v_expr = v_tuple "levelexpr" [|v_level;Int|]
let v_univ = List v_expr
let v_cstrs =
Annot
("Univ.constraints",
v_set
(v_tuple "univ_constraint"
[|v_level;v_enum "order_request" 3;v_level|]))
let v_variance = v_enum "variance" 3
let v_instance = Annot ("instance", Array v_level)
let v_context = v_tuple "universe_context" [|v_instance;v_cstrs|]
let v_abs_context = v_context (* only for clarity *)
let v_abs_cum_info = v_tuple "cumulativity_info" [|v_abs_context; Array v_variance|]
let v_context_set = v_tuple "universe_context_set" [|v_hset v_level;v_cstrs|]
(** kernel/term *)
let v_sort = v_sum "sort" 0 [|[|v_enum "cnt" 2|];[|v_univ|]|]
let v_sortfam = v_enum "sorts_family" 3
let v_puniverses v = v_tuple "punivs" [|v;v_instance|]
let v_boollist = List v_bool
let v_caseinfo =
let v_cstyle = v_enum "case_style" 5 in
let v_cprint = v_tuple "case_printing" [|v_boollist;Array v_boollist;v_cstyle|] in
v_tuple "case_info" [|v_ind;Int;Array Int;Array Int;v_cprint|]
let v_cast = v_enum "cast_kind" 4
let v_proj = v_tuple "projection" [|v_cst; v_bool|]
let rec v_constr =
Sum ("constr",0,[|
[|Int|]; (* Rel *)
[|Fail "Var"|]; (* Var *)
[|Fail "Meta"|]; (* Meta *)
[|Fail "Evar"|]; (* Evar *)
[|v_sort|]; (* Sort *)
[|v_constr;v_cast;v_constr|]; (* Cast *)
[|v_name;v_constr;v_constr|]; (* Prod *)
[|v_name;v_constr;v_constr|]; (* Lambda *)
[|v_name;v_constr;v_constr;v_constr|]; (* LetIn *)
[|v_constr;Array v_constr|]; (* App *)
[|v_puniverses v_cst|]; (* Const *)
[|v_puniverses v_ind|]; (* Ind *)
[|v_puniverses v_cons|]; (* Construct *)
[|v_caseinfo;v_constr;v_constr;Array v_constr|]; (* Case *)
[|v_fix|]; (* Fix *)
[|v_cofix|]; (* CoFix *)
[|v_proj;v_constr|] (* Proj *)
|])
and v_prec = Tuple ("prec_declaration",
[|Array v_name; Array v_constr; Array v_constr|])
and v_fix = Tuple ("pfixpoint", [|Tuple ("fix2",[|Array Int;Int|]);v_prec|])
and v_cofix = Tuple ("pcofixpoint",[|Int;v_prec|])
let v_rdecl = v_sum "rel_declaration" 0 [| [|v_name; v_constr|]; (* LocalAssum *)
[|v_name; v_constr; v_constr|] |] (* LocalDef *)
let v_rctxt = List v_rdecl
let v_section_ctxt = v_enum "emptylist" 1
(** kernel/mod_subst *)
let v_delta_hint =
v_sum "delta_hint" 0 [|[|Int; Opt v_constr|];[|v_kn|]|]
let v_resolver =
v_tuple "delta_resolver"
[|v_map v_mp v_mp;
v_hmap v_kn v_delta_hint|]
let v_mp_resolver = v_tuple "" [|v_mp;v_resolver|]
let v_subst =
v_tuple "substitution"
[|v_map v_mp v_mp_resolver;
v_map v_uid v_mp_resolver|]
(** kernel/lazyconstr *)
let v_substituted v_a =
v_tuple "substituted" [|v_a; List v_subst|]
let v_cstr_subst = v_substituted v_constr
(** NB: Second constructor [Direct] isn't supposed to appear in a .vo *)
let v_lazy_constr =
v_sum "lazy_constr" 0 [|[|List v_subst;v_dp;Int|]|]
(** kernel/declarations *)
let v_impredicative_set = v_enum "impr-set" 2
let v_engagement = v_impredicative_set
let v_conv_level =
v_sum "conv_level" 2 [|[|Int|]|]
let v_oracle =
v_tuple "oracle" [|
v_map v_id v_conv_level;
v_hmap v_cst v_conv_level;
v_pred v_id;
v_pred v_cst;
|]
let v_pol_arity =
v_tuple "polymorphic_arity" [|List(Opt v_level);v_univ|]
let v_cst_def =
v_sum "constant_def" 0
[|[|Opt Int|]; [|v_cstr_subst|]; [|v_lazy_constr|]|]
let v_projbody =
v_tuple "projection_body"
[|v_cst;Int;Int;v_constr;
v_tuple "proj_eta" [|v_constr;v_constr|];
v_constr|]
let v_typing_flags =
v_tuple "typing_flags" [|v_bool; v_bool; v_oracle|]
let v_const_univs = v_sum "constant_universes" 0 [|[|v_context_set|]; [|v_abs_context|]|]
let v_cb = v_tuple "constant_body"
[|v_section_ctxt;
v_cst_def;
v_constr;
Any;
v_const_univs;
Opt v_projbody;
v_bool;
v_typing_flags|]
let v_recarg = v_sum "recarg" 1 (* Norec *)
[|[|v_ind|] (* Mrec *);[|v_ind|] (* Imbr *)|]
let rec v_wfp = Sum ("wf_paths",0,
[|[|Int;Int|]; (* Rtree.Param *)
[|v_recarg;Array v_wfp|]; (* Rtree.Node *)
[|Int;Array v_wfp|] (* Rtree.Rec *)
|])
let v_mono_ind_arity =
v_tuple "monomorphic_inductive_arity" [|v_constr;v_sort|]
let v_ind_arity = v_sum "inductive_arity" 0
[|[|v_mono_ind_arity|];[|v_pol_arity|]|]
let v_one_ind = v_tuple "one_inductive_body"
[|v_id;
v_rctxt;
v_ind_arity;
Array v_id;
Array v_constr;
Int;
Int;
List v_sortfam;
Array v_constr;
Array Int;
Array Int;
v_wfp;
Int;
Int;
Any|]
let v_finite = v_enum "recursivity_kind" 3
let v_mind_record = Annot ("mind_record",
Opt (Opt (v_tuple "record" [| v_id; Array v_cst; Array v_projbody |])))
let v_ind_pack_univs =
v_sum "abstract_inductive_universes" 0
[|[|v_context_set|]; [|v_abs_context|]; [|v_abs_cum_info|]|]
let v_ind_pack = v_tuple "mutual_inductive_body"
[|Array v_one_ind;
v_mind_record;
v_finite;
Int;
v_section_ctxt;
Int;
Int;
v_rctxt;
v_ind_pack_univs; (* universes *)
Opt v_bool;
v_typing_flags|]
let rec v_mae =
Sum ("module_alg_expr",0,
[|[|v_mp|]; (* SEBident *)
[|v_mae;v_mp|]; (* SEBapply *)
[|v_mae; Any|] (* SEBwith *)
|])
let rec v_sfb =
Sum ("struct_field_body",0,
[|[|v_cb|]; (* SFBconst *)
[|v_ind_pack|]; (* SFBmind *)
[|v_module|]; (* SFBmodule *)
[|v_modtype|] (* SFBmodtype *)
|])
and v_struc = List (Tuple ("label*sfb",[|v_id;v_sfb|]))
and v_sign =
Sum ("module_sign",0,
[|[|v_struc|]; (* NoFunctor *)
[|v_uid;v_modtype;v_sign|]|]) (* MoreFunctor *)
and v_mexpr =
Sum ("module_expr",0,
[|[|v_mae|]; (* NoFunctor *)
[|v_uid;v_modtype;v_mexpr|]|]) (* MoreFunctor *)
and v_impl =
Sum ("module_impl",2, (* Abstract, FullStruct *)
[|[|v_mexpr|]; (* Algebraic *)
[|v_sign|]|]) (* Struct *)
and v_noimpl = v_unit
and v_module =
Tuple ("module_body",
[|v_mp;v_impl;v_sign;Opt v_mexpr;v_context_set;v_resolver;Any|])
and v_modtype =
Tuple ("module_type_body",
[|v_mp;v_noimpl;v_sign;Opt v_mexpr;v_context_set;v_resolver;v_unit|])
(** kernel/safe_typing *)
let v_vodigest = Sum ("module_impl",0, [| [|String|]; [|String;String|] |])
let v_deps = Array (v_tuple "dep" [|v_dp;v_vodigest|])
let v_compiled_lib =
v_tuple "compiled" [|v_dp;v_module;v_deps;v_engagement;Any|]
(** Library objects *)
let v_obj = Dyn
let v_libobj = Tuple ("libobj", [|v_id;v_obj|])
let v_libobjs = List v_libobj
let v_libraryobjs = Tuple ("library_objects",[|v_libobjs;v_libobjs|])
(** STM objects *)
let v_frozen = Tuple ("frozen", [|List (v_pair Int Dyn); Opt Dyn|])
let v_states = v_pair Any v_frozen
let v_state = Tuple ("state", [|v_states; Any; v_bool|])
let v_vcs =
let data = Opt Any in
let vcs =
Tuple ("vcs",
[|Any; Any;
Tuple ("dag",
[|Any; Any; v_map Any (Tuple ("state_info",
[|Any; Any; Opt v_state; v_pair data Any|]))
|])
|])
in
let () = Obj.set_field (Obj.magic data) 0 (Obj.magic vcs) in
vcs
let v_uuid = Any
let v_request id doc =
Tuple ("request", [|Any; Any; doc; Any; id; String|])
let v_tasks = List (v_pair (v_request v_uuid v_vcs) v_bool)
let v_counters = Any
let v_stm_seg = v_pair v_tasks v_counters
(** Toplevel structures in a vo (see Cic.mli) *)
let v_libsum =
Tuple ("summary", [|v_dp;Array v_dp;v_deps|])
let v_lib =
Tuple ("library",[|v_compiled_lib;v_libraryobjs|])
let v_opaques = Array (v_computation v_constr)
let v_univopaques =
Opt (Tuple ("univopaques",[|Array (v_computation v_context_set);v_context_set;v_bool|]))
|