Debian Codegraph @

tactics/tacticals.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 Pp
12 open CErrors
13 open Util
14 open Names
15 open Constr
16 open EConstr
17 open Declarations
18 open Tactypes
19 open Proofview
20 open Proofview.Notations
21
22 module RelDecl = Context.Rel.Declaration
23 module NamedDecl = Context.Named.Declaration
24
25 (*********************)
26 (* Tacticals *)
27 (*********************)
28
29 exception FailError of int * Pp.t Lazy.t
30
31 let catch_failerror (e, info) =
32 match e with
33 | FailError (lvl,s) when lvl > 0 ->
34 tclZERO ~info (FailError (lvl - 1, s))
35 | e ->
36 Control.check_for_interrupt ();
37 tclUNIT ()
38
39 (************************************************************************)
40 (* Elimination Tacticals *)
41 (************************************************************************)
42
43 (* The following tacticals allow to apply a tactic to the
44 branches generated by the application of an elimination
45 tactic.
46
47 Two auxiliary types --branch_args and branch_assumptions-- are
48 used to keep track of some information about the ``branches'' of
49 the elimination. *)
50
51 let fix_empty_or_and_pattern nv l =
52 (* 1- The syntax does not distinguish between "[ ]" for one clause with no
53 names and "[ ]" for no clause at all *)
54 (* 2- More generally, we admit "[ ]" for any disjunctive pattern of
55 arbitrary length *)
56 match l with
57 | IntroOrPattern [[]] -> IntroOrPattern (List.make nv [])
58 | _ -> l
59
60 let check_or_and_pattern_size ?loc check_and names branchsigns =
61 let n = Array.length branchsigns in
62 let msg p1 p2 = strbrk "a conjunctive pattern made of " ++ int p1 ++ (if p1 == p2 then mt () else str " or " ++ int p2) ++ str " patterns" in
63 let err1 p1 p2 =
64 user_err ?loc (str "Expects " ++ msg p1 p2 ++ str ".") in
65 let errn n =
66 user_err ?loc (str "Expects a disjunctive pattern with " ++ int n
67 ++ str " branches.") in
68 let err1' p1 p2 =
69 user_err ?loc (strbrk "Expects a disjunctive pattern with 1 branch or " ++ msg p1 p2 ++ str ".") in
70 let errforthcoming ?loc =
71 user_err ?loc (strbrk "Unexpected non atomic pattern.") in
72 match names with
73 | IntroAndPattern l ->
74 if not (Int.equal n 1) then errn n;
75 let l' = List.filter CAst.(function {v=IntroForthcoming _} -> true | {v=IntroNaming _} | {v=IntroAction _} -> false) l in
76 if l' != [] then errforthcoming ?loc:(List.hd l').CAst.loc;
77 if check_and then
78 let p1 = List.count (fun x -> x) branchsigns.(0) in
79 let p2 = List.length branchsigns.(0) in
80 let p = List.length l in
81 if not (Int.equal p p1 || Int.equal p p2) then err1 p1 p2;
82 if Int.equal p p1 then
83 IntroAndPattern
84 (List.extend branchsigns.(0) (CAst.make @@ IntroNaming Namegen.IntroAnonymous) l)
85 else
86 names
87 else
88 names
89 | IntroOrPattern ll ->
90 if not (Int.equal n (List.length ll)) then
91 if Int.equal n 1 then
92 let p1 = List.count (fun x -> x) branchsigns.(0) in
93 let p2 = List.length branchsigns.(0) in
94 err1' p1 p2 else errn n;
95 names
96
97 let get_and_check_or_and_pattern_gen ?loc check_and names branchsigns =
98 let names = check_or_and_pattern_size ?loc check_and names branchsigns in
99 match names with
100 | IntroAndPattern l -> [|l|]
101 | IntroOrPattern l -> Array.of_list l
102
103 let get_and_check_or_and_pattern ?loc = get_and_check_or_and_pattern_gen ?loc true
104
105 let compute_induction_names check_and branchletsigns = function
106 | None ->
107 Array.make (Array.length branchletsigns) []
108 | Some {CAst.loc;v=names} ->
109 let names = fix_empty_or_and_pattern (Array.length branchletsigns) names in
110 get_and_check_or_and_pattern_gen check_and ?loc names branchletsigns
111
112 let is_recursive_argument env self recarg = match Declareops.dest_recarg recarg with
113 | Norec | Mrec (RecArgPrim _) -> false
114 | Mrec (RecArgInd ind) -> Environ.QInd.equal env self ind
115
116 (* Compute the let-in signature of case analysis or standard induction scheme *)
117 let compute_constructor_signatures env ~rec_flag ((_,k as ity),u) =
118 let rec analrec c recargs =
119 match c, recargs with
120 | RelDecl.LocalAssum _ :: c, recarg::rest ->
121 let rest = analrec c rest in
122 if rec_flag && is_recursive_argument env ity recarg then true :: true :: rest
123 else true :: rest
124 | RelDecl.LocalDef _ :: c, rest -> false :: analrec c rest
125 | [], [] -> []
126 | _ -> anomaly (Pp.str "compute_constructor_signatures.")
127 in
128 let (mib,mip) = Inductive.lookup_mind_specif env ity in
129 let map (ctx, _) = List.skipn (Context.Rel.length mib.mind_params_ctxt) (List.rev ctx) in
130 let lc = Array.map map mip.mind_nf_lc in
131 let lrecargs = Declareops.dest_subterms mip.mind_recargs in
132 Array.map2 analrec lc lrecargs
133
134 let tclIDTAC = tclUNIT ()
135
136 let tclTHEN t1 t2 =
137 t1 <*> t2
138
139 let tclFAILn ?info lvl msg =
140 let info = match info with
141 (* If the backtrace points here it means the caller didn't save
142 the backtrace correctly *)
143 | None -> Exninfo.reify ()
144 | Some info -> info
145 in
146 tclZERO ~info (FailError (lvl,lazy msg))
147
148 let tclFAIL ?info msg = tclFAILn ?info 0 msg
149
150 let tclZEROMSG ?info ?loc msg =
151 let info = match info with
152 (* If the backtrace points here it means the caller didn't save
153 the backtrace correctly *)
154 | None -> Exninfo.reify ()
155 | Some info -> info
156 in
157 let info = match loc with
158 | None -> info
159 | Some loc -> Loc.add_loc info loc
160 in
161 let err = UserError msg in
162 tclZERO ~info err
163
164 (* spiwack: I chose to give the Ltac + the same semantics as
165 [Proofview.tclOR], however, for consistency with the or-else
166 tactical, we may consider wrapping the first argument with
167 [tclPROGRESS]. It strikes me as a bad idea, but consistency can be
168 considered valuable. *)
169 let tclOR t1 t2 =
170 tclINDEPENDENT begin
171 Proofview.tclOR
172 t1
173 begin fun e ->
174 catch_failerror e <*> t2
175 end
176 end
177
178 let tclORD t1 t2 =
179 tclINDEPENDENT begin
180 Proofview.tclOR
181 t1
182 begin fun e ->
183 catch_failerror e <*> t2 ()
184 end
185 end
186
187 let tclONCE = Proofview.tclONCE
188
189 let tclEXACTLY_ONCE t = Proofview.tclEXACTLY_ONCE (FailError(0,lazy (assert false))) t
190
191 let tclIFCATCH t tt te =
192 tclINDEPENDENT begin
193 Proofview.tclIFCATCH t
194 tt
195 (fun e -> catch_failerror e <*> te ())
196 end
197
198 let tclORELSE0 t1 t2 =
199 tclINDEPENDENT begin
200 tclORELSE
201 t1
202 begin fun e ->
203 catch_failerror e <*> t2
204 end
205 end
206
207 let tclORELSE0L t1 t2 =
208 tclINDEPENDENTL begin
209 tclORELSE
210 t1
211 begin fun e ->
212 catch_failerror e <*> t2
213 end
214 end
215
216 let tclORELSE t1 t2 =
217 tclORELSE0 (tclPROGRESS t1) t2
218
219 let tclTHENS3PARTS t1 l1 repeat l2 =
220 tclINDEPENDENT begin
221 t1 <*>
222 Proofview.tclORELSE (* converts the [SizeMismatch] error into an ltac error *)
223 begin tclEXTEND (Array.to_list l1) repeat (Array.to_list l2) end
224 begin function (e, info) -> match e with
225 | SizeMismatch (i,_)->
226 let errmsg =
227 str"Incorrect number of goals" ++ spc() ++
228 str"(expected "++int i++str(String.plural i " tactic") ++ str")"
229 in
230 tclFAIL errmsg
231 | reraise -> tclZERO ~info reraise
232 end
233 end
234 let tclTHENSFIRSTn t1 l repeat =
235 tclTHENS3PARTS t1 l repeat [||]
236 let tclTHENFIRSTn t1 l =
237 tclTHENSFIRSTn t1 l (tclUNIT())
238 let tclTHENFIRST t1 t2 =
239 tclTHENFIRSTn t1 [|t2|]
240
241 let tclBINDFIRST t1 t2 =
242 t1 >>= fun ans ->
243 Proofview.Unsafe.tclGETGOALS >>= fun gls ->
244 match gls with
245 | [] -> tclFAIL (str "Expect at least one goal.")
246 | hd::tl ->
247 Proofview.Unsafe.tclSETGOALS [hd] <*> t2 ans >>= fun ans ->
248 Proofview.Unsafe.tclNEWGOALS tl <*>
249 Proofview.tclUNIT ans
250
251 let tclTHENSLASTn t1 repeat l =
252 tclTHENS3PARTS t1 [||] repeat l
253
254 let tclTHENLASTn t1 l =
255 tclTHENS3PARTS t1 [||] (tclUNIT()) l
256 let tclTHENLAST t1 t2 = tclTHENLASTn t1 [|t2|]
257
258 let option_of_failure f x = try Some (f x) with Failure _ -> None
259
260 let tclBINDLAST t1 t2 =
261 t1 >>= fun ans ->
262 Proofview.Unsafe.tclGETGOALS >>= fun gls ->
263 match option_of_failure List.sep_last gls with
264 | None -> tclFAIL (str "Expect at least one goal.")
265 | Some (last,firstn) ->
266 Proofview.Unsafe.tclSETGOALS [last] <*> t2 ans >>= fun ans ->
267 Proofview.Unsafe.tclGETGOALS >>= fun newgls ->
268 tclEVARMAP >>= fun sigma ->
269 let firstn = Proofview.Unsafe.undefined sigma firstn in
270 Proofview.Unsafe.tclSETGOALS (firstn@newgls) <*>
271 Proofview.tclUNIT ans
272
273 let tclTHENS t l =
274 tclINDEPENDENT begin
275 t <*>Proofview.tclORELSE (* converts the [SizeMismatch] error into an ltac error *)
276 begin tclDISPATCH l end
277 begin function (e, info) -> match e with
278 | SizeMismatch (i,_)->
279 let errmsg =
280 str"Incorrect number of goals" ++ spc() ++
281 str"(expected "++int i++str(String.plural i " tactic") ++ str")"
282 in
283 tclFAIL errmsg
284 | reraise -> tclZERO ~info reraise
285 end
286 end
287 let tclTHENLIST l =
288 List.fold_left tclTHEN (tclUNIT()) l
289
290
291 (* [tclMAP f [x1..xn]] builds [(f x1);(f x2);...(f xn)] *)
292 let tclMAP tacfun l =
293 List.fold_right (fun x -> (tclTHEN (tacfun x))) l (tclUNIT())
294
295 let tclTRY t =
296 tclORELSE0 t (tclUNIT ())
297
298 let tclTRYb t =
299 tclORELSE0L (t <*> tclUNIT true) (tclUNIT false)
300
301 let tclIFTHENELSE t1 t2 t3 =
302 tclINDEPENDENT begin
303 Proofview.tclIFCATCH t1
304 (fun () -> t2)
305 (fun (e, info) -> Proofview.tclORELSE t3 (fun e' -> tclZERO ~info e))
306 end
307 let tclIFTHENSVELSE t1 a t3 =
308 Proofview.tclIFCATCH t1
309 (fun () -> tclDISPATCH (Array.to_list a))
310 (fun _ -> t3)
311 let tclIFTHENFIRSTELSE t1 t2 t3 =
312 Proofview.tclIFCATCH t1
313 (fun () -> tclEXTEND [t2] (tclUNIT ()) [])
314 (fun _ -> t3)
315 let tclIFTHENTRYELSEMUST t1 t2 =
316 tclIFTHENELSE t1 (tclTRY t2) t2
317 let tclIFTHENFIRSTTRYELSEMUST t1 t2 =
318 tclIFTHENFIRSTELSE t1 (tclTRY t2) t2
319
320 (* Try the first tactic that does not fail in a list of tactics *)
321 let rec tclFIRST = function
322 | [] ->
323 let info = Exninfo.reify () in
324 tclZEROMSG ~info (str"No applicable tactic.")
325 | t::rest -> tclORELSE0 t (tclFIRST rest)
326
327 let rec tclFIRST_PROGRESS_ON tac = function
328 | [] -> tclFAIL (str "No applicable tactic")
329 | [a] -> tac a (* so that returned failure is the one from last item *)
330 | a::tl -> tclORELSE (tac a) (tclFIRST_PROGRESS_ON tac tl)
331
332 let rec tclDO n t =
333 if n < 0 then
334 let info = Exninfo.reify () in
335 tclZEROMSG ~info (str"Wrong argument : Do needs a positive integer.")
336 else if n = 0 then tclUNIT ()
337 else if n = 1 then t
338 else
339 (* Thunk to avoid stack overflow with large n *)
340 tclTHEN t (tclUNIT () >>= fun () -> (tclDO (n-1) t))
341
342 let rec tclREPEAT0 t =
343 tclINDEPENDENT begin
344 Proofview.tclIFCATCH t
345 (fun () -> tclCHECKINTERRUPT <*> tclREPEAT0 t)
346 (fun e -> catch_failerror e <*> tclUNIT ())
347 end
348 let tclREPEAT t =
349 tclREPEAT0 (tclPROGRESS t)
350 let rec tclREPEAT_MAIN0 t =
351 Proofview.tclIFCATCH t
352 (fun () -> tclTRYFOCUS 1 1 (tclREPEAT_MAIN0 t))
353 (fun e -> catch_failerror e <*> tclUNIT ())
354 let tclREPEAT_MAIN t =
355 tclREPEAT_MAIN0 (tclPROGRESS t)
356
357 let tclCOMPLETE t =
358 t >>= fun res ->
359 (tclINDEPENDENT
360 (let info = Exninfo.reify () in
361 tclZEROMSG ~info (str"Proof is not complete."))
362 ) <*>
363 tclUNIT res
364
365 (* Try the first that solves the current goal *)
366 let tclSOLVE tacl = tclFIRST (List.map tclCOMPLETE tacl)
367
368 let tclPROGRESS t =
369 Proofview.tclINDEPENDENT (Proofview.tclPROGRESS t)
370
371 (* Check that holes in arguments have been resolved *)
372
373 let check_evar_list env sigma evars origsigma =
374 (* origsigma ⊆ sigma *)
375 (* evars ⊆ sigma *)
376 let reachable = lazy (Evarutil.reachable_from_evars sigma
377 (Evar.Map.domain (Evd.undefined_map origsigma))) in
378 let rec is_undefined_up_to_restriction sigma evk =
379 if Evd.mem origsigma evk then None else
380 let EvarInfo evi = Evd.find sigma evk in
381 match Evd.evar_body evi with
382 | Evd.Evar_empty -> Some (evk, Evd.EvarInfo evi)
383 | Evd.Evar_defined c -> match Constr.kind (EConstr.Unsafe.to_constr c) with
384 | Evar (evk,l) -> is_undefined_up_to_restriction sigma evk
385 | _ ->
386 (* We make the assumption that there is no way to refine an
387 evar remaining after typing from the initial term given to
388 apply/elim and co tactics, is it correct? *)
389 None in
390 Evar.Set.fold (fun evk acc ->
391 match is_undefined_up_to_restriction sigma evk with
392 | Some (evk',evi) ->
393 (* If [evk'] descends from [evk] which descends itself from
394 an originally undefined evar in [origsigma], it is a not
395 a fresh undefined hole from [sigma]. *)
396 if Evar.Set.mem evk (Lazy.force reachable) then acc
397 else evk'::acc
398 | _ -> acc)
399 evars []
400
401 let check_evars env sigma extsigma origsigma =
402 (* origsigma ⊆ extsigma ⊆ sigma *)
403 if Evd.undefined_map extsigma != Evd.undefined_map origsigma then
404 match check_evar_list env sigma (Evar.Map.domain (Evd.undefined_map extsigma)) origsigma with
405 | [] -> ()
406 | evk :: _ ->
407 let EvarInfo evi = Evd.find sigma evk in
408 let (loc,_) = Evd.evar_source evi in
409 Pretype_errors.error_unsolvable_implicit ?loc env sigma evk None
410
411 let tclMAPDELAYEDWITHHOLES accept_unresolved_holes l tac =
412 let rec aux = function
413 | [] -> tclUNIT ()
414 | x :: l ->
415 Proofview.Goal.enter begin fun gl ->
416 let env = Proofview.Goal.env gl in
417 let sigma_initial = Proofview.Goal.sigma gl in
418 let (sigma, x) = x env sigma_initial in
419 Proofview.Unsafe.tclEVARS sigma <*> tac x >>= fun () -> aux l >>= fun () ->
420 if accept_unresolved_holes then
421 tclUNIT ()
422 else
423 tclEVARMAP >>= fun sigma_final ->
424 try
425 let () = check_evars env sigma_final sigma sigma_initial in
426 tclUNIT ()
427 with e when CErrors.noncritical e ->
428 let e, info = Exninfo.capture e in
429 tclZERO ~info e
430 end in
431 aux l
432
433 (* The following is basically
434 tclMAPDELAYEDWITHHOLES accept_unresolved_holes [fun _ _ -> (sigma,())] (fun () -> tac)
435 but with value not necessarily in unit *)
436
437 let with_holes_check ~sigma_initial ~sigma =
438 tclEVARMAP >>= fun sigma_final ->
439 tclENV >>= fun env ->
440 try
441 let () = check_evars env sigma_final sigma sigma_initial in
442 tclUNIT ()
443 with e when CErrors.noncritical e ->
444 let e, info = Exninfo.capture e in
445 tclZERO ~info e
446
447 let tclRUNWITHHOLES accept_unresolved_holes tac0 tac =
448 if accept_unresolved_holes then tac0 >>= tac
449 else
450 tclEVARMAP >>= fun sigma_initial ->
451 tac0 >>= fun v ->
452 tclEVARMAP >>= fun sigma ->
453 if sigma == sigma_initial then tac v
454 else
455 tac v >>= fun v ->
456 with_holes_check ~sigma_initial ~sigma <*>
457 tclUNIT v
458
459 let tclWITHHOLES accept_unresolved_holes tac sigma =
460 tclEVARMAP >>= fun sigma_initial ->
461 if sigma == sigma_initial then tac
462 else
463 Proofview.Unsafe.tclEVARS sigma <*>
464 tac >>= fun v ->
465 (if accept_unresolved_holes then tclUNIT () else with_holes_check ~sigma_initial ~sigma) <*>
466 tclUNIT v
467
468 let tactic_of_delayed d =
469 Proofview.Goal.enter_one ~__LOC__ @@ fun gl ->
470 let env = Proofview.Goal.env gl in
471 let sigma = Proofview.Goal.sigma gl in
472 let sigma, v = d env sigma in
473 Proofview.Unsafe.tclEVARS sigma <*>
474 tclUNIT v
475
476 let tclDELAYEDWITHHOLES check x tac =
477 Proofview.Goal.enter begin fun gl ->
478 let env = Proofview.Goal.env gl in
479 let sigma = Proofview.Goal.sigma gl in
480 let (sigma, x) = x env sigma in
481 tclWITHHOLES check (tac x) sigma
482 end
483
484 let tclTIMEOUT n t =
485 Proofview.tclOR
486 (Proofview.tclTIMEOUT n t)
487 begin function (e, info) -> match e with
488 | Logic_monad.Tac_Timeout as e ->
489 let info = Exninfo.reify () in
490 Proofview.tclZERO ~info (FailError (0,lazy (CErrors.print e)))
491 | e -> Proofview.tclZERO ~info e
492 end
493
494 let tclTIME s t =
495 Proofview.tclTIME s t
496
497 let nthDecl m gl =
498 let hyps = Proofview.Goal.hyps gl in
499 try
500 List.nth hyps (m-1)
501 with Failure _ -> CErrors.user_err Pp.(str "No such assumption.")
502
503 let nLastDecls gl n =
504 try List.firstn n (Proofview.Goal.hyps gl)
505 with Failure _ -> CErrors.user_err Pp.(str "Not enough hypotheses in the goal.")
506
507 let nthHypId m gl =
508 (* We only use [id] *)
509 nthDecl m gl |> NamedDecl.get_id
510 let nthHyp m gl =
511 mkVar (nthHypId m gl)
512
513 let onNthHypId m tac =
514 Proofview.Goal.enter begin fun gl -> tac (nthHypId m gl) end
515 let onNthHyp m tac =
516 Proofview.Goal.enter begin fun gl -> tac (nthHyp m gl) end
517
518 let onLastHypId = onNthHypId 1
519 let onLastHyp = onNthHyp 1
520
521 let onNthDecl m tac =
522 Proofview.Goal.enter begin fun gl ->
523 Proofview.tclUNIT (nthDecl m gl) >>= tac
524 end
525 let onLastDecl = onNthDecl 1
526
527 let nLastHypsId gl n = List.map (NamedDecl.get_id) (nLastDecls gl n)
528 let nLastHyps gl n = List.map mkVar (nLastHypsId gl n)
529
530 let ifOnHyp pred tac1 tac2 id =
531 Proofview.Goal.enter begin fun gl ->
532 let env = Proofview.Goal.env gl in
533 let sigma = Proofview.Goal.sigma gl in
534 let typ = Tacmach.pf_get_hyp_typ id gl in
535 if pred env sigma (id, typ) then
536 tac1 id
537 else
538 tac2 id
539 end
540
541 let onHyps find tac = Proofview.Goal.enter begin fun gl -> tac (find gl) end
542
543 let onNLastDecls n tac = onHyps (fun gl -> nLastDecls gl n) tac
544 let onNLastHypsId n tac = onHyps (fun gl -> nLastHypsId gl n) tac
545 let onNLastHyps n tac = onHyps (fun gl -> nLastHyps gl n) tac
546
547 let afterHyp id tac =
548 Proofview.Goal.enter begin fun gl ->
549 let hyps = Proofview.Goal.hyps gl in
550 let rem, _ = List.split_when (NamedDecl.get_id %> Id.equal id) hyps in
551 tac rem
552 end
553
554 let fullGoal gl =
555 let hyps = Tacmach.pf_ids_of_hyps gl in
556 None :: List.map Option.make hyps
557
558 let tryAllHyps tac =
559 Proofview.Goal.enter begin fun gl ->
560 let hyps = Tacmach.pf_ids_of_hyps gl in
561 tclFIRST_PROGRESS_ON tac hyps
562 end
563 let tryAllHypsAndConcl tac =
564 Proofview.Goal.enter begin fun gl ->
565 tclFIRST_PROGRESS_ON tac (fullGoal gl)
566 end
567
568 let onClause tac cl =
569 Proofview.Goal.enter begin fun gl ->
570 let hyps = Tacmach.pf_ids_of_hyps gl in
571 tclMAP tac (Locusops.simple_clause_of (fun () -> hyps) cl)
572 end
573
574 let fullGoal gl = None :: List.map Option.make (Tacmach.pf_ids_of_hyps gl)
575 let onAllHyps tac =
576 Proofview.Goal.enter begin fun gl ->
577 tclMAP tac (Tacmach.pf_ids_of_hyps gl)
578 end
579 let onAllHypsAndConcl tac =
580 Proofview.Goal.enter begin fun gl ->
581 tclMAP tac (fullGoal gl)
582 end
583
584 let elimination_sort_of_goal gl =
585 let env = Proofview.Goal.env gl in
586 let sigma = Proofview.Goal.sigma gl in
587 let c = Proofview.Goal.concl gl in
588 Retyping.get_sort_quality_of env sigma c
589
590 let elimination_sort_of_hyp id gl =
591 let env = Proofview.Goal.env gl in
592 let sigma = Proofview.Goal.sigma gl in
593 let c = Tacmach.pf_get_hyp_typ id gl in
594 Retyping.get_sort_quality_of env sigma c
595
596 let elimination_sort_of_clause id gl = match id with
597 | None -> elimination_sort_of_goal gl
598 | Some id -> elimination_sort_of_hyp id gl
599
600 let pf_constr_of_global ref =
601 Proofview.tclEVARMAP >>= fun sigma ->
602 Proofview.tclENV >>= fun env ->
603 let (sigma, c) = Evd.fresh_global env sigma ref in
604 Proofview.Unsafe.tclEVARS sigma <*> Proofview.tclUNIT c
605
606 let tclTYPEOFTHEN ?refresh c tac =
607 Proofview.Goal.enter (fun gl ->
608 let env = Proofview.Goal.env gl in
609 let sigma = Proofview.Goal.sigma gl in
610 let (sigma, t) = Typing.type_of ?refresh env sigma c in
611 Proofview.Unsafe.tclEVARS sigma <*> tac sigma t)