Debian Codegraph @

kernel/safe_typing.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 open Names
12
13 type vodigest =
14 | Dvo_or_vi of Digest.t (* The digest of the seg_lib part *)
15
16 val digest_match : actual:vodigest -> required:vodigest -> bool
17
18 (** {6 Safe environments } *)
19
20 (** Since we are now able to type terms, we can define an abstract type
21 of safe environments, where objects are typed before being added.
22
23 We also provide functionality for modules : [start_module], [end_module],
24 etc.
25 *)
26
27 type safe_environment
28
29 type section_data
30
31 val empty_environment : safe_environment
32
33 val env_of_safe_env : safe_environment -> Environ.env
34
35 val sections_of_safe_env : safe_environment -> section_data Section.t option
36
37 val structure_body_of_safe_env : safe_environment -> Mod_declarations.structure_body
38
39 val flatten_env : safe_environment -> ModPath.t * Mod_declarations.structure_body
40
41 (** The safe_environment state monad *)
42
43 type safe_transformer0 = safe_environment -> safe_environment
44 type 'a safe_transformer = safe_environment -> 'a * safe_environment
45
46
47 (** {6 Stm machinery } *)
48
49 type private_constants
50
51 val debug_print_private_constants : private_constants -> Pp.t
52
53 val empty_private_constants : private_constants
54 val is_empty_private_constants : private_constants -> bool
55 val length_private : private_constants -> int
56 val pop_private : private_constants -> int -> private_constants * private_constants
57
58 val concat_private : private_constants -> private_constants -> private_constants
59 (** [concat_private e1 e2] adds the constants of [e1] to [e2], i.e. constants in
60 [e1] must be more recent than those of [e2]. *)
61
62 val inline_private_constants :
63 Environ.env -> private_constants Entries.proof_output -> Constr.constr * Univ.ContextSet.t
64 (** Abstract the private constants of a proof over the proof output *)
65
66 val push_private_constants : Environ.env -> private_constants -> Environ.env
67 (** Push the constants in the environment if not already there. *)
68
69 val universes_of_private : private_constants -> Univ.ContextSet.t
70
71 val constants_of_private : private_constants -> Constant.t list
72
73 val is_curmod_library : safe_environment -> bool
74
75 val is_joined_environment : safe_environment -> bool
76 (** {6 Enriching a safe environment } *)
77
78 (** Insertion of global axioms or definitions *)
79
80 type side_effect_declaration =
81 | DefinitionEff : Entries.definition_entry -> side_effect_declaration
82 | OpaqueEff : Constr.constr Entries.opaque_entry -> side_effect_declaration
83
84 type exported_opaque
85 type exported_private_constant = Constant.t * exported_opaque option
86
87 val repr_exported_opaque : exported_opaque -> Opaqueproof.opaque_handle * Opaqueproof.opaque_proofterm
88
89 val export_private_constants :
90 private_constants ->
91 exported_private_constant list safe_transformer
92
93 (** returns the main constant *)
94 val add_constant :
95 ?typing_flags:Declarations.typing_flags ->
96 Id.t -> Entries.constant_entry -> Constant.t safe_transformer
97
98 (** Similar to add_constant but also returns a certificate *)
99 val add_private_constant :
100 Id.t -> Univ.ContextSet.t -> side_effect_declaration -> (Constant.t * private_constants) safe_transformer
101
102 (** {5 Delayed proofs} *)
103
104 (** Witness that a delayed Qed hole has a proof. This datatype is marshallable
105 but care must be taken to marshal it at the same time as the environment
106 it is referring to, since {!fill_opaque} relies on a shared pointer between
107 the environment and the certificate. *)
108 type opaque_certificate
109
110 (** Check that the provided proof is correct for the corresponding handle. This
111 does not modify the environment. Call {!fill_opaque} below for that. *)
112 val check_opaque : safe_environment -> Opaqueproof.opaque_handle ->
113 private_constants Entries.proof_output -> opaque_certificate
114
115 (** Given an already checked proof for an opaque hole, actually fill it with the
116 proof. This might fail if the current set of global universes is
117 inconsistent with the one at the time of the call to {!check_opaque}.
118 Precondition: the underlying handle must exist and must not have been
119 filled. *)
120 val fill_opaque : opaque_certificate -> safe_transformer0
121
122 (** Check whether a handle was filled. It assumes that the handle was introduced
123 in the opaque table and throws an anomaly otherwise. *)
124 val is_filled_opaque : Opaqueproof.opaque_handle -> safe_environment -> bool
125
126 (** Get the proof term that was checked by the kernel. *)
127 val repr_certificate : opaque_certificate ->
128 Constr.t * Univ.ContextSet.t Opaqueproof.delayed_universes
129
130 (** {5 Rewrite rules} *)
131
132 (** Add a rewrite rule corresponding to the equality witnessed by the constant. *)
133 val add_rewrite_rules : Id.t -> Declarations.rewrite_rules_body -> safe_environment -> safe_environment
134
135 (** {5 Inductive blocks} *)
136
137 (** Adding an inductive type *)
138
139 val add_mind :
140 ?typing_flags:Declarations.typing_flags ->
141 Id.t -> Entries.mutual_inductive_entry ->
142 (MutInd.t * IndTyping.NotPrimRecordReason.t option) safe_transformer
143
144 (** Adding a module or a module type *)
145
146 val add_module :
147 Id.t -> Entries.module_entry -> Declarations.inline ->
148 (ModPath.t * Mod_subst.delta_resolver) safe_transformer
149 val add_modtype :
150 Id.t -> Entries.module_type_entry -> Declarations.inline ->
151 ModPath.t safe_transformer
152
153 (** Adding universe constraints *)
154
155 val push_context_set :
156 strict:bool -> Univ.ContextSet.t -> safe_transformer0
157
158 (** Adding global sort qualities *)
159
160 val push_qualities : rigid:bool -> Sorts.QContextSet.t -> safe_transformer0
161
162 (* (\** Generator of universes *\) *)
163 (* val next_universe : int safe_transformer *)
164
165 (** Setting the type theory flavor *)
166 val set_rewrite_rules_allowed : bool -> safe_transformer0
167 val set_impredicative_set : bool -> safe_transformer0
168 val set_indices_matter : bool -> safe_transformer0
169 val set_typing_flags : Declarations.typing_flags -> safe_transformer0
170 val set_share_reduction : bool -> safe_transformer0
171 val set_check_guarded : bool -> safe_transformer0
172 val set_check_positive : bool -> safe_transformer0
173 val set_check_universes : bool -> safe_transformer0
174 val set_VM : bool -> safe_transformer0
175 val set_native_compiler : bool -> safe_transformer0
176 val set_allow_sprop : bool -> safe_transformer0
177
178 (** {6 Interactive section functions } *)
179
180 val open_section : safe_transformer0
181
182 val close_section : safe_transformer0
183
184 val sections_are_opened : safe_environment -> bool
185
186 (** Insertion of local declarations (Local or Variables) *)
187
188 val push_named_assum : (Id.t * Constr.types) -> safe_transformer0
189
190 val push_named_def :
191 Id.t * Entries.section_def_entry -> safe_transformer0
192
193 (** Add local universes to a polymorphic section *)
194 val push_section_context : UVars.UContext.t -> safe_transformer0
195
196 (** {6 Interactive module functions } *)
197
198 val start_module : Id.t -> ModPath.t safe_transformer
199
200 val start_modtype : Id.t -> ModPath.t safe_transformer
201
202 val add_module_parameter :
203 MBId.t -> Entries.module_struct_entry -> Declarations.inline ->
204 Mod_declarations.module_type_body safe_transformer
205
206 (** returns the number of module (type) parameters following the nested module
207 structure. The inner module (type) comes first in the list. *)
208 val module_num_parameters : safe_environment -> int list
209
210 (** returns true if the module is a module type following the nested module
211 structure. The inner module (type) comes first in the list. true means
212 a module type, false a regular module *)
213 val module_is_modtype : safe_environment -> bool list
214
215 (** Traditional mode: check at end of module that no future was
216 created. *)
217 val allow_delayed_constants : bool ref
218
219 (** The optional result type is given without its functorial part *)
220
221 val end_module :
222 Id.t -> (Entries.module_struct_entry * Declarations.inline) option ->
223 (ModPath.t * MBId.t list * Mod_subst.delta_resolver) safe_transformer
224
225 val end_modtype : Id.t -> (ModPath.t * MBId.t list) safe_transformer
226
227 val add_include :
228 Entries.module_struct_entry -> bool -> Declarations.inline ->
229 Mod_subst.delta_resolver safe_transformer
230
231 val current_modpath : safe_environment -> ModPath.t
232
233 val current_dirpath : safe_environment -> DirPath.t
234
235 (** {6 Libraries : loading and saving compilation units } *)
236
237 type compiled_library
238
239 val dirpath_of_library : compiled_library -> DirPath.t
240 val module_of_library : compiled_library -> Mod_declarations.module_body
241 val univs_of_library : compiled_library -> Sorts.QContextSet.t * Univ.ContextSet.t
242 val check_flags_for_library : compiled_library -> safe_transformer0
243
244 val start_library : DirPath.t -> ModPath.t safe_transformer
245
246 val export :
247 output_native_objects:bool ->
248 safe_environment -> DirPath.t ->
249 ModPath.t * compiled_library * Vmlibrary.compiled_library * Nativelib.native_library
250
251 val import : compiled_library -> Vmlibrary.on_disk -> vodigest ->
252 ModPath.t safe_transformer
253
254 (** {6 Safe typing judgments } *)
255
256 type judgment = private {
257 jdg_env : safe_environment;
258 jdg_val : Constr.constr;
259 jdg_type : Constr.types;
260 }
261
262 (** The safe typing of a term returns a typing judgment. *)
263 val typing : safe_environment -> Constr.constr -> judgment
264
265 (** {6 Queries } *)
266
267 val exists_objlabel : Id.t -> safe_environment -> bool
268
269 val delta_of_senv : safe_environment -> Mod_subst.delta_resolver
270
271 val constant_of_delta_kn_senv : safe_environment -> KerName.t -> Constant.t
272 val mind_of_delta_kn_senv : safe_environment -> KerName.t -> MutInd.t
273
274 (** {6 Retroknowledge / Native compiler } *)
275
276 val register_inline : Constant.t -> safe_transformer0
277 val register_inductive : inductive -> 'a CPrimitives.prim_ind -> safe_transformer0
278
279 val set_oracle : Conv_oracle.oracle -> safe_transformer0
280 val set_strategy : Conv_oracle.evaluable -> Conv_oracle.level -> safe_transformer0