Debian Codegraph @

engine/proofview_monad.mli

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 (** This file defines the datatypes used as internal states by the
12 tactic monad, and specialises the [Logic_monad] to these types. It should
13 not be used directly. Consider using {!Proofview} instead. *)
14
15 (** {6 Traces} *)
16
17 module Trace : sig
18
19 (** The intent is that an ['a forest] is a list of messages of type
20 ['a]. But messages can stand for a list of more precise
21 messages, hence the structure is organised as a tree. *)
22 type 'a forest = 'a tree list
23 and 'a tree = Seq of 'a * 'a forest
24
25 (** To build a trace incrementally, we use an intermediary data
26 structure on which we can define an S-expression like language
27 (like a simplified xml except the closing tags do not carry a
28 name). *)
29 type 'a incr
30 val to_tree : 'a incr -> 'a forest
31
32 (** [open a] opens a tag with name [a]. *)
33 val opn : 'a -> 'a incr -> 'a incr
34
35 (** [close] closes the last open tag. It is the responsibility of
36 the user to close all the tags. *)
37 val close : 'a incr -> 'a incr
38
39 (** [leaf] creates an empty tag with name [a]. *)
40 val leaf : 'a -> 'a incr -> 'a incr
41
42 end
43
44 (** {6 State types} *)
45
46 (** We typically label nodes of [Trace.tree] with messages to
47 print. But we don't want to compute the result. *)
48 type lazy_msg = unit -> Pp.t
49
50 (** Info trace. *)
51 module Info : sig
52
53 (** The type of the tags for [info]. *)
54 type tag =
55 | Msg of lazy_msg (** A simple message *)
56 | Tactic of lazy_msg (** A tactic call *)
57 | Dispatch (** A call to [tclDISPATCH]/[tclEXTEND] *)
58 | DBranch (** A special marker to delimit individual branch of a dispatch. *)
59
60 type state = tag Trace.incr
61 type tree = tag Trace.forest
62
63 val print : Environ.env -> Evd.evar_map -> tree -> Pp.t
64
65 (** [collapse n t] flattens the first [n] levels of [Tactic] in an
66 info trace, effectively forgetting about the [n] top level of
67 names (if there are fewer, the last name is kept). *)
68 val collapse : int -> tree -> tree
69
70 end
71
72 module StateStore : Store.S
73 type goal = Evar.t
74 type goal_with_state
75 val drop_state : goal_with_state -> goal
76 val get_state : goal_with_state -> StateStore.t
77 val goal_with_state : goal -> StateStore.t -> goal_with_state
78 val with_empty_state : goal -> goal_with_state
79 val map_goal_with_state : (goal -> goal) -> goal_with_state -> goal_with_state
80
81 (** Type of proof views: current [evar_map] together with the list of
82 focused goals, locally shelved goals and globally shelved goals. *)
83 type proofview = {
84 solution : Evd.evar_map;
85 comb : goal_with_state list;
86 }
87
88 (** {6 Instantiation of the logic monad} *)
89
90 module P : sig
91 type s = proofview * Environ.env
92
93 (** Status (safe/unsafe) * given up *)
94 type w = bool
95
96 val wunit : w
97 val wprod : w -> w -> w
98
99 (** Recording info trace (true) or not. *)
100 type e = { trace: bool; name : Names.Id.t; poly : PolyFlags.t }
101
102 type u = Info.state
103
104 val uunit : u
105 end
106
107 module Logical : module type of Logic_monad.Logical(P)
108
109
110 (** {6 Lenses to access to components of the states} *)
111
112 module type State = sig
113 type t
114 val get : t Logical.t
115 val set : t -> unit Logical.t
116 val modify : (t->t) -> unit Logical.t
117 end
118 module type Reader = sig
119 type t
120 val get : t Logical.t
121 end
122
123 module type Writer = sig
124 type t
125 val put : t -> unit Logical.t
126 end
127
128 (** Lens to the [proofview]. *)
129 module Pv : State with type t := proofview
130
131 (** Lens to the [evar_map] of the proofview. *)
132 module Solution : State with type t := Evd.evar_map
133
134 (** Lens to the list of focused goals. *)
135 module Comb : State with type t = goal_with_state list
136
137 (** Lens to the global environment. *)
138 module Env : State with type t := Environ.env
139
140 (** Lens to the tactic status ([true] if safe, [false] if unsafe) *)
141 module Status : Writer with type t := bool
142
143 (** Lens and utilities pertaining to the info trace *)
144 module InfoL : sig
145 (** [record_trace t] behaves like [t] and compute its [info] trace. *)
146 val record_trace : 'a Logical.t -> 'a Logical.t
147
148 val update : (Info.state -> Info.state) -> unit Logical.t
149 val opn : Info.tag -> unit Logical.t
150 val close : unit Logical.t
151 val leaf : Info.tag -> unit Logical.t
152
153 (** [tag a t] opens tag [a] runs [t] then closes the tag. *)
154 val tag : Info.tag -> 'a Logical.t -> 'a Logical.t
155 end