Debian Codegraph @

vernac/tactic_option.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 Libobject
12
13 type tac_option_locality =
14 | Default
15 | Global
16 | Local
17 | Export
18 | GlobalAndExport
19
20 let tac_option_locality =
21 let open Attributes in
22 let open Attributes.Notations in
23 let one x = attribute_of_list [x,single_key_parser ~name:"Locality" ~key:x ()] in
24 one "local" ++ one "global" ++ one "export" >>= fun ((local,global),export) ->
25 match local, global, export with
26 | None, None, None -> return Default
27
28 | Some (), Some (), _ -> CErrors.user_err Pp.(str "Cannot combine local and global.")
29 | Some (), _, Some () -> CErrors.user_err Pp.(str "Cannot combine local and export.")
30
31 | Some (), None, None -> return Local
32 | None, Some (), None -> return Global
33 | None, None, Some () -> return Export
34 | None, Some (), Some () -> return GlobalAndExport
35
36 let warn_default_locality =
37 CWarnings.create ~name:"deprecated-tacopt-without-locality" ~category:Deprecation.Version.v8_17 Pp.(fun () ->
38 strbrk
39 "The default and global localities for this command outside \
40 sections are currently equivalent to the combination of the \
41 standard meaning of \"global\" (as described in the reference \
42 manual), \"export\" and re-exporting for every surrounding \
43 module. It will change to just \"global\" (with the meaning \
44 used by the \"Set\" command) in a future release." ++ fnl() ++
45 strbrk
46 "To preserve the current meaning in a forward compatible way, \
47 use the attribute \"#[global,export]\" and repeat the command \
48 with just \"#[export]\" in any surrounding modules. If you \
49 are fine with the change of semantics, disable this warning.")
50
51 let declare_tactic_option ?default name =
52 let current_tactic : Gentactic.glob_generic_tactic option ref =
53 Summary.ref default ~name:(name^"-default-tactic")
54 in
55 let set_current_tactic t =
56 current_tactic := t
57 in
58 let cache (_, tac) = set_current_tactic tac in
59 let load _ (local, tac) = match local with
60 | Default | Global | GlobalAndExport -> set_current_tactic tac
61 | Export -> ()
62 | Local -> assert false (* not allowed by classify *)
63 in
64 let import i (local, tac) = match local with
65 | GlobalAndExport | Export -> if Int.equal i 1 then set_current_tactic tac
66 | Default | Global -> set_current_tactic tac
67 | Local -> assert false (* not allowed by classify *)
68 in
69 let classify (local, _) = match local with
70 | Local -> Dispose
71 | Default | Global | Export | GlobalAndExport -> Substitute
72 in
73 let subst (s, (local, tac)) =
74 (local, Option.map (Gentactic.subst s) tac)
75 in
76 let input : tac_option_locality * Gentactic.glob_generic_tactic option -> obj =
77 declare_object
78 { (default_object name) with
79 cache_function = cache;
80 load_function = load;
81 (* can't simple_open: crappy behaviour when superglobal *)
82 open_function = filtered_open import;
83 classify_function = classify;
84 subst_function = subst}
85 in
86 let put ?loc local tac =
87 let () = match local with
88 | Default -> if not (Lib.sections_are_opened()) then warn_default_locality ?loc ()
89 | Local -> ()
90 | Export | Global | GlobalAndExport ->
91 if Lib.sections_are_opened()
92 then CErrors.user_err ?loc
93 Pp.(str "This locality is not supported inside sections by this command.")
94 in
95 Lib.add_leaf (input (local, Some tac))
96 in
97 let get () = match !current_tactic with
98 | None -> Proofview.tclUNIT ()
99 | Some tac -> Gentactic.interp tac
100 in
101 let print () = match !current_tactic with
102 | None -> Pp.str "<unset>"
103 | Some tac ->
104 let env = Global.env () in
105 let sigma = Evd.from_env env in
106 Gentactic.print_glob env sigma tac
107 in
108 put, get, print