Debian Codegraph @

kernel/vmerrors.ml

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 Pp
12
13 type error =
14 | TooLargeInductive of Names.Id.t
15 | TooLargeCode
16
17
18 exception CompileError of error
19
20 let too_large_code () = raise (CompileError TooLargeCode)
21
22 (* Limit needed to make SWITCH work. The specific limit is
23 arbitrary but nobody needs more than 0x1000000 constructors. *)
24
25 let max_nb_const = 0x1000000
26 let max_nb_block = 0x1000000 + Obj.last_non_constant_constructor_tag - 1
27
28 let str_max_constructors =
29 Format.sprintf
30 " which has more than %i constant constructors or more than %i non-constant constructors" max_nb_const max_nb_block
31
32 (* NB: Declarations depends on Vmemitcodes which depends on
33 too_large_code so we can't use Declarations.one_inductive_body
34 here. Instead we pass the needed fields. *)
35 let check_compilable_ind ~name ~mind_nb_args ~mind_nb_constant =
36 if not (mind_nb_args <= max_nb_block && mind_nb_constant <= max_nb_const) then
37 raise (CompileError (TooLargeInductive name))
38
39 let pr_error = function
40 | TooLargeCode -> str "Cannot compile code for virtual machine as it exceeds string size limits."
41 | TooLargeInductive name ->
42 str "Cannot compile code for virtual machine as it uses inductive " ++
43 Names.Id.print name ++ str str_max_constructors
44
45 let () = CErrors.register_handler (function
46 | CompileError e -> Some (pr_error e)
47 | _ -> None)