controller_itp.ml 47.3 KB
Newer Older
1 2 3
(********************************************************************)
(*                                                                  *)
(*  The Why3 Verification Platform   /   The Why3 Development Team  *)
Guillaume Melquiond's avatar
Guillaume Melquiond committed
4
(*  Copyright 2010-2018   --   Inria - CNRS - Paris-Sud University  *)
5 6 7 8 9 10 11
(*                                                                  *)
(*  This software is distributed under the terms of the GNU Lesser  *)
(*  General Public License version 2.1, with the special exception  *)
(*  on linking described in file LICENSE.                           *)
(*                                                                  *)
(********************************************************************)

12
open Format
13
open Wstdlib
Clément Fumex's avatar
Clément Fumex committed
14
open Session_itp
Sylvain Dailler's avatar
Sylvain Dailler committed
15 16
open Generic_arg_trans_utils
open Args_wrapper
Clément Fumex's avatar
Clément Fumex committed
17

Sylvain Dailler's avatar
Sylvain Dailler committed
18 19 20 21
let debug_sched = Debug.register_info_flag "scheduler"
  ~desc:"Print@ debugging@ messages@ about@ scheduling@ of@ prover@ calls@ \
         and@ transformation@ applications."

Sylvain Dailler's avatar
Sylvain Dailler committed
22
let debug_call_prover = Debug.lookup_flag "call_prover"
23 24
let default_delay_ms = 100 (* 0.1 seconds *)

Clément Fumex's avatar
Clément Fumex committed
25 26
(** State of a proof *)
type proof_attempt_status =
27
  | Undone   (** prover was never called *)
28 29 30
  | Scheduled (** external proof attempt is scheduled *)
  | Running (** external proof attempt is in progress *)
  | Done of Call_provers.prover_result (** external proof done *)
31 32
  | Interrupted (** external proof has never completed *)
  | Detached (** parent goal has no task, is detached *)
33 34
  | InternalFailure of exn (** external proof aborted by internal error *)
  | Uninstalled of Whyconf.prover (** prover is uninstalled *)
35
  | UpgradeProver of Whyconf.prover (** prover is upgraded *)
36
  | Removed of Whyconf.prover (** prover has been removed or upgraded *)
Clément Fumex's avatar
Clément Fumex committed
37

MARCHE Claude's avatar
MARCHE Claude committed
38 39
let print_status fmt st =
  match st with
40
  | Undone            -> fprintf fmt "Undone"
Sylvain Dailler's avatar
Sylvain Dailler committed
41 42 43 44
  | Scheduled         -> fprintf fmt "Scheduled"
  | Running           -> fprintf fmt "Running"
  | Done r            ->
      fprintf fmt "Done(%a)" Call_provers.print_prover_result r
45 46
  | Interrupted       -> fprintf fmt "Interrupted"
  | Detached          -> fprintf fmt "Detached"
Sylvain Dailler's avatar
Sylvain Dailler committed
47 48 49 50
  | InternalFailure e ->
      fprintf fmt "InternalFailure(%a)" Exn_printer.exn_printer e
  | Uninstalled pr    ->
      fprintf fmt "Prover %a is uninstalled" Whyconf.print_prover pr
51 52
  | UpgradeProver pr    ->
      fprintf fmt "Prover upgrade to %a" Whyconf.print_prover pr
53 54
  | Removed pr    ->
      fprintf fmt "Prover %a removed" Whyconf.print_prover pr
MARCHE Claude's avatar
MARCHE Claude committed
55 56

type transformation_status =
57
  | TSscheduled | TSdone of transID | TSfailed of (proofNodeID * exn)
Sylvain Dailler's avatar
Sylvain Dailler committed
58
  | TSfatal of (proofNodeID * exn)
59 60 61 62

let print_trans_status fmt st =
  match st with
  | TSscheduled -> fprintf fmt "TScheduled"
63
  | TSdone _tid -> fprintf fmt "TSdone" (* TODO print tid *)
64
  | TSfailed _e -> fprintf fmt "TSfailed"
Sylvain Dailler's avatar
Sylvain Dailler committed
65
  | TSfatal _e -> fprintf fmt "TSfatal"
Clément Fumex's avatar
Clément Fumex committed
66

67
type strategy_status = STSgoto of proofNodeID * int | STShalt
Sylvain Dailler's avatar
Sylvain Dailler committed
68
                     | STSfatal of string * proofNodeID * exn
69 70 71

let print_strategy_status fmt st =
  match st with
Sylvain Dailler's avatar
Sylvain Dailler committed
72 73
  | STSgoto(id,n) ->
      fprintf fmt "goto step %d in proofNode %a" n print_proofNodeID id
74
  | STShalt -> fprintf fmt "halt"
Sylvain Dailler's avatar
Sylvain Dailler committed
75
  | STSfatal _ -> fprintf fmt "fatal"
76 77


78
type controller =
Sylvain Dailler's avatar
Sylvain Dailler committed
79
  { mutable controller_session: Session_itp.session;
80
    mutable controller_config : Whyconf.config;
MARCHE Claude's avatar
MARCHE Claude committed
81
    mutable controller_env: Env.env;
Sylvain Dailler's avatar
Sylvain Dailler committed
82 83
    controller_provers:
      (Whyconf.config_prover * Driver.driver) Whyconf.Hprover.t;
84
    controller_strategies : (string * string * string * Strategy.instruction array) Hstr.t;
85
    controller_running_proof_attempts : unit Hpan.t;
86 87
  }

88 89 90 91 92
let session_max_tasks = ref 1

let set_session_max_tasks n =
  session_max_tasks := n;
  Prove_client.set_max_running_provers n
93

94 95 96
let set_session_prover_upgrade_policy c p u =
  c.controller_config <- Whyconf.set_prover_upgrade_policy c.controller_config p u

MARCHE Claude's avatar
MARCHE Claude committed
97 98 99
let load_drivers c =
  let env = c.controller_env in
  let config = c.controller_config in
100 101 102 103
  let provers = Whyconf.get_provers config in
  Whyconf.Mprover.iter
    (fun _ p ->
     try
104
       let d = Whyconf.load_driver (Whyconf.get_main config) env p.Whyconf.driver [] in
105 106
       Whyconf.Hprover.add c.controller_provers p.Whyconf.prover (p,d)
     with e ->
Sylvain Dailler's avatar
Sylvain Dailler committed
107
       Debug.dprintf debug_call_prover
108 109 110
         "[Controller_itp] error while loading driver for prover %a: %a@."
         Whyconf.print_prover p.Whyconf.prover
         Exn_printer.exn_printer e)
