Debian Codegraph @

library/goptions.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 manages customization parameters at the vernacular level *)
12
13 (** Two kinds of things are managed : tables and options value
14 - Tables are created by applying the [MakeTable] functor.
15 - Variables storing options value are created by applying one of the
16 [declare_int_option], [declare_bool_option], ... functions.
17
18 Each table/option is uniquely identified by a key of type [option_name]
19 which consists in a list of strings. Note that for parsing constraints,
20 table names must not be made of more than 2 strings while option names
21 can be of arbitrary length.
22
23 The declaration of a table, say of name [["Toto";"Titi"]]
24 automatically makes available the following vernacular commands:
25
26 Add Toto Titi foo.
27 Remove Toto Titi foo.
28 Print Toto Titi.
29 Test Toto Titi.
30
31 The declaration of a non boolean option value, say of name
32 [["Tata";"Tutu";"Titi"]], automatically makes available the
33 following vernacular commands:
34
35 Set Tata Tutu Titi val.
36 Print Table Tata Tutu Titi.
37
38 If it is the declaration of a boolean value, the following
39 vernacular commands are made available:
40
41 Set Tata Tutu Titi.
42 Unset Tata Tutu Titi.
43 Print Table Tata Tutu Titi. (** synonym: Test Table Tata Tutu Titi. *)
44
45 All options are synchronized with the document.
46 *)
47
48 type option_name = string list
49
50 type _ option_kind =
51 | BoolKind : bool option_kind
52 | IntKind : int option option_kind
53 | StringKind : string option_kind
54 | StringOptKind : string option option_kind
55
56 type option_locality = OptDefault | OptLocal | OptExport | OptGlobal
57
58 (** {6 Tables. } *)
59
60 (** The functor [MakeStringTable] declares a table containing objects
61 of type [string]; the function [member_message] say what to print
62 when invoking the "Test Toto Titi foo." command; at the end [title]
63 is the table name printed when invoking the "Print Toto Titi."
64 command; [active] is roughly the internal version of the vernacular
65 "Test ...": it tells if a given object is in the table; [elements]
66 returns the list of elements of the table *)
67
68 module MakeStringTable :
69 functor
70 (_ : sig
71 val key : option_name
72 val title : string
73 val member_message : string -> bool -> Pp.t
74 end) ->
75 sig
76 val v : unit -> CString.Set.t
77 val active : string -> bool
78 end
79
80 (** The functor [MakeRefTable] declares a new table of objects of type
81 [A.t] practically denoted by [reference]; the encoding function
82 [encode : env -> reference -> A.t] is typically a globalization function,
83 possibly with some restriction checks; the function
84 [member_message] say what to print when invoking the "Test Toto
85 Titi foo." command; at the end [title] is the table name printed
86 when invoking the "Print Toto Titi." command; [active] is roughly
87 the internal version of the vernacular "Test ...": it tells if a
88 given object is in the table. *)
89
90 module type RefConvertArg = sig
91 type t
92 module Set : CSig.USetS with type elt = t
93 val encode : Environ.env -> Libnames.qualid -> t
94 val subst : Mod_subst.substitution -> t -> t
95
96 val check_local : Libobject.locality -> t -> unit
97 val discharge : t -> t
98 (** Elements which cannot be discharged should only be added with Local *)
99
100 val printer : t -> Pp.t
101 val key : option_name
102 val title : string
103 val member_message : t -> bool -> Pp.t
104 end
105
106 module MakeRefTable :
107 functor (A : RefConvertArg) ->
108 sig
109 val v : unit -> A.Set.t
110 val active : A.t -> bool
111 val set : Libobject.locality -> A.t -> bool -> unit
112 end
113
114
115 (** {6 Options. } *)
116
117 (** These types and function are for declaring a new option of name
118 [key] and access functions [read] and [write]; the parameter [name]
119 is the option name used when printing the option value (command
120 "Print Toto Titi."
121
122 The declare_*_option functions are low-level, to be used when
123 implementing complex option workflows, e.g. when the option data is in the global env.
124 For most use cases, you should use
125 the helper functions declare_*_option_and_ref. *)
126
127 type 'a option_sig = {
128 optstage : Summary.Stage.t;
129 optdepr : Deprecation.t option;
130 (** whether the option is DEPRECATED *)
131 optkey : option_name;
132 (** the low-level name of this option *)
133 optread : unit -> 'a;
134 optwrite : 'a -> unit
135 }
136
137 (** The [preprocess] function is triggered before setting the option. It can be
138 used to emit a warning on certain values, and clean-up the final value.
139
140 By default [no_summary:false], and declare_option declares a
141 summary entry to synchronize the backing state by calling read and write.
142 If you pass [no_summary:true] you must handle synchronization separately.
143
144 [StringOptKind] should be preferred to [StringKind] because it supports "Unset". *)
145 val declare_option : ?preprocess:('a -> 'a) -> ?no_summary:bool ->
146 kind:'a option_kind -> 'a option_sig -> unit
147
148 val declare_append_only_option : ?preprocess:(string -> string) -> sep:string ->
149 string option_sig -> unit
150
151 (** Helpers to declare a reference controlled by an option. *)
152
153 (** Wrapper type to separate the function calls to register the option
154 at toplevel from the calls to read the option value. *)
155 type 'a getter = { get : unit -> 'a }
156
157 type 'a opt_decl = ?stage:Summary.Stage.t -> ?depr:Deprecation.t -> key:option_name -> value:'a -> unit -> 'a getter
158
159 val declare_interpreted_option_and_ref :
160 ('a -> 'b) -> ('b -> 'a) ->
161 stage:Summary.Stage.t ->
162 ?depr:Deprecation.t ->
163 key:option_name ->
164 'a option_kind ->
165 value:'b ->
166 unit ->
167 'b getter
168
169 val declare_int_option_and_ref : int opt_decl
170 val declare_intopt_option_and_ref : int option opt_decl
171 val declare_nat_option_and_ref : int opt_decl
172 val declare_bool_option_and_ref : bool opt_decl
173 val declare_string_option_and_ref : string opt_decl
174 val declare_stringopt_option_and_ref : string option opt_decl
175 val declare_interpreted_string_option_and_ref : (string -> 'a) -> ('a -> string) -> 'a opt_decl
176
177 (** {6 Special functions supposed to be used only in vernacentries.ml } *)
178
179 module OptionMap : CSig.MapS with type key = option_name
180
181 type 'a table_of_A = {
182 add : Environ.env -> Libobject.locality -> 'a -> unit;
183 remove : Environ.env -> Libobject.locality -> 'a -> unit;
184 mem : Environ.env -> 'a -> unit;
185 print : unit -> unit;
186 }
187
188 val get_string_table :
189 option_name -> string table_of_A
190 val get_ref_table :
191 option_name -> Libnames.qualid table_of_A
192
193 (** The first argument is a locality flag.
194 If [stage] is provided, the option is set/unset only if it is declared in the corresponding stage.
195 If omitted, the option is always set/unset. *)
196 val set_int_option_value_gen : ?locality:option_locality -> ?stage:Summary.Stage.t -> option_name -> int option -> unit
197 val set_bool_option_value_gen : ?locality:option_locality -> ?stage:Summary.Stage.t -> option_name -> bool -> unit
198 val set_string_option_value_gen : ?locality:option_locality -> ?stage:Summary.Stage.t -> option_name -> string -> unit
199 val unset_option_value_gen : ?locality:option_locality -> ?stage:Summary.Stage.t -> option_name -> unit
200
201 val set_int_option_value : ?stage:Summary.Stage.t -> option_name -> int option -> unit
202 val set_bool_option_value : ?stage:Summary.Stage.t -> option_name -> bool -> unit
203 val set_string_option_value : ?stage:Summary.Stage.t -> option_name -> string -> unit
204
205 val print_option_value : option_name -> unit
206
207 type option_value =
208 | BoolValue of bool
209 | IntValue of int option
210 | StringValue of string
211 | StringOptValue of string option
212
213 type table_value =
214 | StringRefValue of string
215 | QualidRefValue of Libnames.qualid
216
217 (** [get_option_value key] returns [None] if option with name [key] was not found. *)
218 val get_option_value : option_name -> (unit -> option_value) option
219
220 type 'a check_and_cast = { check_and_cast : 'b. 'a -> 'b option_kind -> 'b }
221
222 val set_option_value : ?locality:option_locality -> ?stage:Summary.Stage.t ->
223 'a check_and_cast -> option_name -> 'a -> unit
224 (** [set_option_value ?locality f name v] sets [name] to the result of
225 applying [f] to [v] and [name]'s option kind. Use for behaviour
226 depending on the type of the option, eg erroring when ['a] doesn't
227 match it. *)
228
229 (** Summary of an option status *)
230 type option_state = {
231 opt_depr : Deprecation.t option;
232 opt_value : option_value;
233 }
234
235 val get_tables : unit -> option_state OptionMap.t
236 val print_tables : unit -> Pp.t
237
238 type iter_table_aux = { aux : 'a. 'a table_of_A -> Environ.env -> 'a -> unit }
239 val iter_table : Environ.env -> iter_table_aux -> option_name -> table_value list -> unit
240
241 val error_undeclared_key : option_name -> 'a
242
243 (** Compat *)
244
245 val declare_int_option : ?preprocess:(int option -> int option) ->
246 int option option_sig -> unit
247 val declare_bool_option : ?preprocess:(bool -> bool) ->
248 bool option_sig -> unit
249 val declare_string_option: ?preprocess:(string -> string) ->
250 string option_sig -> unit
251 val declare_stringopt_option: ?preprocess:(string option -> string option) ->
252 string option option_sig -> unit