Debian Codegraph @

library/summary.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 module registers the declaration of global tables, which will be kept
12 in synchronization during the various backtracks of the system. *)
13 module Stage : sig
14
15 (** We distinguish two stages and separate the system state accordingly.
16 [Synterp] is the syntactic interpretation phase, i.e. vernacular parsing and
17 execution of commands having an effect on parsing. [Interp] is the
18 interpretation phase, where standard commands are executed. *)
19 type t = Synterp | Interp
20
21 val equal : t -> t -> bool
22
23 end
24
25 (** Types of global Rocq states. The ['a] type should be pure and marshallable by
26 the standard OCaml marshalling function. *)
27 type 'a summary_declaration = {
28 stage : Stage.t;
29 freeze_function : unit -> 'a;
30 unfreeze_function : 'a -> unit;
31 init_function : unit -> unit }
32
33 (** For tables registered during the launch of rocq repl, the [init_function]
34 will be run only once, during an [init_summaries] done at the end of
35 coqtop initialization. For tables registered later (for instance
36 during a plugin dynlink), [init_function] is used when unfreezing
37 an earlier frozen state that doesn't contain any value for this table.
38
39 Beware: for tables registered dynamically after the initialization
40 of Coq, their init functions may not be run immediately. It is hence
41 the responsibility of plugins to initialize themselves properly.
42 *)
43
44 val declare_summary : string -> ?make_marshallable:('a -> 'a) -> 'a summary_declaration -> unit
45
46 (** We provide safe projection from the summary to the types stored in
47 it.*)
48 module Dyn : Dyn.S
49
50 val declare_summary_tag : string -> ?make_marshallable:('a -> 'a) -> 'a summary_declaration -> 'a Dyn.tag
51
52 (** All-in-one reference declaration + summary registration.
53 It behaves just as OCaml's standard [ref] function, except
54 that a [declare_summary] is done, with [name] as string.
55 The [init_function] restores the reference to its initial value.
56 The [stage] argument defaults to [Interp] and should be changed to [Synterp]
57 for references which are read from and written to during the syntactic
58 interpretation.
59
60 When [local:true] the value is local to the process, i.e. not sent to proof workers.
61 Consequently it doesn't need to be of a marshallable type.
62 It is useful to implement a local cache for example.
63
64 [ref_tag] is never local.
65 *)
66
67 val ref : ?stage:Stage.t -> ?local:bool -> name:string -> 'a -> 'a ref
68 val ref_tag : ?stage:Stage.t -> name:string -> 'a -> 'a ref * 'a Dyn.tag
69
70 (** Special summary for ML modules. This summary entry is special
71 because its unfreeze may load ML code and hence add summary
72 entries. Thus is has to be recognizable, and handled properly.
73
74 The args correspond to Mltop.PluginSpec.t , that is to say, the
75 findlib name for the plugin. *)
76 val declare_ml_modules_summary : string list summary_declaration -> unit
77
78 (** For global tables registered statically before the end of coqtop
79 launch, the following empty [init_function] could be used. *)
80
81 val nop : unit -> unit
82
83 module type FrozenStage = sig
84
85 (** The type [frozen] is a snapshot of the states of all the registered
86 tables of the system. *)
87
88 type frozen
89
90 val empty_frozen : frozen
91 val freeze_summaries : unit -> frozen
92 val make_marshallable : frozen -> frozen
93 val unfreeze_summaries : ?partial:bool -> frozen -> unit
94 val init_summaries : unit -> unit
95 val project_from_summary : frozen -> 'a Dyn.tag -> 'a
96
97 end
98
99 module Synterp : FrozenStage
100 module Interp : sig
101
102 include FrozenStage
103
104 (** Typed projection of the summary. Experimental API, use with CARE *)
105
106 val modify_summary : frozen -> 'a Dyn.tag -> 'a -> frozen
107 val remove_from_summary : frozen -> 'a Dyn.tag -> frozen
108
109 end
110
111 (** {6 Observables}
112
113 [OBSERVABLE] captures the pattern of backtrackable state that can be enabled
114 and disabled. To use it, [register] the value that you want to record and then
115 [activate] and [deactivate] the value using the returned [token].
116
117 Indirection is used to be able to handle non-marshallable values.
118 *)
119 module type OBSERVABLE =
120 sig
121 (** The type of tokens to manipulate values. This is always marshallable. *)
122 type token
123
124 (** The value being stored. May be non-marshallable (typically a closure). *)
125 type value
126
127 (** Register a new value and get the token used to enable and disable it. *)
128 val register : name:string -> ?override:bool -> value -> token
129
130 (** Activate/deactive the value attached to the token. *)
131 val activate : token -> unit
132 val deactivate : token -> unit
133
134 (** Determine if the value for the given token is active. *)
135 val is_active : token -> bool
136 end
137
138 (** The implementation side of observation.
139 This should be held internally with the creator of the state.
140 Only the [OBSERVABLE] signature should be exposed.
141 *)
142 module type OBSERVABLE_USER =
143 sig
144 include OBSERVABLE
145
146 (** Get all of the active values *)
147 val all_active : unit -> (string * value) list
148 end
149
150 (** Generic implementation of [OBSERVABLE_USER]. *)
151 module MakeObservable
152 (Obs : sig
153 (** An arbitrary type, does not need to be marshallable. *)
154 type value
155
156 val stage : Stage.t
157
158 (** Whether the list of active observers is process-local.
159 Unlike [ref ~local] this doesn't matter for marshalling since
160 observers apply indirection to be always marshallable. *)
161 val local : bool
162
163 (** The name of the summary. *)
164 val name : string
165 end) : OBSERVABLE_USER with type value = Obs.value
166
167 (** {6 Debug} *)
168 val dump : unit -> (int * string) list