MARCHE Claude's avatar
MARCHE Claude committed
111 112 113 114 115 116 117 118 119
    provers

let create_controller config env ses =
  let c =
    {
      controller_session = ses;
      controller_config = config;
      controller_env = env;
      controller_provers = Whyconf.Hprover.create 7;
120
      controller_strategies = Hstr.create 7;
MARCHE Claude's avatar
MARCHE Claude committed
121 122 123 124
      controller_running_proof_attempts = Hpan.create 17;
    }
  in
  load_drivers c;
125 126
  c

127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147

(* Cannot remove a proof_attempt that was scheduled but did not finish yet.
   It can be interrupted though. *)
let removable_proof_attempt c pa =
  try let () = Hpan.find c.controller_running_proof_attempts pa in false
  with Not_found -> true

let any_removable c any =
  match any with
  | APa pa -> removable_proof_attempt c pa
  | _ -> true

(* Check whether the subtree [n] contains an unremovable proof_attempt
   (ie: scheduled or running) *)
let check_removable c (n: any) =
  fold_all_any c.controller_session (fun acc any -> acc && any_removable c any) true n


let remove_subtree ~(notification:notifier) ~(removed:notifier) c (n: any) =
  if check_removable c n then
    Session_itp.remove_subtree ~notification ~removed c.controller_session n
148

149 150 151
(* Get children of any without proofattempts *)
let get_undetached_children_no_pa s any : any list =
  match any with
152
  | AFile f -> List.map (fun th -> ATh th) (file_theories f)
153 154 155
  | ATh th  -> List.map (fun g -> APn g) (theory_goals th)
  | ATn tn  -> List.map (fun pn -> APn pn) (get_sub_tasks s tn)
  | APn pn  -> List.map (fun tn -> ATn tn) (get_transformations s pn)
Sylvain Dailler's avatar
Sylvain Dailler committed
156
  | APa _ -> []
157

158 159


160 161 162 163 164 165 166 167 168 169
(* printing *)

module PSession = struct

  type any =
    | Session
    | File of file
    | Theory of theory
    | Goal of proofNodeID
    | Transf of transID
170
    | ProofAttempt of proof_attempt_node
171 172 173 174 175 176 177 178 179 180

  type 'a t = { tcont : controller;
                tkind : any }

  let decomp x =
    let s = x.tcont.controller_session in
    let n y acc = { x with tkind = y } :: acc in
    match x.tkind with
    | Session -> "", Hstr.fold (fun _ f -> n (File f)) (get_files s) []
    | File f ->
181
       (file_name f),
182
       List.fold_right (fun th -> n (Theory th)) (file_theories f) []
183 184 185
    | Theory th ->
       let id = theory_name th in
       let name = id.Ident.id_string in
186
       let name = if th_proved s th then name^"!" else name^"?" in
187
       name,
Sylvain Dailler's avatar
Sylvain Dailler committed
188 189 190
       List.fold_right
         (fun g -> n (Goal g))
         (theory_goals th)
MARCHE Claude's avatar
MARCHE Claude committed
191
         []
192 193 194
    | Goal id ->
       let gid = get_proof_name s id in
       let name = gid.Ident.id_string in
195
       let name = if pn_proved s id then name^"!" else name^"?" in
196 197 198 199 200 201 202
       let pas = get_proof_attempts s id in
       let trs = get_transformations s id in
       name,
       List.fold_right (fun g -> n (Transf g)) trs
                       (List.fold_right (fun g -> n (ProofAttempt g)) pas [])
    | ProofAttempt pa ->
       Pp.sprintf_wnl "%a%s%s"
Sylvain Dailler's avatar
Sylvain Dailler committed
203 204 205 206 207
          Whyconf.print_prover pa.prover
          (match pa.Session_itp.proof_state with
          | Some { Call_provers.pr_answer = Call_provers.Valid} -> ""
          | _ -> "?")
          (if pa.proof_obsolete then "O" else ""), []
208 209
    | Transf id ->
       let name = get_transf_name s id in
210
       let name = if tn_proved s id then name^"!" else name^"?" in
211 212
       let sts = get_sub_tasks s id in
       name,
MARCHE Claude's avatar
MARCHE Claude committed
213
       List.fold_right (fun g -> n (Goal g)) sts []
214 215 216 217 218 219 220 221 222 223 224 225

end

module P = Print_tree.PMake(PSession)

let print_session fmt c =
  P.print fmt { PSession.tcont = c; PSession.tkind = PSession.Session }

(*********)



226 227 228 229 230 231

(** reload files, associating old proof attempts and transformations
    to the new goals.  old theories and old goals for which we cannot
    find a corresponding new theory resp. old goal are kept, with
    tasks associated to them *)

232
let reload_files (c : controller) ~shape_version =
233
  let old_ses = c.controller_session in
MARCHE Claude's avatar
MARCHE Claude committed
234
  c.controller_env <- Env.create_env (Env.get_loadpath c.controller_env);
MARCHE Claude's avatar
MARCHE Claude committed
235 236
  Whyconf.Hprover.reset c.controller_provers;
  load_drivers c;
237
  c.controller_session <- empty_session ~from:old_ses (get_dir old_ses);
238
  merge_files ~shape_version c.controller_env c.controller_session old_ses
239 240 241

exception Errors_list of exn list

242 243
let reload_files (c: controller) ~shape_version =
  let errors, b1, b2 = reload_files c ~shape_version in
244 245 246
  match errors with
  | [] -> b1, b2
  | _ -> raise (Errors_list errors)
247 248

let add_file c ?format fname =
249 250 251
  let file_is_detached,theories,errors =
    try false,(Session_itp.read_file c.controller_env ?format fname), None
    with e -> true,[], Some e
252
  in
253
  let (_ : file) = add_file_section c.controller_session fname ~file_is_detached theories format in
254
  errors
255

256 257 258 259 260
let add_file c ?format fname =
  let errors = add_file c ?format fname in
  match errors with
  | None -> ()
  | Some error -> raise (Errors_list [error])
261 262

module type Scheduler = sig
263
  val blocking: bool
264
  val multiplier: int
