Debian Codegraph @

vernac/comPrimitive.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 Names
12
13 let declare ?loc id entry =
14 let _ : Constant.t =
15 Declare.declare_constant ?loc ~name:id ~kind:Decls.IsPrimitive (Declare.PrimitiveEntry entry)
16 in
17 Flags.if_verbose Feedback.msg_info Pp.(Id.print id ++ str " is declared")
18
19 let do_primitive id udecl prim typopt =
20 if Lib.sections_are_opened () then
21 CErrors.user_err Pp.(str "Declaring a primitive is not allowed in sections.");
22 if Dumpglob.dump () then Dumpglob.dump_definition id false "ax";
23 let loc = id.CAst.loc in
24 let id = id.CAst.v in
25 match typopt with
26 | None ->
27 if Option.has_some udecl then
28 CErrors.user_err ?loc
29 Pp.(strbrk "Cannot use a universe declaration without a type when declaring primitives.");
30 let e = Declare.primitive_entry prim in
31 declare ?loc id e
32 | Some typ ->
33 let env = Global.env () in
34 let evd, udecl = Constrintern.interp_univ_decl_opt env udecl in
35 let auctx = CPrimitives.op_or_type_univs prim in
36 let evd, u = Evd.with_sort_context_set UState.univ_flexible ~src:UState.Internal evd (UnivGen.fresh_instance auctx) in
37 let expected_typ = EConstr.of_constr @@ Typeops.type_of_prim_or_type env u prim in
38 let evd, (typ,impls) =
39 Constrintern.(interp_type_evars_impls ~impls:empty_internalization_env)
40 env evd typ
41 in
42 let evd = try Evarconv.unify_delay env evd typ expected_typ
43 with Evarconv.UnableToUnify (evd,e) as exn ->
44 let _, info = Exninfo.capture exn in
45 Exninfo.iraise (Pretype_errors.(
46 PretypeError (env,evd,CannotUnify (typ,expected_typ,Some e)),info))
47 in
48 Pretyping.check_evars_are_solved ~program_mode:false env evd;
49 let evd = Evd.minimize_universes evd in
50 let _qvars, uvars = EConstr.universes_of_constr evd typ in
51 let evd = Evd.restrict_universe_context evd uvars in
52 let typ = EConstr.to_constr evd typ in
53 let univ_poly = not (UVars.AbstractContext.is_empty auctx) in
54 let poly = PolyFlags.of_univ_poly univ_poly in
55 let univ_entry = Evd.check_univ_decl ~poly evd udecl in
56 let entry = Declare.primitive_entry ~types:(typ, univ_entry) prim in
57 declare ?loc id entry