1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
type t = Vernacstate.t
let marshal_in ic : t = Marshal.from_channel ic
let marshal_out oc st = Marshal.to_channel oc st []
let of_coq x = x
let to_coq x = x
let compare (x : t) (y : t) =
let open Vernacstate in
let { parsing = ps1
; system = is1
; lemmas = l1
; program = g1
; opaques = o1
; shallow = h1
} =
x
in
let { parsing = ps2
; system = is2
; lemmas = l2
; program = g2
; opaques = o2
; shallow = h2
} =
y
in
if ps1 == ps2 && is1 == is2 && l1 == l2 && g1 == g2 && o1 == o2 && h1 == h2
then 0
else 1
let equal x y = compare x y = 0
let hash x =
let meaningful, total = (64, 256) in
Hashtbl.hash_param meaningful total x
let mode ~st =
Option.map
(fun _ -> Vernacinterp.get_default_proof_mode ())
st.Vernacstate.lemmas
let parsing ~st = st.Vernacstate.parsing
module Proof_ = Proof
module Proof = struct
type t = Vernacstate.LemmaStack.t
let to_coq x = x
let equal x y = x == y
let hash x =
let meaningful, total = (128, 256) in
Hashtbl.hash_param meaningful total x
end
let lemmas ~st = st.Vernacstate.lemmas
module Declare_ = Declare
module Declare = struct
open Names
open Constr
[@@@ocaml.warning "-34"]
[@@@ocaml.warning "-37"]
type 'a obligation_body =
| DefinedObl of 'a
| TermObl of constr
type fixpoint_kind =
| IsFixpoint of lident option list
| IsCoFixpoint
module Obligation = struct
type t =
{ obl_name : Id.t
; obl_type : types
; obl_location : Evar_kinds.t Loc.located
; obl_body : pconstant obligation_body option
; obl_status : bool * Evar_kinds.obligation_definition_status
; obl_deps : Int.Set.t
; obl_tac : unit Proofview.tactic option
}
end
module ProgramDecl = struct
type obligations =
{ obls : Obligation.t array
; remaining : int
}
type 'a t =
{ prg_cinfo : constr Declare.CInfo.t
; prg_info : Declare.Info.t
; prg_opaque : bool
; prg_hook : 'a option
; prg_body : Constr.constr
; prg_uctx : UState.t
; prg_obligations : obligations
; prg_deps : Id.t list
; prg_fixkind : fixpoint_kind option
; prg_notations : Metasyntax.where_decl_notation list
; prg_reduce : constr -> constr
}
end
module ProgMap = Id.Map
module OblState = struct
type t = prg_hook ProgramDecl.t CEphemeron.key ProgMap.t
and prg_hook = PrgHook of t Declare.Hook.g
module View = struct
module Obl = struct
type t =
{ name : Names.Id.t
; loc : Loc.t option
; status : bool * Evar_kinds.obligation_definition_status
; solved : bool
}
let make (o : Obligation.t) =
let { Obligation.obl_name; obl_location; obl_status; obl_body; _ } =
o
in
{ name = obl_name
; loc = fst obl_location
; status = obl_status
; solved = Option.has_some obl_body
}
end
type t =
{ opaque : bool
; remaining : int
; obligations : Obl.t array
}
let make { ProgramDecl.prg_opaque; prg_obligations; _ } =
{ opaque = prg_opaque
; remaining = prg_obligations.remaining
; obligations = Array.map Obl.make prg_obligations.obls
}
let make eph = CEphemeron.get eph |> make
end
let view s = Names.Id.Map.map View.make (Obj.magic s)
end
end
let program ~st = NeList.head st.Vernacstate.program |> Declare.OblState.view
let drop_proof ~st =
let open Vernacstate in
{ st with
lemmas =
Option.cata (fun s -> snd @@ Vernacstate.LemmaStack.pop s) None st.lemmas
}
let drop_all_proofs ~st =
let open Vernacstate in
{ st with lemmas = None }
let in_state ~token ~st ~f a =
let f a =
Vernacstate.unfreeze_interp_state st;
f a
in
Protect.eval ~token ~f a
let in_stateM ~token ~st ~f a =
let open Protect.E.O in
let* () = Protect.eval ~token ~f:Vernacstate.unfreeze_interp_state st in
f a
let admit ~st () =
let () = Vernacstate.unfreeze_interp_state st in
match st.Vernacstate.lemmas with
| None -> st
| Some lemmas ->
let pm = NeList.head st.Vernacstate.program in
let proof, lemmas = Vernacstate.(LemmaStack.pop lemmas) in
let pm = Declare_.Proof.save_admitted ~pm ~proof in
let program = NeList.map_head (fun _ -> pm) st.Vernacstate.program in
let st = Vernacstate.freeze_interp_state ~marshallable:false in
{ st with lemmas; program }
let admit ~token ~st = Protect.eval ~token ~f:(admit ~st) ()
let admit_goal ~st () =
let () = Vernacstate.unfreeze_interp_state st in
match st.Vernacstate.lemmas with
| None -> st
| Some lemmas ->
let f pf = Declare_.Proof.by Proofview.give_up pf |> fst in
let lemmas = Some (Vernacstate.LemmaStack.map_top ~f lemmas) in
{ st with lemmas }
let admit_goal ~token ~st = Protect.eval ~token ~f:(admit_goal ~st) ()
let count_edges univ =
let univ = UGraph.repr univ in
Univ.Level.Map.fold
(fun _ node acc ->
acc
+
match node with
| UGraph.Alias _ -> 1
| Node m -> Univ.Level.Map.cardinal m)
univ
(Univ.Level.Map.cardinal univ)
let info_universes ~token ~st =
let open Protect.E.O in
let+ univ = in_state ~token ~st ~f:Global.universes () in
let univs = UGraph.domain univ in
let nuniv = Univ.Level.Set.cardinal univs in
let nconst = count_edges univ in
(nuniv, nconst)