265 266 267 268
  val timeout: ms:int -> (unit -> bool) -> unit
  val idle: prio:int -> (unit -> bool) -> unit
end

269 270
module Make(S : Scheduler) = struct

Sylvain Dailler's avatar
Sylvain Dailler committed
271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294
(* type for scheduled proof attempts *)
type sched_pa_rec =
  { spa_contr    : controller;
    spa_id       : proofNodeID;
    spa_pr       : Whyconf.prover;
    spa_limit    : Call_provers.resource_limit;
    spa_pr_scr   : string option;
    spa_callback : (proof_attempt_status -> unit);
    spa_ores     : Call_provers.prover_result option;
  }

let scheduled_proof_attempts : sched_pa_rec Queue.t = Queue.create ()

(* type for prover tasks in progress *)
type tasks_prog_rec =
  {
    tp_session  : Session_itp.session;
    tp_id       : proofNodeID;
    tp_pr       : Whyconf.prover;
    tp_callback : (proof_attempt_status -> unit);
    tp_started  : bool;
    tp_call     : Call_provers.prover_call;
    tp_ores     : Call_provers.prover_result option;
  }
MARCHE Claude's avatar
MARCHE Claude committed
295

Sylvain Dailler's avatar
Sylvain Dailler committed
296 297 298
let prover_tasks_in_progress :
    (Call_provers.prover_call,tasks_prog_rec) Hashtbl.t =
  Hashtbl.create 17
299 300 301 302 303

