Debian Codegraph @

plugins/ltac2/tac2bt.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 Tac2expr
12 open Proofview.Notations
13
14 let backtrace_evd : backtrace Evd.Store.field = Evd.Store.field "ltac2_trace"
15
16 let backtrace : backtrace Exninfo.t = Exninfo.make "ltac2_trace"
17
18 let print_ltac2_backtrace = ref false
19
20 let () = Goptions.declare_bool_option {
21 optstage = Summary.Stage.Interp;
22 optdepr = None;
23 optkey = ["Ltac2"; "Backtrace"];
24 optread = (fun () -> !print_ltac2_backtrace);
25 optwrite = (fun b -> print_ltac2_backtrace := b);
26 }
27
28 let ltac2_in_ltac1_profiling = ref false
29
30 let () = Goptions.declare_bool_option {
31 optstage = Summary.Stage.Interp;
32 optdepr = None;
33 optkey = ["Ltac2"; "In"; "Ltac1"; "Profiling"];
34 optread = (fun () -> !ltac2_in_ltac1_profiling);
35 optwrite = (fun b -> ltac2_in_ltac1_profiling := b);
36 }
37
38 let get_backtrace =
39 Proofview.tclEVARMAP >>= fun sigma ->
40 match Evd.Store.get (Evd.get_extra_data sigma) backtrace_evd with
41 | None -> Proofview.tclUNIT []
42 | Some bt -> Proofview.tclUNIT bt
43
44 let set_backtrace bt =
45 Proofview.tclEVARMAP >>= fun sigma ->
46 let store = Evd.get_extra_data sigma in
47 let store = Evd.Store.set store backtrace_evd bt in
48 let sigma = Evd.set_extra_data store sigma in
49 Proofview.Unsafe.tclEVARS sigma
50
51 let pr_frame, pr_frame_hook = Hook.make ()
52
53 let with_frame frame tac =
54 let tac =
55 if !print_ltac2_backtrace then
56 get_backtrace >>= fun bt ->
57 set_backtrace (frame :: bt) >>= fun () ->
58 Proofview.tclOR tac (fun (e,info) ->
59 (* If it's already present assume it's more precise *)
60 let info = if Option.has_some (Exninfo.get info backtrace) then info
61 else Exninfo.add info backtrace (frame::bt)
62 in
63 Proofview.tclZERO ~info e)
64 >>= fun ans ->
65 set_backtrace bt >>= fun () ->
66 Proofview.tclUNIT ans
67 else tac
68 in
69 if !ltac2_in_ltac1_profiling then
70 let pr_frame f = Some (Hook.get pr_frame f) in
71 Profile_tactic.do_profile_gen pr_frame frame ~count_call:true tac
72 else tac