Debian Codegraph @

kernel/names.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 (** This file defines a lot of different notions of names used pervasively in
12 the kernel as well as in other places. The essential datatypes exported by
13 this API are:
14
15 - Id.t is the type of identifiers, that is morally a subset of strings which
16 only contains Unicode characters of the Letter kind (and a few more).
17 - Name.t is an ad-hoc variant of Id.t option allowing to handle optionally
18 named objects.
19 - DirPath.t represents generic paths as sequences of identifiers.
20 - ModPath.t are module paths.
21 - KerName.t are absolute names of objects in Rocq.
22 *)
23
24 open Util
25
26 (** {6 Identifiers } *)
27
28 (** Representation and operations on identifiers. *)
29 module Id :
30 sig
31 type t
32 (** Values of this type represent (Rocq) identifiers. *)
33
34 val equal : t -> t -> bool
35 (** Equality over identifiers. *)
36
37 val compare : t -> t -> int
38 (** Comparison over identifiers. *)
39
40 val hash : t -> int
41 (** Hash over identifiers. *)
42
43 val is_valid : string -> bool
44 (** Check that a string may be converted to an identifier. *)
45
46 val is_valid_ident_part : string -> bool
47 (** Check that a string is a valid part of an identifier *)
48
49 val of_bytes : bytes -> t
50 val of_string : string -> t
51 (** Converts a string into an identifier.
52 @raise UserError if the string is invalid as an identifier. *)
53
54 val of_string_soft : string -> t
55 (** Same as {!of_string} except that any string made of supported UTF-8 characters is accepted.
56 @raise UserError if the string is invalid as an UTF-8 string. *)
57
58 val to_string : t -> string
59 (** Converts a identifier into an string. *)
60
61 val print : t -> Pp.t
62 (** Pretty-printer. *)
63
64 module Set : Set.ExtS with type elt = t
65 (** Finite sets of identifiers. *)
66
67 module Map : Map.ExtS with type key = t and module Set := Set
68 (** Finite maps of identifiers. *)
69
70 module Pred : Predicate.S with type elt = t
71 (** Predicates over identifiers. *)
72
73 module List : List.MonoS with type elt = t
74 (** Operations over lists of identifiers. *)
75
76 val hcons : t Hashcons.f
77 (** Hashconsing of identifiers. *)
78
79 end
80
81 (** Representation and operations on identifiers that are allowed to be anonymous
82 (i.e. "_" in concrete syntax). *)
83 module Name :
84 sig
85 type t = Anonymous (** anonymous identifier *)
86 | Name of Id.t (** non-anonymous identifier *)
87
88 val mk_name : Id.t -> t
89 (** constructor *)
90
91 val is_anonymous : t -> bool
92 (** Return [true] iff a given name is [Anonymous]. *)
93
94 val is_name : t -> bool
95 (** Return [true] iff a given name is [Name _]. *)
96
97 val compare : t -> t -> int
98 (** Comparison over names. *)
99
100 val equal : t -> t -> bool
101 (** Equality over names. *)
102
103 val hash : t -> int
104 (** Hash over names. *)
105
106 val hcons : t Hashcons.f
107 (** Hashconsing over names. *)
108
109 val print : t -> Pp.t
110 (** Pretty-printer (print "_" for [Anonymous]. *)
111
112 end
113
114 (** {6 Type aliases} *)
115
116 type name = Name.t = Anonymous | Name of Id.t
117 [@@ocaml.deprecated "(8.8) Use Name.t"]
118
119 type variable = Id.t
120
121 (** {6 Directory paths = section names paths } *)
122
123 module DirPath :
124 sig
125 type t
126 (** Type of directory paths. Essentially a list of module identifiers. The
127 order is reversed to improve sharing. E.g. A.B.C is ["C";"B";"A"] *)
128
129 val equal : t -> t -> bool
130 (** Equality over directory paths. *)
131
132 val compare : t -> t -> int
133 (** Comparison over directory paths. *)
134
135 val hash : t -> int
136 (** Hash over directory paths. *)
137
138 val make : Id.t list -> t
139 (** Create a directory path. (The list must be reversed). *)
140
141 val repr : t -> Id.t list
142 (** Represent a directory path. (The result list is reversed). *)
143
144 val empty : t
145 (** The empty directory path. *)
146
147 val is_empty : t -> bool
148 (** Test whether a directory path is empty. *)
149
150 val dummy : t
151 (** Used in [Safe_typing.empty_environment] and similar *)
152
153 val hcons : t Hashcons.f
154 (** Hashconsing of directory paths. *)
155
156 val to_string : t -> string
157 (** Print non-empty directory paths as ["root.module.submodule"] *)
158
159 val print : t -> Pp.t
160
161 module Set : Set.ExtS with type elt = t
162 module Map : Map.ExtS with type key = t and module Set := Set
163 end
164
165 module DPset = DirPath.Set [@@deprecated "Use DirPath.Set"]
166 module DPmap = DirPath.Map [@@deprecated "Use DirPath.Map"]
167
168 (** {6 Unique names for bound modules} *)
169
170 module MBId :
171 sig
172 type t
173 (** Unique names for bound modules. Each call to [make] constructs a fresh
174 unique identifier. *)
175
176 val equal : t -> t -> bool
177 (** Equality over unique bound names. *)
178
179 val compare : t -> t -> int
180 (** Comparison over unique bound names. *)
181
182 val hash : t -> int
183 (** Hash over unique bound names. *)
184
185 val make : DirPath.t -> Id.t -> t
186 (** The first argument is a file name, to prevent conflict between different
187 files. *)
188
189 val repr : t -> int * Id.t * DirPath.t
190 (** Reverse of [make]. *)
191
192 val to_id : t -> Id.t
193 (** Return the identifier contained in the argument. *)
194
195 val to_string : t -> string
196 (** Encode as a string (not to be used for user-facing messages). *)
197
198 val debug_to_string : t -> string
199 (** Same as [to_string], but outputs extra information related to debug. *)
200
201 module Set : Set.ExtS with type elt = t
202 module Map : Map.ExtS with type key = t and module Set := Set
203
204 end
205
206 module MBIset = MBId.Set [@@deprecated "Use MBId.Set"]
207 module MBImap = MBId.Map [@@deprecated "Use MBId.Map"]
208
209 (** {6 The module part of the kernel name } *)
210
211 module ModPath :
212 sig
213 type t =
214 | MPfile of DirPath.t
215 | MPbound of MBId.t
216 | MPdot of t * Id.t
217
218 val compare : t -> t -> int
219 val equal : t -> t -> bool
220 val hash : t -> int
221
222 val subpath : t -> t -> bool
223 (* [subpath p q] is true when q = p.l1. ... . ln, where n is potentially 0 *)
224
225 val is_bound : t -> bool
226
227 val dummy : t
228 (** ([= MPfile DirPath.dummy]) *)
229
230 val dp : t -> DirPath.t
231
232 val to_string : t -> string
233 (** Converts a identifier into an string. *)
234
235 val print : t -> Pp.t
236 (** Pretty-printer. *)
237
238 val debug_to_string : t -> string
239 (** Same as [to_string], but outputs extra information related to debug. *)
240
241 module Set : Set.ExtS with type elt = t
242 module Map : Map.ExtS with type key = t and module Set := Set
243
244 end
245
246 module MPset = ModPath.Set [@@deprecated "Use ModPath.Set"]
247 module MPmap = ModPath.Map [@@deprecated "Use ModPath.Map"]
248
249 (** {6 The absolute names of objects seen by kernel } *)
250
251 module KerName :
252 sig
253 type t
254
255 (** Constructor and destructor *)
256 val make : ModPath.t -> Id.t -> t
257 val repr : t -> ModPath.t * Id.t
258
259 (** Projections *)
260 val modpath : t -> ModPath.t
261 val label : t -> Id.t
262
263 val to_string : t -> string
264 (** Encode as a string (not to be used for user-facing messages). *)
265
266 val print : t -> Pp.t
267 (** Print internal representation (not to be used for user-facing messages). *)
268
269 val debug_to_string : t -> string
270 (** Same as [to_string], but outputs extra information related to debug. *)
271
272 val debug_print : t -> Pp.t
273 (** Same as [print], but outputs extra information related to debug. *)
274
275 (** Comparisons *)
276 val compare : t -> t -> int
277 val equal : t -> t -> bool
278 val hash : t -> int
279
280 module Set : CSig.USetS with type elt = t
281 module Map : Map.UExtS with type key = t and module Set := Set
282 module Pred : Predicate.S with type elt = t
283
284 end
285
286 module KNset = KerName.Set [@@deprecated "Use KerName.Set"]
287 module KNpred = KerName.Pred [@@deprecated "Use KerName.Pred"]
288 module KNmap = KerName.Map [@@deprecated "Use KerName.Map"]
289
290 (** {6 Signature for quotiented names} *)
291
292 module type EqType =
293 sig
294 type t
295 val compare : t -> t -> int
296 val equal : t -> t -> bool
297 val hash : t -> int
298 end
299
300 module type QNameS =
301 sig
302 type t
303 (** A type of reference that implements an implicit quotient by containing
304 two different names. The first one is the user name, i.e. what the user
305 sees when printing. The second one is the canonical name, which is the
306 actual absolute name of the reference.
307
308 This mechanism is fundamentally tied to the module system of Rocq. Functor
309 application and module inclusion are the typical ways to introduce names
310 where the canonical and user components differ. In particular, the two
311 components should be undistinguishable from the point of view of typing,
312 i.e. from a "kernel" ground. This aliasing only makes sense inside an
313 environment, but at this point this notion is not even defined so, this
314 dual name trick is fragile. One has to ensure many invariants when
315 creating such names, but the kernel is quite lenient when it comes to
316 checking that these invariants hold. (Read: there are soundness bugs
317 lurking in the module system.)
318
319 One could enforce the invariants by splitting the names and storing that
320 information in the environment instead, but unfortunately, this wreaks
321 havoc in the upper layers. The latter are infamously not stable by
322 syntactic equality, in particular they might observe the difference
323 between canonical and user names if not packed together.
324
325 For this reason, it is discouraged to use the canonical-accessing API
326 in the upper layers, notably the [CanOrd] module below. Instead, one
327 should use their quotiented versions defined in the [Environ] module.
328 Eventually all uses to [CanOrd] outside of the kernel should be removed.
329
330 CAVEAT: name sets and maps are still exposing a canonical-accessing API
331 surreptitiously. *)
332
333 module CanOrd : EqType with type t = t
334 (** Equality functions over the canonical name. Their use should be
335 restricted to the kernel. *)
336
337 module UserOrd : EqType with type t = t
338 (** Equality functions over the user name. *)
339
340 val canonize : t -> t
341 (** Returns the canonical version of the name *)
342 end
343
344 (** {6 Constant Names } *)
345
346 module Constant:
347 sig
348 type t
349
350 (** Constructors *)
351
352 val make : KerName.t -> KerName.t -> t
353 (** Builds a constant name from a user and a canonical kernel name. *)
354
355 val make1 : KerName.t -> t
356 (** Special case of [make] where the user name is canonical. *)
357
358 val make2 : ModPath.t -> Id.t -> t
359 (** Shortcut for [(make1 (KerName.make ...))] *)
360
361 (** Projections *)
362
363 val user : t -> KerName.t
364 val canonical : t -> KerName.t
365
366 val modpath : t -> ModPath.t
367 (** Shortcut for [KerName.modpath (user ...)] *)
368
369 val label : t -> Id.t
370 (** Shortcut for [KerName.label (user ...)] *)
371
372 (** Comparisons *)
373
374 include QNameS with type t := t
375
376 val change_label : t -> Id.t -> t
377 (** Builds a new constant name with a different label *)
378
379 (** Displaying *)
380
381 val to_string : t -> string
382 (** Encode as a string (not to be used for user-facing messages). *)
383
384 val print : t -> Pp.t
385 (** Print internal representation (not to be used for user-facing messages). *)
386
387 val debug_to_string : t -> string
388 (** Same as [to_string], but outputs extra information related to debug. *)
389
390 val debug_print : t -> Pp.t
391 (** Same as [print], but outputs extra information related to debug. *)
392
393 end
394
395 (** The [*_env] modules consider an order on user part of names
396 the others consider an order on canonical part of names*)
397 module Cpred : Predicate.S with type elt = Constant.t
398 module Cset : CSig.USetS with type elt = Constant.t
399 module Cset_env : CSig.USetS with type elt = Constant.t
400
401 module Cmap : Map.UExtS with type key = Constant.t and module Set := Cset
402 (** A map whose keys are constants (values of the {!Constant.t} type).
403 Keys are ordered wrt. "canonical form" of the constant. *)
404
405 module Cmap_env : Map.UExtS with type key = Constant.t and module Set := Cset_env
406 (** A map whose keys are constants (values of the {!Constant.t} type).
407 Keys are ordered wrt. "user form" of the constant. *)
408
409 (** {6 Inductive names} *)
410
411 module MutInd :
412 sig
413 type t
414
415 (** Constructors *)
416
417 val make : KerName.t -> KerName.t -> t
418 (** Builds a mutual inductive name from a user and a canonical kernel name. *)
419
420 val make1 : KerName.t -> t
421 (** Special case of [make] where the user name is canonical. *)
422
423 val make2 : ModPath.t -> Id.t -> t
424 (** Shortcut for [(make1 (KerName.make ...))] *)
425
426 (** Projections *)
427
428 val user : t -> KerName.t
429 val canonical : t -> KerName.t
430
431 val modpath : t -> ModPath.t
432 (** Shortcut for [KerName.modpath (user ...)] *)
433
434 val label : t -> Id.t
435 (** Shortcut for [KerName.label (user ...)] *)
436
437 (** Comparisons *)
438
439 include QNameS with type t := t
440
441 (** Displaying *)
442
443 val to_string : t -> string
444 (** Encode as a string (not to be used for user-facing messages). *)
445
446 val print : t -> Pp.t
447 (** Print internal representation (not to be used for user-facing messages). *)
448
449 val debug_to_string : t -> string
450 (** Same as [to_string], but outputs extra information related to debug. *)
451
452 val debug_print : t -> Pp.t
453 (** Same as [print], but outputs extra information related to debug. *)
454
455 end
456
457 module Mindset : CSig.USetS with type elt = MutInd.t
458 [@@ocaml.deprecated "(9.2) This will switch to user ordering at some point in \
459 the future. In the meantime either use the _env variant or the Q-variant from \
460 Environ, depending on the desired semantics."]
461 module Mindmap : Map.UExtS with type key = MutInd.t and module Set := Mindset [@ocaml.warning "-3"]
462 [@@ocaml.deprecated "(9.2) This will switch to user ordering at some point in \
463 the future. In the meantime either use the _env variant or the Q-variant from \
464 Environ, depending on the desired semantics."]
465
466 module Mindmap_env : CMap.UExtS with type key = MutInd.t
467
468 module Ind :
469 sig
470 (** Designation of a (particular) inductive type. *)
471 type t = MutInd.t (* the name of the inductive type *)
472 * int (* the position of this inductive type
473 within the block of mutually-recursive inductive types.
474 BEWARE: indexing starts from 0. *)
475 val modpath : t -> ModPath.t
476
477 include QNameS with type t := t
478
479 end
480
481 type inductive = Ind.t
482
483 module Construct :
484 sig
485 (** Designation of a (particular) constructor of a (particular) inductive type. *)
486 type t = Ind.t (* designates the inductive type *)
487 * int (* the index of the constructor
488 BEWARE: indexing starts from 1. *)
489
490 val modpath : t -> ModPath.t
491
492 include QNameS with type t := t
493
494 end
495
496 type constructor = Construct.t
497
498 module Indset : CSet.ExtS with type elt = inductive
499 [@@ocaml.deprecated "(9.2) This will switch to user ordering at some point in \
500 the future. In the meantime either use the _env variant or the Q-variant from \
501 Environ, depending on the desired semantics."]
502 module Constrset : CSet.ExtS with type elt = constructor
503 [@@ocaml.deprecated "(9.2) This will switch to user ordering at some point in \
504 the future. In the meantime either use the _env variant or the Q-variant from \
505 Environ, depending on the desired semantics."]
506
507 module Indset_env : CSet.ExtS with type elt = inductive
508 module Constrset_env : CSet.ExtS with type elt = constructor
509
510 module Indmap : CMap.ExtS with type key = inductive and module Set := Indset [@ocaml.warning "-3"]
511 [@@ocaml.deprecated "(9.2) This will switch to user ordering at some point in \
512 the future. In the meantime either use the _env variant or the Q-variant from \
513 Environ, depending on the desired semantics."]
514 module Constrmap : CMap.ExtS with type key = constructor and module Set := Constrset [@ocaml.warning "-3"]
515 [@@ocaml.deprecated "(9.2) This will switch to user ordering at some point in \
516 the future. In the meantime either use the _env variant or the Q-variant from \
517 Environ, depending on the desired semantics."]
518
519 module Indmap_env : CMap.ExtS with type key = inductive and module Set := Indset_env
520 module Constrmap_env : CMap.ExtS with type key = constructor and module Set := Constrset_env
521
522 val ith_mutual_inductive : inductive -> int -> inductive
523 val ith_constructor_of_inductive : inductive -> int -> constructor
524 val inductive_of_constructor : constructor -> inductive
525 val index_of_constructor : constructor -> int
526
527 (** {6 Hash-consing } *)
528
529 val hcons_con : Constant.t Hashcons.f
530 val hcons_mind : MutInd.t Hashcons.f
531 val hcons_ind : inductive Hashcons.f
532 val hcons_construct : constructor Hashcons.f
533
534 (******)
535
536 type 'a tableKey =
537 | ConstKey of 'a
538 | VarKey of Id.t
539 | RelKey of Int.t
540
541 type inv_rel_key = int (** index in the [rel_context] part of environment
542 starting by the end, {e inverse}
543 of de Bruijn indice *)
544
545 val eq_table_key : ('a -> 'a -> bool) -> 'a tableKey -> 'a tableKey -> bool
546 val hash_table_key : ('a -> int) -> 'a tableKey -> int
547 val eq_constant_key : Constant.t -> Constant.t -> bool
548
549 (** {5 Module paths} *)
550
551 type module_path = ModPath.t =
552 | MPfile of DirPath.t
553 | MPbound of MBId.t
554 | MPdot of ModPath.t * Id.t
555 [@@ocaml.deprecated "(8.8) Alias type"]
556
557 module Projection : sig
558 module Repr : sig
559 type t
560
561 val make : inductive -> proj_npars:int -> proj_arg:int -> Id.t -> t
562
563 include QNameS with type t := t
564
565 val constant : t -> Constant.t
566 (** Don't use this if you don't have to. *)
567
568 val inductive : t -> inductive
569 val mind : t -> MutInd.t
570 val npars : t -> int
571 val arg : t -> int
572 val label : t -> Id.t
573
574 val map : (MutInd.t -> MutInd.t) -> t -> t
575 val map_npars : (int -> int) -> t -> t
576
577 val to_string : t -> string
578 (** Encode as a string (not to be used for user-facing messages). *)
579
580 val print : t -> Pp.t
581 (** Print internal representation (not to be used for user-facing messages). *)
582
583 end
584 type t (* = Repr.t * bool *)
585
586 val make : Repr.t -> bool -> t
587 val repr : t -> Repr.t
588
589 include QNameS with type t := t
590
591 val constant : t -> Constant.t
592 val mind : t -> MutInd.t
593 val inductive : t -> inductive
594 val npars : t -> int
595 val arg : t -> int
596 val label : t -> Id.t
597 val unfolded : t -> bool
598 val unfold : t -> t
599
600 val hcons : t Hashcons.f
601 (** Hashconsing of projections. *)
602
603 val map : (MutInd.t -> MutInd.t) -> t -> t
604 val map_npars : (int -> int) -> t -> t
605
606 val to_string : t -> string
607 (** Encode as a string (not to be used for user-facing messages). *)
608
609 val print : t -> Pp.t
610 (** Print internal representation (not to be used for user-facing messages). *)
611
612 val debug_to_string : t -> string
613 (** Same as [to_string], but outputs extra information related to debug. *)
614
615 val debug_print : t -> Pp.t
616 (** Same as [print], but outputs extra information related to debug. *)
617
618 end
619
620 module PRset : CSig.USetS with type elt = Projection.Repr.t
621 module PRmap : Map.UExtS with type key = Projection.Repr.t and module Set := PRset
622
623 (** Predicate on projection representation (ignoring unfolding state) *)
624 module PRpred : Predicate.S with type elt = Projection.Repr.t
625
626 (** {6 Global reference is a kernel side type for all references together } *)
627
628 module GlobRef : sig
629
630 type t =
631 | VarRef of variable (** A reference to the section-context. *)
632 | ConstRef of Constant.t (** A reference to the environment. *)
633 | IndRef of inductive (** A reference to an inductive type. *)
634 | ConstructRef of constructor (** A reference to a constructor of an inductive type. *)
635
636 val is_bound : t -> bool
637
638 include QNameS with type t := t
639
640 module Set_env : CSig.USetS with type elt = t
641 module Map_env : Map.UExtS
642 with type key = t and module Set := Set_env
643
644 module Set : CSig.USetS with type elt = t
645 [@@ocaml.deprecated "(9.2) This will switch to user ordering at some point in \
646 the future. In the meantime either use the _env variant or the Q-variant from \
647 Environ, depending on the desired semantics."]
648
649 module Map : Map.UExtS
650 with type key = t and module Set := Set [@@ocaml.warning "-3"]
651
652 val print : t -> Pp.t
653 (** Print internal representation (not to be used for user-facing messages). *)
654
655 end
656
657 (** Located identifiers and objects with syntax. *)
658
659 type lident = Id.t CAst.t
660 type lname = Name.t CAst.t
661 type lstring = string CAst.t
662
663 val lident_eq : lident -> lident -> bool
664
665 (** Deprecated *)
666 module Label : sig
667 type t = Id.t
668 (** Type of labels *)
669
670 val equal : t -> t -> bool
671 (** Equality over labels *)
672
673 val compare : t -> t -> int
674 (** Comparison over labels. *)
675
676 val hash : t -> int
677 (** Hash over labels. *)
678
679 val make : string -> t
680 (** Create a label out of a string. *)
681
682 val of_id : Id.t -> t
683 (** Conversion from an identifier. *)
684
685 val to_id : t -> Id.t
686 (** Conversion to an identifier. *)
687
688 val to_string : t -> string
689 (** Conversion to string. *)
690
691 val print : t -> Pp.t
692 (** Pretty-printer. *)
693
694 module Set : Set.ExtS with type elt = t
695 module Map : Map.ExtS with type key = t and module Set := Set
696
697 val hcons : t Hashcons.f
698
699 end [@@deprecated "(9.2) Use Id"]