(* We need to separate tasks that are edited from proofattempt in progress
   because we are not using why3server for the edited proofs and timeout_handler
   rely on a loop on why3server's results. *)
let prover_tasks_edited = Queue.create ()
MARCHE Claude's avatar
MARCHE Claude committed
304 305 306

let timeout_handler_running = ref false

307

MARCHE Claude's avatar
MARCHE Claude committed
308
let number_of_running_provers = ref 0
309

310 311 312 313
let observer = ref (fun _ _ _ -> ())

let register_observer = (:=) observer

314
module Hprover = Whyconf.Hprover
MARCHE Claude's avatar
MARCHE Claude committed
315

Sylvain Dailler's avatar
Sylvain Dailler committed
316
(* calling provers, with limits adaptation *)
317 318 319 320 321 322 323 324 325 326


(* to avoid corner cases when prover results are obtained very closely
   to the time or mem limits, we adapt these limits when we replay a
   proof *)

let adapt_limits ~interactive ~use_steps limits a =
  let t, m, s =
    let timelimit = limits.Call_provers.limit_time in
    let memlimit = limits.Call_provers.limit_mem in
327
    let steplimit = limits.Call_provers.limit_steps in
328 329 330 331 332 333 334
    match a.proof_state with
    | Some { Call_provers.pr_answer = r;
             Call_provers.pr_time = t;
             Call_provers.pr_steps = s } ->
       (* increased time limit is 1 + twice the previous running time,
       but enforced to remain inside the interval [l,2l] where l is
       the previous time limit *)
335
       let t = truncate (1.5 +. 2.0 *. t) in
336
       let increased_time = if interactive then 0
337 338 339 340 341
                            else max timelimit (min t (2 * timelimit)) in
       (* increased mem limit is just 1.5 times the previous mem limit *)
       let increased_mem = if interactive then 0 else 3 * memlimit / 2 in
       begin
         match r with
342 343
         | Call_provers.OutOfMemory -> increased_time, memlimit, steplimit
         | Call_provers.Timeout -> timelimit, increased_mem, steplimit
344 345
         | Call_provers.Valid ->
            let steplimit =
346 347 348 349 350 351 352 353 354
              if use_steps && not a.proof_obsolete then
                (* We need to allow at least one more step than what was used to
                   prove the same statement. Otherwise, the prover run out of
                   steps: this happens with cvc4 on some very fast proofs
                   (steps = 28).
                *)
                s + 1
              else
                0
355 356 357 358
            in
            increased_time, increased_mem, steplimit
         | Call_provers.Unknown _
         | Call_provers.StepLimitExceeded
359
         | Call_provers.Invalid -> increased_time, increased_mem, steplimit
360 361 362
         | Call_provers.Failure _
         | Call_provers.HighFailure ->
            (* correct ? failures are supposed to appear quickly anyway... *)
363
            timelimit, memlimit, steplimit
364 365
       end
    | None when interactive -> 0, 0, 0
366
    | None -> timelimit, memlimit, steplimit
367 368 369 370 371 372 373 374 375 376 377 378 379 380 381
  in
  { Call_provers.limit_time = t; limit_mem = m; limit_steps = s }

let group_answer a =
  match a with
  | Call_provers.OutOfMemory
  | Call_provers.Unknown _
  | Call_provers.Timeout -> Call_provers.Timeout
  | _ -> a

let fuzzy_proof_time nres ores =
  let ansold = ores.Call_provers.pr_answer in
  let told = ores.Call_provers.pr_time in
  let ansnew = nres.Call_provers.pr_answer in
  let tnew = nres.Call_provers.pr_time in
382
  if ansnew <> Call_provers.Timeout && group_answer ansold = group_answer ansnew &&
383 384 385 386 387
       tnew >= told *. 0.9 -. 0.1 && tnew <= told *. 1.1 +. 0.1
  then { nres with Call_provers.pr_time = told }
  else nres


Sylvain Dailler's avatar
Sylvain Dailler committed
388 389 390 391 392 393
let build_prover_call spa =
  let c = spa.spa_contr in
  let limit = spa.spa_limit in
  let (config_pr,driver) = Hprover.find c.controller_provers spa.spa_pr in
  let with_steps =
    Call_provers.(limit.limit_steps <> empty_limit.limit_steps) in
394
  let command =
395
    Whyconf.get_complete_command config_pr ~with_steps in
396
  try
Sylvain Dailler's avatar
Sylvain Dailler committed
397
    let task = Session_itp.get_task c.controller_session spa.spa_id in
398
    Debug.dprintf debug_sched "[build_prover_call] Script file = %a@."
Sylvain Dailler's avatar
Sylvain Dailler committed
399
                  (Pp.print_option Pp.string) spa.spa_pr_scr;
400
    let inplace = config_pr.Whyconf.in_place in
401
    let interactive = config_pr.Whyconf.interactive in
402 403
    try
      let call =
Sylvain Dailler's avatar
Sylvain Dailler committed
404 405
        Driver.prove_task ?old:spa.spa_pr_scr ~inplace ~command
                        ~limit ~interactive driver task
406
      in
Sylvain Dailler's avatar
Sylvain Dailler committed
407 408 409 410 411 412 413 414
      let pa =
        { tp_session  = c.controller_session;
          tp_id       = spa.spa_id;
          tp_pr       = spa.spa_pr;
          tp_callback = spa.spa_callback;
          tp_started  = false;
          tp_call     = call;
          tp_ores     = spa.spa_ores } in
415 416
      Hashtbl.replace prover_tasks_in_progress call pa
    with Sys_error _ as e ->
Sylvain Dailler's avatar
Sylvain Dailler committed
417
      spa.spa_callback (InternalFailure e)
418
  with Not_found (* goal has no task, it is detached *) ->
Sylvain Dailler's avatar
Sylvain Dailler committed
419
       spa.spa_callback Detached
MARCHE Claude's avatar
MARCHE Claude committed
420

421 422
let update_observer () =
  let scheduled = Queue.length scheduled_proof_attempts in
423
  let waiting_or_running = Hashtbl.length prover_tasks_in_progress in
424 425 426
  let running = !number_of_running_provers in
  !observer scheduled (waiting_or_running - running) running

MARCHE Claude's avatar
MARCHE Claude committed
427 428
let timeout_handler () =
  (* examine all the prover tasks in progress *)
429 430 431
  (* When no tasks are there, probably no tasks were scheduled and the server
     was not launched so getting results could fail. *)
  if Hashtbl.length prover_tasks_in_progress != 0 then begin
432
    let results = Call_provers.get_new_results ~blocking:S.blocking in
433 434
    List.iter (fun (call, prover_update) ->
      match Hashtbl.find prover_tasks_in_progress call with
Sylvain Dailler's avatar
Sylvain Dailler committed
435
      | ptp ->
436
        begin match prover_update with
437 438
        | Call_provers.NoUpdates -> ()
        | Call_provers.ProverStarted ->
Sylvain Dailler's avatar
Sylvain Dailler committed
439 440
            assert (not ptp.tp_started);
            ptp.tp_callback Running;
441
            incr number_of_running_provers;
Sylvain Dailler's avatar
Sylvain Dailler committed
442 443
            Hashtbl.replace prover_tasks_in_progress ptp.tp_call
              {ptp with tp_started = true}
444
        | Call_provers.ProverFinished res ->
Sylvain Dailler's avatar
Sylvain Dailler committed
445 446 447
            Hashtbl.remove prover_tasks_in_progress ptp.tp_call;
            if ptp.tp_started then decr number_of_running_provers;
            let res = Opt.fold fuzzy_proof_time res ptp.tp_ores in
448
            (* inform the callback *)
Sylvain Dailler's avatar
Sylvain Dailler committed
449
            ptp.tp_callback (Done res)
450
        | Call_provers.ProverInterrupted ->
Sylvain Dailler's avatar
Sylvain Dailler committed
451 452
            Hashtbl.remove prover_tasks_in_progress ptp.tp_call;
            if ptp.tp_started then decr number_of_running_provers;
453
            (* inform the callback *)
Sylvain Dailler's avatar
Sylvain Dailler committed
454
            ptp.tp_callback (Interrupted)
455
        | Call_provers.InternalFailure exn ->
Sylvain Dailler's avatar
Sylvain Dailler committed
456 457
            Hashtbl.remove prover_tasks_in_progress ptp.tp_call;
            if ptp.tp_started then decr number_of_running_provers;
458
            (* inform the callback *)
Sylvain Dailler's avatar
Sylvain Dailler committed
459
            ptp.tp_callback (InternalFailure (exn))
460 461 462 463 464 465
        end
      | exception Not_found -> ()
        (* We probably received ProverStarted after ProverFinished,
           because what is sent to and received from the server is
           not ordered. *)
    ) results;
466 467
  end;

468 469 470 471 472 473 474
  (* When blocking is activated, we are in script mode and we don't want editors
     to be launched so we don't need to go in this loop. *)
  if not S.blocking then begin
    (* Check for editor calls which are not finished *)
    let q = Queue.create () in
    while not (Queue.is_empty prover_tasks_edited) do
      (* call is an EditorCall *)
475
      let (callback,call,ores) as c =
476 477 478 479
        Queue.pop prover_tasks_edited in
      let prover_update = Call_provers.query_call call in
      match prover_update with
      | Call_provers.NoUpdates -> Queue.add c q
480
      | Call_provers.ProverFinished res ->
481 482
          (* res is meaningless for edition, we returned the old result *)
          (* inform the callback *)
483
          callback (match ores with None -> Done res | Some r -> Done r)
484 485 486 487
      | _ -> assert (false) (* An edition can only return Noupdates or finished *)
    done;
    Queue.transfer q prover_tasks_edited;
  end;
488 489

  (* if the number of prover tasks is less than S.multiplier times the maximum
MARCHE Claude's avatar
MARCHE Claude committed
490 491
     number of running provers, then we heuristically decide to add
     more tasks *)
492 493
  begin
    try
494
      for _i = Hashtbl.length prover_tasks_in_progress
495
          to S.multiplier * !session_max_tasks do
Sylvain Dailler's avatar
Sylvain Dailler committed
496 497
        let spa = Queue.pop scheduled_proof_attempts in
        try build_prover_call spa
498
        with e when not (Debug.test_flag Debug.stack_trace) ->
Sylvain Dailler's avatar
Sylvain Dailler committed
499
          spa.spa_callback (InternalFailure e)
500 501 502
      done
  with Queue.Empty -> ()
  end;
503
  update_observer ();
504
  true
MARCHE Claude's avatar
MARCHE Claude committed
505

506
let interrupt () =
507
  (* Interrupt provers *)
Sylvain Dailler's avatar
Sylvain Dailler committed
508
  Hashtbl.iter (fun _k e -> e.tp_callback Interrupted)
509 510 511 512
    prover_tasks_in_progress;
  Hashtbl.clear prover_tasks_in_progress;
  (* Do not interrupt editors
  while not (Queue.is_empty prover_tasks_edited) do
513
    let (_ses,_id,_pr,callback,_started,_call,_ores) =
514
      Queue.pop prover_tasks_edited in
515 516
    callback Interrupted
  done;
517
  *)
518 519
  number_of_running_provers := 0;
  while not (Queue.is_empty scheduled_proof_attempts) do
Sylvain Dailler's avatar
Sylvain Dailler committed
520 521
    let spa = Queue.pop scheduled_proof_attempts in
    spa.spa_callback Interrupted
522 523 524
  done;
  !observer 0 0 0

MARCHE Claude's avatar
MARCHE Claude committed
525 526 527 528
let run_timeout_handler () =
  if not !timeout_handler_running then
    begin
      timeout_handler_running := true;
529
      S.timeout ~ms:default_delay_ms timeout_handler;
MARCHE Claude's avatar
MARCHE Claude committed
530 531
    end

532
let schedule_proof_attempt c id pr ?save_to ~limit ~callback ~notification =
533 534
  let ses = c.controller_session in
  let callback panid s =
535 536
    begin
      match s with
537
      | UpgradeProver _ | Removed _ -> ()
538 539 540 541 542 543 544 545
      | Scheduled ->
         Hpan.add c.controller_running_proof_attempts panid ();
         update_goal_node notification ses id
      | Running -> update_goal_node notification ses id
      | Done res ->
         Hpan.remove c.controller_running_proof_attempts panid;
         update_proof_attempt ~obsolete:false notification ses id pr res;
         update_goal_node notification ses id
546 547
      | Interrupted
      | InternalFailure _ ->
548 549 550 551 552
         Hpan.remove c.controller_running_proof_attempts panid;
         (* what to do ?
         update_proof_attempt ~obsolete:false notification ses id pr res;
          *)
         update_goal_node notification ses id
553 554
      | Detached -> assert false
      | Uninstalled _ -> assert false
555
      | Undone -> assert false
556
    end;
557 558 559
    callback panid s
  in
  let adaptlimit,ores,proof_script =
560
    try
561
      let h = get_proof_attempt_ids ses id in
562
      let pa = Hprover.find h pr in
563
      let a = get_proof_attempt_node ses pa in
564 565 566 567 568
      let old_res = a.proof_state in
      let config_pr,_ = Hprover.find c.controller_provers pr in
      let interactive = config_pr.Whyconf.interactive in
      let use_steps = Call_provers.(limit.limit_steps <> empty_limit.limit_steps) in
      let limit = adapt_limits ~interactive ~use_steps limit a in
569 570 571
      let script =
        if save_to = None then
          Opt.map (fun s ->
572 573
                            Debug.dprintf debug_sched "Script file = %s@." s;
                            Filename.concat (get_dir ses) s) a.proof_script
574 575
        else
          save_to
576 577
      in
      limit, old_res, script
578
    with Not_found | Session_itp.BadID -> limit,None,save_to
579
  in
580
  let panid = graft_proof_attempt ~limit ses id pr in
Sylvain Dailler's avatar
Sylvain Dailler committed
581 582 583 584 585 586 587 588 589
  let spa =
    { spa_contr    = c;
      spa_id       = id;
      spa_pr       = pr;
      spa_limit    = adaptlimit;
      spa_pr_scr   = proof_script;
      spa_callback = callback panid;
      spa_ores     = ores } in
  Queue.add spa scheduled_proof_attempts;
590
  callback panid Scheduled;
MARCHE Claude's avatar
MARCHE Claude committed
591
  run_timeout_handler ()
Clément Fumex's avatar
Clément Fumex committed
592

593

594 595


596 597
(*** { 2 edition of proof scripts} *)

Sylvain Dailler's avatar
Sylvain Dailler committed
598 599 600
(* create the path to a file for saving the external proof script *)
let create_file_rel_path c pr pn =
  let session = c.controller_session in
601
  let driver = snd (Hprover.find c.controller_provers pr) in
602
  let task = Session_itp.get_task session pn in
Sylvain Dailler's avatar
Sylvain Dailler committed
603 604 605 606
  let session_dir = Session_itp.get_dir session in
  let th = get_encapsulating_theory session (APn pn) in
  let th_name = (Session_itp.theory_name th).Ident.id_string in
  let f = get_encapsulating_file session (ATh th) in
607
  let fn = Filename.chop_extension (Filename.basename (file_name f)) in
Sylvain Dailler's avatar
Sylvain Dailler committed
608 609 610 611 612 613
  let file = Driver.file_of_task driver fn th_name task in
  let file = Filename.concat session_dir file in
  let file = Sysutil.uniquify file in
  let file = Sysutil.relativize_filename session_dir file in
  file

614
let prepare_edition c ?file pn pr ~notification =
Sylvain Dailler's avatar
Sylvain Dailler committed
615
  let session = c.controller_session in
616 617 618
  let proof_attempts_id = get_proof_attempt_ids session pn in
  let panid =
    try
619 620 621 622 623 624 625 626 627 628 629 630 631 632
      let panid = Hprover.find proof_attempts_id pr in
      (* if no proof script yet, we need to add one
         it happens e.g when editing a file for an automatic prover
       *)
      let pa = get_proof_attempt_node session panid in
      match pa.proof_script with
      | None ->
         let file = match file with
           | Some f -> f
           | None -> create_file_rel_path c pr pn
         in
         set_proof_script pa file;
         panid
      | Some _ -> panid
633
    with Not_found ->
634 635 636 637
      let file = match file with
        | Some f -> f
        | None -> create_file_rel_path c pr pn
      in
638 639
      let limit = Call_provers.empty_limit in
      graft_proof_attempt session pn pr ~file ~limit
Sylvain Dailler's avatar
Sylvain Dailler committed
640
  in
641
  update_goal_node notification session pn;
642 643
  let pa = get_proof_attempt_node session panid in
  let file = Opt.get pa.proof_script in
644
  let old_res = pa.proof_state in
645
  let session_dir = Session_itp.get_dir session in
Sylvain Dailler's avatar
Sylvain Dailler committed
646 647 648 649 650 651 652 653 654 655 656 657 658 659 660
  let file = Filename.concat session_dir file in
  let old =
    if Sys.file_exists file
    then
      begin
        let backup = file ^ ".bak" in
        if Sys.file_exists backup
        then Sys.remove backup;
        Sys.rename file backup;
        Some(open_in backup)
      end
    else None
  in
  let ch = open_out file in
  let fmt = formatter_of_out_channel ch in
661
  let task = Session_itp.get_task session pn in
662
  let driver = snd (Hprover.find c.controller_provers pr) in
663
  Driver.print_task ?old driver fmt task;
Sylvain Dailler's avatar
Sylvain Dailler committed
664 665
  Opt.iter close_in old;
  close_out ch;
666
  panid,file,old_res
Sylvain Dailler's avatar
Sylvain Dailler committed
667 668 669

exception Editor_not_found

670
let schedule_edition c id pr ~callback ~notification =
Sylvain Dailler's avatar
Sylvain Dailler committed
671 672 673 674
  Debug.dprintf debug_sched "[Sched] Scheduling an edition@.";
  let config = c.controller_config in
  let session = c.controller_session in
  let prover_conf = Whyconf.get_prover_config config pr in
675
  (* Make sure editor exists. Fails otherwise *)
Sylvain Dailler's avatar
Sylvain Dailler committed
676 677
  let editor =
    match prover_conf.Whyconf.editor with
678
    | "" -> Whyconf.(default_editor (get_main config))
Sylvain Dailler's avatar
Sylvain Dailler committed
679
    | s ->
680 681 682 683 684
       try
         let ed = Whyconf.editor_by_id config s in
         String.concat " " (ed.Whyconf.editor_command ::
                              ed.Whyconf.editor_options)
       with Not_found -> raise Editor_not_found
Sylvain Dailler's avatar
Sylvain Dailler committed
685
  in
686
  let panid,file,old_res = prepare_edition c id pr ~notification in
687
  (* Notification node *)
688 689 690
  let callback panid s =
    begin
      match s with
691
      | UpgradeProver _ -> ()
692
      | Running -> ()
693 694
      | Done res ->
         (* set obsolete to true since we do not know if the manual
695
            proof was completed or not *)
696 697 698 699 700
         Debug.dprintf debug_sched
                       "Setting status of %a under parent %a to obsolete@."
                       print_proofAttemptID panid print_proofNodeID id;
         update_proof_attempt ~obsolete:true notification session id pr res;
         update_goal_node notification session id
701 702 703
      | Interrupted
      | InternalFailure _ ->
         update_goal_node notification session id
704
      | Undone | Detached | Uninstalled _ | Scheduled | Removed _ -> assert false
705 706
    end;
    callback panid s
707
  in
Sylvain Dailler's avatar
Sylvain Dailler committed
708
  Debug.dprintf debug_sched "[Editing] goal %s with command '%s' on file %s@."
709 710
                (Session_itp.get_proof_name session id).Ident.id_string
                editor file;
711 712
  let call = Call_provers.call_editor ~command:editor file in
  callback panid Running;
713
  Queue.add (callback panid,call,old_res) prover_tasks_edited;
714
  run_timeout_handler ()
715

716 717
exception TransAlreadyExists of string * string

718 719
(*** { 2 transformations} *)

720 721 722 723 724
let schedule_transformation c id name args ~callback ~notification =
  let callback s =
    begin match s with
          | TSdone tid -> update_trans_node notification c.controller_session tid
          | TSscheduled
Sylvain Dailler's avatar
Sylvain Dailler committed
725
          | TSfailed _ | TSfatal _  -> ()
726 727 728
    end;
    callback s
  in
729
  let apply_trans () =
730 731
    begin
      try
732 733 734
        let subtasks =
          apply_trans_to_goal ~allow_no_effect:false
                              c.controller_session c.controller_env name args id
735
        in
736 737 738
        let tid = graft_transf c.controller_session id name args subtasks in
        callback (TSdone tid)
      with
739
      | NoProgress ->
740
         (* if result is same as input task, consider it as a failure *)
741
         callback (TSfailed (id, NoProgress))
Sylvain Dailler's avatar
Sylvain Dailler committed
742 743 744 745 746 747 748 749
      | (Arg_trans _ | Arg_trans_decl _
        | Arg_trans_term _ | Arg_trans_term2 _
        | Arg_trans_pattern _ | Arg_trans_type _ | Arg_bad_hypothesis _
        | Cannot_infer_type _ | Unnecessary_terms _ | Parse_error _
        | Arg_expected _ | Arg_theory_not_found _ | Arg_expected_none _
        | Arg_qid_not_found _ | Arg_pr_not_found _ | Arg_error _
        | Arg_parse_type_error _ | Unnecessary_arguments _) as e ->
          callback (TSfailed (id, e))
750
      | e when not (Debug.test_flag Debug.stack_trace) ->
751
          (* "@[Exception raised in Session_itp.apply_trans_to_goal %s:@ %a@.@]"
752
          name Exn_printer.exn_printer e; TODO *)
Sylvain Dailler's avatar
Sylvain Dailler committed
753
        callback (TSfatal (id, e))
754 755
    end;
    false
756
  in
757 758
  if Session_itp.check_if_already_exists c.controller_session id name args then
    raise (TransAlreadyExists (name, List.fold_left (fun acc s -> s ^ " " ^ acc) "" args));
759 760
  S.idle ~prio:0 apply_trans;
  callback TSscheduled
Clément Fumex's avatar
Clément Fumex committed
761

762 763 764

open Strategy

Sylvain Dailler's avatar
Sylvain Dailler committed
765
let run_strategy_on_goal
766
    c id strat ~callback_pa ~callback_tr ~callback ~notification =
767 768 769 770 771 772
  let rec exec_strategy pc strat g =
    if pc < 0 || pc >= Array.length strat then
      callback STShalt
    else
      match Array.get strat pc with
      | Icall_prover(p,timelimit,memlimit) ->
MARCHE Claude's avatar
MARCHE Claude committed
773 774
         let callback panid res =
           callback_pa panid res;
775
           match res with
776
           | UpgradeProver _ | Scheduled | Running -> (* nothing to do yet *) ()
777 778 779
           | Done { Call_provers.pr_answer = Call_provers.Valid } ->
              (* proof succeeded, nothing more to do *)
              callback STShalt
780 781
           | Interrupted | InternalFailure _ ->
              callback STShalt
782 783 784 785 786
           | Done _ ->
              (* proof did not succeed, goto to next step *)
              callback (STSgoto (g,pc+1));
              let run_next () = exec_strategy (pc+1) strat g; false in
              S.idle ~prio:0 run_next
787
           | Undone | Detached | Uninstalled _ | Removed _ ->
788 789 790 791 792 793
                         (* should not happen *)
                         assert false
         in
         let limit = { Call_provers.empty_limit with
                       Call_provers.limit_time = timelimit;
                       limit_mem  = memlimit} in
794
         schedule_proof_attempt c g p ?save_to:None ~limit ~callback ~notification
795 796
      | Itransform(trname,pcsuccess) ->
         let callback ntr =
797
           callback_tr trname [] ntr;
798
           match ntr with
Sylvain Dailler's avatar
Sylvain Dailler committed
799 800
           | TSfatal (id, e) ->
               callback (STSfatal (trname, id, e))
801
           | TSfailed _e -> (* transformation failed *)
802 803 804 805 806 807 808 809 810 811 812 813
              callback (STSgoto (g,pc+1));
              let run_next () = exec_strategy (pc+1) strat g; false in
              S.idle ~prio:0 run_next
           | TSscheduled -> ()
           | TSdone tid ->
              List.iter
                (fun g ->
                 callback (STSgoto (g,pcsuccess));
                 let run_next () =
                   exec_strategy pcsuccess strat g; false
                 in
                 S.idle ~prio:0 run_next)
MARCHE Claude's avatar
MARCHE Claude committed
814
                (get_sub_tasks c.controller_session tid)
815
         in
816
         schedule_transformation c g trname [] ~callback ~notification
817 818 819 820 821 822
      | Igoto pc ->
         callback (STSgoto (g,pc));
         exec_strategy pc strat g
  in
  exec_strategy 0 strat id

Sylvain Dailler's avatar
Sylvain Dailler committed
823 824
let schedule_pa_with_same_arguments
    c (pa: proof_attempt_node) (pn: proofNodeID) ~callback ~notification =
Sylvain Dailler's avatar
Sylvain Dailler committed
825 826 827 828
  let prover = pa.prover in
  let limit = pa.limit in
  schedule_proof_attempt c pn prover ~limit ~callback ~notification

Sylvain Dailler's avatar
Sylvain Dailler committed
829 830
let schedule_tr_with_same_arguments
    c (tr: transID) (pn: proofNodeID) ~callback ~notification =
Sylvain Dailler's avatar
Sylvain Dailler committed
831 832 833
  let s = c.controller_session in
  let args = get_transf_args s tr in
  let name = get_transf_name s tr in
834
  let callback = callback name args in
835

Sylvain Dailler's avatar
Sylvain Dailler committed
836 837
  schedule_transformation c pn name args ~callback ~notification

MARCHE Claude's avatar
MARCHE Claude committed
838 839 840 841 842
let proof_is_complete pa =
  match pa.Session_itp.proof_state with
  | None -> false
  | Some pr ->
     not pa.Session_itp.proof_obsolete &&
843
       Call_provers.(pr.pr_answer = Valid)
MARCHE Claude's avatar
MARCHE Claude committed
844

845

Sylvain Dailler's avatar
Sylvain Dailler committed
846
let clean c ~removed nid =
847

848
  (* clean should not change proved status *)
849 850 851
  let notification any =
    Format.eprintf "Cleaning error: cleaning attempts to change status of node %a@." fprintf_any any
  in
852
  let s = c.controller_session in
853
  (* This function is applied on leafs first for the case of removes *)
854
  let clean_aux () any =
855 856 857 858 859 860
    let do_remove =
      Session_itp.is_detached s any ||
      match any with
      | APa pa ->
         let pa = Session_itp.get_proof_attempt_node s pa in
         pn_proved s pa.parent && not (proof_is_complete pa)
861
      | ATn tn ->
862 863 864 865 866 867
         let pn = get_trans_parent s tn in
         pn_proved s pn && not (tn_proved s tn)
      | _ -> false
    in
    if do_remove then
      remove_subtree ~notification ~removed c any
868 869 870 871 872 873 874
  in

  match nid with
  | Some nid ->
      Session_itp.fold_all_any s clean_aux () nid
  | None ->
      Session_itp.fold_all_session s clean_aux ()
875

876 877
(* This function folds on any subelements of given node and tries to mark all
   proof attempts it encounters *)
878
let mark_as_obsolete ~notification c any =
879
  let s = c.controller_session in
880
  (* Case for proof attempt only *)
881
  let mark_as_obsolete_pa n =
882 883
    let parent = get_proof_attempt_parent s n in
    Session_itp.mark_obsolete s n;
884
    notification (APa n);
885
    update_goal_node notification s parent
886
  in
887 888 889 890 891 892 893 894 895 896
  match any with
  | Some any ->
      fold_all_any s
        (fun () any -> match any with
        | APa n -> mark_as_obsolete_pa n
        | _ -> ()) () any
  | None ->
      session_iter_proof_attempt
        (fun pa _pan ->
          mark_as_obsolete_pa pa) s
897

Sylvain Dailler's avatar
Sylvain Dailler committed
898 899 900
exception BadCopyPaste

(* Reproduce the transformation made on node on an other one *)
901
let rec copy_rec ~notification ~callback_pa ~callback_tr c from_any to_any =
Sylvain Dailler's avatar
Sylvain Dailler committed
902
  let s = c.controller_session in
903 904
  match from_any, to_any with
(*
Sylvain Dailler's avatar
Sylvain Dailler committed
905 906 907 908
    | AFile _, AFile _ ->
        raise BadCopyPaste
    | ATh _from_th, ATh _to_th ->
        raise BadCopyPaste
909
 *)
Sylvain Dailler's avatar
Sylvain Dailler committed
910 911
    | APn from_pn, APn to_pn ->
      let from_pa_list = get_proof_attempts s from_pn in
912
      List.iter (fun x -> schedule_pa_with_same_arguments ?save_to:None c x to_pn
Sylvain Dailler's avatar
Sylvain Dailler committed
913 914
          ~callback:callback_pa ~notification) from_pa_list;
      let from_tr_list = get_transformations s from_pn in
915
      let callback x tr args st = callback_tr tr args st;
Sylvain Dailler's avatar
Sylvain Dailler committed
916
        match st with
Sylvain Dailler's avatar
Sylvain Dailler committed
917
        | TSdone tid ->
918
          copy_rec c (ATn x) (ATn tid) ~notification ~callback_pa ~callback_tr
Sylvain Dailler's avatar
Sylvain Dailler committed
919 920 921 922 923 924 925
        | _ -> ()
      in
      List.iter (fun x -> schedule_tr_with_same_arguments c x to_pn
          ~callback:(callback x) ~notification) from_tr_list
    | ATn from_tn, ATn to_tn ->
        let from_tn_list = get_sub_tasks s from_tn in
        let to_tn_list = get_sub_tasks s to_tn in
926 927 928 929 930 931 932 933
        let rec iter_copy l1 l2 =
          match l1,l2 with
          | x::r1, y::r2 ->
             copy_rec c (APn x) (APn y)
                      ~notification ~callback_pa ~callback_tr;
             iter_copy r1 r2
          | _ -> ()
        in iter_copy from_tn_list to_tn_list
Sylvain Dailler's avatar
Sylvain Dailler committed
934 935 936
    | _ -> raise BadCopyPaste


937 938
let copy_paste ~notification ~callback_pa ~callback_tr c from_any to_any =
  let s = c.controller_session in
939 940
  if is_below s to_any from_any then
    raise BadCopyPaste;
941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956
  match from_any, to_any with
  | APn _, APn _ ->
     copy_rec ~notification ~callback_pa ~callback_tr c from_any to_any
  | ATn from_tn, APn to_pn ->
     let callback tr args st =
       callback_tr tr args st;
       match st with
       | TSdone tid ->
          copy_rec c (ATn from_tn) (ATn tid) ~notification ~callback_pa ~callback_tr
       | _ -> ()
     in
     schedule_tr_with_same_arguments c from_tn to_pn ~callback ~notification
  | _ -> raise BadCopyPaste



MARCHE Claude's avatar
MARCHE Claude committed
957 958 959 960 961 962 963 964





(***************** {2 replay} ****************)


965
let debug_replay = Debug.register_flag "replay" ~desc:"Debug@ info@ for@ replay"
MARCHE Claude's avatar
MARCHE Claude committed
966

967
let find_prover notification c goal_id pr =
968
  if Hprover.mem c.controller_provers pr then `Found pr else
969
   match Whyconf.get_prover_upgrade_policy c.controller_config pr with
970 971
   | exception Not_found -> `Keep
   | Whyconf.CPU_keep -> `Keep
972
   | Whyconf.CPU_remove -> `Remove
973 974 975
   | Whyconf.CPU_upgrade new_pr ->
      (* does a proof using new_pr already exists ? *)
      if Hprover.mem (get_proof_attempt_ids c.controller_session goal_id) new_pr
976
      then (* yes, then we remove the attempt *)
977
        `Remove
978 979 980 981
      else
        begin
          (* we modify the prover in-place *)
          Session_itp.change_prover notification c.controller_session goal_id pr new_pr;
982
          `Found new_pr
983
        end
984 985 986
   | Whyconf.CPU_duplicate new_pr ->
      (* does a proof using new_pr already exists ? *)
      if Hprover.mem (get_proof_attempt_ids c.controller_session goal_id) new_pr
987
      then (* yes, then we do nothing *)
988
        `Keep
989 990
      else
        begin
991 992
          (* we duplicate the proof attempt *)
          `Found new_pr
993
        end
994

995 996 997 998 999

let replay_proof_attempt c pr limit (parid: proofNodeID) id ~callback ~notification =
  (* The replay can be done on a different machine so we need
     to check more things before giving the attempt to the scheduler *)
  match find_prover notification c parid pr with
1000 1001
  | `Keep -> callback id (Uninstalled pr)
  | `Remove ->
1002 1003 1004
     (* it is necessary to call the callback before effectively removing the node, otherwise, a bad id will be used in the callback *)
      callback id (Removed pr);
      remove_proof_attempt c.controller_session parid pr
1005
  | `Found pr' ->
1006 1007
     try
       if pr' <> pr then callback id (UpgradeProver pr');
1008
       let _ = get_task c.controller_session parid in
1009
       schedule_proof_attempt ?save_to:None c parid pr' ~limit ~callback ~notification
1010 1011 1012 1013 1014
     with Not_found ->
       callback id Detached



1015 1016 1017 1018
type report =
  | Result of Call_provers.prover_result * Call_provers.prover_result
  (** Result(new_result,old_result) *)
  | CallFailed of exn
1019
  | Replay_interrupted
1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030
  | Prover_not_installed
  | Edited_file_absent of string
  | No_former_result of Call_provers.prover_result

(* TODO find a better way to print it *)
let print_report fmt (r: report) =
  match r with
  | Result (new_r, old_r) ->
    Format.fprintf fmt "new_result = %a, old_result = %a@."
      Call_provers.print_prover_result new_r
      Call_provers.print_prover_result old_r
1031 1032 1033 1034
  | CallFailed e ->
    Format.fprintf fmt "Callfailed %a@." Exn_printer.exn_printer e
  | Replay_interrupted ->
    Format.fprintf fmt "Interrupted@."
1035 1036 1037 1038 1039 1040 1041 1042 1043
  | Prover_not_installed ->
    Format.fprintf fmt "Prover not installed@."
  | Edited_file_absent _ ->
    Format.fprintf fmt "No edited file@."
  | No_former_result new_r ->
    Format.fprintf fmt "new_result = %a, no former result@."
      Call_provers.print_prover_result new_r

(* TODO to be removed when we have a better way to print *)
1044
let replay_print fmt (lr: (proofNodeID * Whyconf.prover * Call_provers.resource_limit * report) list) =
1045 1046
  let pp_elem fmt (id, pr, rl, report) =
    fprintf fmt "ProofNodeID: %d, Prover: %a, Timelimit?: %d, Result: %a@."
Sylvain Dailler's avatar
Sylvain Dailler committed
1047 1048
      (Obj.magic id) Whyconf.print_prover pr
      rl.Call_provers.limit_time print_report report
1049
  in
1050
  Format.fprintf fmt "%a@." (Pp.print_list Pp.newline pp_elem) lr
1051

1052
let replay ~valid_only ~obsolete_only ?(use_steps=false) ?(filter=fun _ -> true)
Sylvain Dailler's avatar
Sylvain Dailler committed
1053
           c ~callback ~notification ~final_callback ~any =
1054

1055 1056 1057 1058 1059
  let session = c.controller_session in
  let count = ref 0 in
  let report = ref [] in
  let found_upgraded_prover = ref false in

1060 1061
  let craft_report s id limits pa =
    let pr = pa.Session_itp.prover in
1062
    match s with
1063 1064 1065 1066
    | UpgradeProver _ -> found_upgraded_prover := true
    | Removed _ ->
       found_upgraded_prover := true;
       decr count
MARCHE Claude's avatar