Debian Codegraph @

lib/deprecation.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 type t = { since : string option ; note : string option }
12 type 'a with_qf = { depr : t; use_instead : 'a option }
13
14 let drop_qf { depr } = depr
15 let with_empty_qf depr = { depr; use_instead = None }
16 let map_qf f { depr; use_instead } = { depr; use_instead = Option.map f use_instead }
17
18 let make ?since ?note () = { since ; note }
19 let make_with_qf depr ?use_instead () = { depr; use_instead }
20
21 type since_name = NoSince | Since of string
22
23 let since_name = function
24 | None -> NoSince
25 | Some s -> Since (String.map (function ' ' -> '-' | c -> c) s)
26
27 let depr_cat = CWarnings.CoreCategories.deprecated
28
29 let since_cats = ref CString.Map.empty
30
31 let get_generic_cat since =
32 match CString.Map.find_opt since !since_cats with
33 | Some c -> c
34 | None ->
35 let c = CWarnings.create_category ~from:[depr_cat] ~name:("deprecated-since-"^since) () in
36 since_cats := CString.Map.add since c !since_cats;
37 c
38
39 let printer ~object_name ~pp_qf pp (x,{depr={since;note};use_instead}) =
40 let open Pp in
41 let note =
42 match note, use_instead with
43 | None, None -> None
44 | Some x, _ -> Some (str x)
45 | None, Some x -> Some (str"Use " ++ pp_qf x ++ str" instead.") in
46 str object_name ++ spc () ++ pp x ++
47 strbrk " is deprecated" ++
48 pr_opt (fun since -> str "since " ++ str since) since ++
49 str "." ++ pr_opt (fun x -> x) note
50
51 let quickfix ~pp_qf ~loc (x,{use_instead}) =
52 match use_instead with
53 | None -> []
54 | Some replacement ->
55 [Quickfix.make ~loc (pp_qf replacement)]
56
57 let create_warning_with_qf ?default ~object_name ~warning_name_if_no_since ~pp_qf pp =
58 let pp = printer ~object_name ~pp_qf pp in
59 let quickfix = quickfix ~pp_qf in
60 let main_cat, main_w = CWarnings.create_hybrid ?default ~name:warning_name_if_no_since ~from:[depr_cat] () in
61 let main_w = CWarnings.create_in main_w ~quickfix pp in
62 let warnings = ref CString.Map.empty in
63 fun ?loc (v, ({depr = {since}; use_instead } as info)) ->
64 let since = since_name since in
65 let w = match since with
66 | NoSince -> main_w
67 | Since since ->
68 match CString.Map.find_opt since !warnings with
69 | Some w -> w
70 | None ->
71 let generic_cat = get_generic_cat since in
72 let w = CWarnings.create_warning ?default ~from:[main_cat; generic_cat]
73 ~name:(warning_name_if_no_since ^ "-since-" ^ since) ()
74 in
75 let w = CWarnings.create_in w pp in
76 warnings := CString.Map.add since w !warnings;
77 w
78 in
79 w ?loc (v,info)
80
81 let create_warning ?default ~object_name ~warning_name_if_no_since pp =
82 let f = create_warning_with_qf ?default ~object_name ~warning_name_if_no_since ~pp_qf:(fun _ -> assert false) pp in
83 fun ?loc (v, depr) -> f ?loc (v, {depr; use_instead = None})
84
85 module Version = struct
86
87 let v8_3 = get_generic_cat "8.3"
88 let v8_5 = get_generic_cat "8.5"
89 let v8_8 = get_generic_cat "8.8"
90 let v8_10 = get_generic_cat "8.10"
91 let v8_11 = get_generic_cat "8.11"
92 let v8_14 = get_generic_cat "8.14"
93 let v8_15 = get_generic_cat "8.15"
94 let v8_16 = get_generic_cat "8.16"
95 let v8_17 = get_generic_cat "8.17"
96 let v8_18 = get_generic_cat "8.18"
97 let v8_19 = get_generic_cat "8.19"
98 let v8_20 = get_generic_cat "8.20"
99 let v9_0 = get_generic_cat "9.0"
100 let v9_1 = get_generic_cat "9.1"
101 let v9_2 = get_generic_cat "9.2"
102 (* When adding a new version here, please also add
103 #[export] Set Warnings "-deprecated-since-X.Y".
104 in theories/Compat/RocqX{Y-1}.v *)
105
106 end