| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
open Goptions |
| 12 |
|
| 13 |
module Dyn = Dyn.Make() |
| 14 |
|
| 15 |
module DMap = Dyn.Map(struct type 'a t = 'a -> unit Proofview.tactic end) |
| 16 |
|
| 17 |
let interp_map = ref DMap.empty |
| 18 |
|
| 19 |
type interpretable = I : 'a Dyn.tag * 'a -> interpretable |
| 20 |
type 'a tactic_interpreter = Interpreter of ('a -> interpretable) |
| 21 |
|
| 22 |
let register_tactic_interpreter na f = |
| 23 |
let t = Dyn.create na in |
| 24 |
interp_map := DMap.add t f !interp_map; |
| 25 |
Interpreter (fun x -> I (t,x)) |
| 26 |
|
| 27 |
let interp_tac (I (tag,t)) = |
| 28 |
let f = DMap.find tag !interp_map in |
| 29 |
f t |
| 30 |
|
| 31 |
type parallel_solver = |
| 32 |
pstate:Declare.Proof.t -> |
| 33 |
info:int option -> |
| 34 |
interpretable -> |
| 35 |
abstract:bool -> |
| 36 |
Declare.Proof.t |
| 37 |
|
| 38 |
let { Goptions.get = print_info_trace } = |
| 39 |
declare_intopt_option_and_ref |
| 40 |
~key:["Info" ; "Level"] |
| 41 |
~value:None |
| 42 |
() |
| 43 |
|
| 44 |
let warn_end_tac = |
| 45 |
CWarnings.create_warning ~name:"deprecated-end-tac" ~from:[Deprecation.Version.v9_2] () |
| 46 |
|
| 47 |
let pp_warn_end_tac = |
| 48 |
let pptac end_tac = |
| 49 |
let env = Global.env() in |
| 50 |
let sigma = Evd.from_env env in |
| 51 |
let pptac = Gentactic.print_glob env sigma end_tac in |
| 52 |
Pp.(str ";" ++ spc() ++ pptac ++ str ".") |
| 53 |
in |
| 54 |
CWarnings.create_in warn_end_tac |
| 55 |
~quickfix:(fun ~loc end_tac -> [Quickfix.make ~loc (pptac end_tac)]) |
| 56 |
Pp.(fun end_tac -> |
| 57 |
fmt "Using \"...\" is deprecated, use \"%t\" instead" (fun () -> pptac end_tac)) |
| 58 |
|
| 59 |
let warn_end_tac ?loc end_tac = |
| 60 |
match end_tac with |
| 61 |
| None -> CErrors.user_err ?loc Pp.(str "This \"...\" is useless, use \".\" instead.") |
| 62 |
| Some end_tac -> |
| 63 |
pp_warn_end_tac ?loc end_tac |
| 64 |
|
| 65 |
let use_end_tac ~with_end_tac end_tac = |
| 66 |
if not with_end_tac.CAst.v then None |
| 67 |
else begin |
| 68 |
warn_end_tac ?loc:with_end_tac.loc end_tac; |
| 69 |
Option.map Gentactic.interp end_tac |
| 70 |
end |
| 71 |
|
| 72 |
let solve_core ~pstate n ~info ?(with_end_tac=CAst.make false) t = |
| 73 |
let pstate, status = Declare.Proof.map_fold_endline ~f:(fun etac p -> |
| 74 |
let with_end_tac = use_end_tac ~with_end_tac etac in |
| 75 |
let info = Option.append info (print_info_trace ()) in |
| 76 |
let (p,status) = Proof.solve (Global.env ()) n info t ?with_end_tac p in |
| 77 |
|
| 78 |
|
| 79 |
let p = Proof.maximal_unfocus Vernacentries.command_focus p in |
| 80 |
p,status) pstate in |
| 81 |
let pstate = Declare.Internal.register_side_effects pstate in |
| 82 |
if not status then Feedback.feedback Feedback.AddedAxiom; |
| 83 |
pstate |
| 84 |
|
| 85 |
let solve ~pstate n ~info ?with_end_tac t = |
| 86 |
let t = interp_tac t in |
| 87 |
solve_core ~pstate n ~info t ?with_end_tac |
| 88 |
|
| 89 |
let check_par_applicable pstate = |
| 90 |
Declare.Proof.fold pstate ~f:(fun p -> |
| 91 |
(Proof.data p).Proof.goals |> List.iter (fun goal -> |
| 92 |
let is_ground = |
| 93 |
let { Proof.sigma = sigma0 } = Declare.Proof.fold pstate ~f:Proof.data in |
| 94 |
let g = Evd.find_undefined sigma0 goal in |
| 95 |
let concl, hyps = Evd.evar_concl g, Evd.evar_context g in |
| 96 |
Evarutil.is_ground_term sigma0 concl && |
| 97 |
List.for_all (Context.Named.Declaration.for_all (Evarutil.is_ground_term sigma0)) hyps in |
| 98 |
if not is_ground then |
| 99 |
CErrors.user_err |
| 100 |
Pp.(strbrk("The par: goal selector does not support goals with existential variables")))) |
| 101 |
|
| 102 |
let par_implementation : parallel_solver ref = ref (fun ~pstate ~info t ~abstract -> |
| 103 |
let t = interp_tac t in |
| 104 |
let t = Proofview.Goal.enter (fun _ -> |
| 105 |
if abstract then Abstract.tclABSTRACT None ~opaque:true t else t) |
| 106 |
in |
| 107 |
solve_core ~pstate Goal_select.SelectAll ~info t) |
| 108 |
|
| 109 |
let set_par_implementation f = par_implementation := f |
| 110 |
|
| 111 |
let solve_parallel ~pstate ~info t ~abstract = |
| 112 |
check_par_applicable pstate; |
| 113 |
!par_implementation ~pstate ~info t ~abstract |