session.mli 12.6 KB
Newer Older
François Bobot's avatar
François Bobot committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
(**************************************************************************)
(*                                                                        *)
(*  Copyright (C) 2010-2011                                               *)
(*    François Bobot                                                      *)
(*    Jean-Christophe Filliâtre                                           *)
(*    Claude Marché                                                       *)
(*    Andrei Paskevich                                                    *)
(*                                                                        *)
(*  This software is free software; you can redistribute it and/or        *)
(*  modify it under the terms of the GNU Library General Public           *)
(*  License version 2.1, with the special exception on linking            *)
(*  described in file LICENSE.                                            *)
(*                                                                        *)
(*  This software is distributed in the hope that it will be useful,      *)
(*  but WITHOUT ANY WARRANTY; without even the implied warranty of        *)
(*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                  *)
(*                                                                        *)
(**************************************************************************)

(** Proof sessions *)
François Bobot's avatar
François Bobot committed
21
(** Define all the function needed for managing a session :
François Bobot's avatar
François Bobot committed
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
    Creation, saving, loading, modification, ...
    All the operation are immediately done.
    Use session_scheduler if you want to queue the operations
*)

val debug : Debug.flag
(** The debug flag "session" *)

module PHstr : Util.PrivateHashtbl with type key = string
(** {2 Prover's data} *)

type prover = private
    { prover_id : string;
      prover_name : string;
      prover_version : string;
    }
    (** record of necessary data for a given external prover
        In the future prover_id will disappear.
    *)

val print_prover : Format.formatter -> prover -> unit
(** Printer for prover *)

module Mprover  : Stdlib.Map.S with type key = prover
module Sprover  : Mprover.Set
module PHprover : Util.PrivateHashtbl with type key = prover

(** {2 Proof attempts} *)

(** State of proof without result *)
type undone_proof =
    | Scheduled (** external proof attempt is scheduled *)
    | Interrupted (** external proof has been interrupted or
                      has never been scheduled*)
    | Running (** external proof attempt is in progress *)
    | Unedited (** unedited but editable *)

(** State of a proof *)
type proof_attempt_status =
    | Undone of undone_proof
    | Done of Call_provers.prover_result (** external proof done *)
    | InternalFailure of exn (** external proof aborted by internal error *)

François Bobot's avatar
François Bobot committed
65
type expl
François Bobot's avatar
François Bobot committed
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
(** An explanation gives hint about how the goal has been produced.
    Allow to reattach proof_attempt to goal when the source file has been
    modified.
*)

type task_option
(** Currently just an option on a task, but later perhaps
    we should be able to release a task and rebuild it when needed *)

(** {2 Session} *)

(** All the element of a session contain a key which can hold whatever
    information the user want. It is generated by the keygen argument
    of the functions of this module *)

type 'a goal = private
    { mutable goal_key  : 'a;
      goal_name : Ident.ident; (** The ident of the task *)
      goal_expl : expl;
      goal_parent : 'a goal_parent;
      goal_checksum : string;  (** checksum of the task *)
      goal_shape : string;     (** shape are produced by the module Termcode *)
      mutable goal_verified : bool;
      goal_task: task_option;
      mutable goal_expanded : bool;
      goal_external_proofs : 'a proof_attempt PHprover.t;
      goal_transformations : 'a transf PHstr.t;
    }

and 'a proof_attempt = private
    { proof_key : 'a;
      proof_prover : prover;
      proof_parent : 'a goal;
      mutable proof_state : proof_attempt_status;
      mutable proof_timelimit : int;
      mutable proof_obsolete : bool;
      mutable proof_edited_as : string option;
    }

and 'a goal_parent = private
                     | Parent_theory of 'a theory
                     | Parent_transf of 'a transf

and 'a transf = private
    { mutable transf_key : 'a;
      transf_name : string;
      (** Why3 tranformation name *)
      transf_parent : 'a goal;
      mutable transf_verified : bool;
      mutable transf_goals : 'a goal list;
      (** Not mutated after the creation *)
      mutable transf_expanded : bool;
    }

and 'a theory = private
    { mutable theory_key : 'a;
      theory_name : Ident.ident;
      theory_parent : 'a file;
      mutable theory_goals : 'a goal list;
      (** Not mutated after the creation *)
      mutable theory_verified : bool;
      mutable theory_expanded : bool;
    }

and 'a file = private
    { mutable file_key : 'a;
      file_name : string;
      file_parent : 'a session;
      mutable file_theories: 'a theory list;
      (** Not mutated after the creation *)
      mutable file_verified : bool;
      mutable file_expanded : bool;
    }

and 'a session = private
    { session_files : 'a file PHstr.t;
      session_dir   : string;
    }

val print_session : Format.formatter -> 'a session -> unit
(** Print a session with a pstree format (cf Tree module) *)

val create_session : string -> 'key session
(** create a new_session in the given directory. The directory is
    created if it doesn't exists yet. Don't change the current
    directory of the program if you give a relative path *)

val get_project_dir : string -> string
(** find the session which correspond to the given file or return
    directly the given directory;
    return {Not_found} if the file or the directory doesn't exists
*)

type notask
(** A phantom type which is used for session which doesn't contain task. The
    only session that can not contain task are session that come from the
    following function *)

val read_session : string -> notask session
François Bobot's avatar
François Bobot committed
165
(** Read a session stored on the disk. It returns a session without any
François Bobot's avatar
François Bobot committed
166 167 168
    task attached to goals *)

val save_session : 'key session -> unit
François Bobot's avatar
François Bobot committed
169
(** Save a session on disk *)
François Bobot's avatar
François Bobot committed
170

François Bobot's avatar
François Bobot committed
171
(** {2 Context of a session} *)
François Bobot's avatar
François Bobot committed
172 173

(** A session which contains task and proof_attempt depends on an
François Bobot's avatar
François Bobot committed
174
    environment and a prover configuration.
François Bobot's avatar
François Bobot committed
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197
    Loaded provers are cached in order to load drivers once *)

type loaded_prover =
    { prover_config : Whyconf.config_prover;
      prover_driver : Driver.driver}

type loaded_provers = loaded_prover option PHstr.t

type 'a env_session = private
    { env : Env.env;
      whyconf : Whyconf.config;
      loaded_provers : loaded_provers;
      session : 'a session}

val load_prover : 'a env_session -> prover -> loaded_prover option
(** load a prover *)

val is_prover_known : 'a env_session -> prover -> bool
(** test if a prover is detected *)

val get_known_provers : 'a env_session -> Sprover.t
(** get the set of known provers *)

François Bobot's avatar
François Bobot committed
198 199 200 201 202 203 204 205 206 207 208
(** {2 Update session} *)

type 'key keygen = ?parent:'key -> unit -> 'key
(** type of functions which can generate keys *)

exception OutdatedSession

val update_session : keygen:'a keygen ->
  allow_obsolete:bool -> 'b session ->
  Env.env -> Whyconf.config -> 'a env_session * bool
(** reload the given session with the given environnement :
François Bobot's avatar
François Bobot committed
209
    - the files are reloaded
François Bobot's avatar
François Bobot committed
210
    - apply again the transformation
François Bobot's avatar
François Bobot committed
211
    - if some goals appear try to find to which goal
François Bobot's avatar
François Bobot committed
212 213 214
    in the given session it corresponds.

    The last case meant that the session was obsolete.
François Bobot's avatar
François Bobot committed
215
    It is authorized if [allow_obsolete] is [true],
François Bobot's avatar
François Bobot committed
216 217 218 219 220 221 222 223 224 225
    otherwise the exception [OutdatedSession] is raised.
    If the session was obsolete is indicated by
    the second result.

    raises [Failure msg] if the database file cannot be read correctly

*)

(** {2 Accessor} *)

François Bobot's avatar
François Bobot committed
226 227
exception NoTask
val goal_task : 'key goal -> Task.task
François Bobot's avatar
François Bobot committed
228
(** Return the task of a goal. Raise NoTask if the goal doesn't contain a task
François Bobot's avatar
François Bobot committed
229 230 231
    (equivalent to 'key = notask) *)

val goal_task_option : 'key goal -> Task.task option
François Bobot's avatar
François Bobot committed
232
(** Return the task of a goal. *)
François Bobot's avatar
François Bobot committed
233 234

val goal_expl : 'key goal -> string
François Bobot's avatar
François Bobot committed
235
(** Return the explication of a goal *)
François Bobot's avatar
François Bobot committed
236 237

val proof_verified : 'key proof_attempt -> bool
François Bobot's avatar
François Bobot committed
238 239 240 241 242
(** Return true if the proof is not obsolete and the result is valid *)


val get_provers : 'a session -> Sprover.t
(** Get the set of provers which appear in the session *)
François Bobot's avatar
François Bobot committed
243

François Bobot's avatar
François Bobot committed
244
(** {2 Modificator} *)
François Bobot's avatar
François Bobot committed
245 246 247 248 249 250 251

val set_transf_expanded : 'key transf -> bool -> unit
val set_goal_expanded : 'key goal -> bool -> unit
val set_theory_expanded : 'key theory -> bool -> unit
val set_file_expanded : 'key file -> bool -> unit
(** open one level or close all the sub-level *)

François Bobot's avatar
François Bobot committed
252
(** {2 General type} *)
François Bobot's avatar
François Bobot committed
253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298

type 'a any =
  | File of 'a file
  | Theory of 'a theory
  | Goal of 'a goal
  | Proof_attempt of 'a proof_attempt
  | Transf of 'a transf

val print_any : Format.formatter -> 'a any -> unit
(** Print a subtree with a pstree format (cf Tree module) *)

val key_any : 'a any -> 'a
(** return the key of an element of the tree *)

(** {2 External proof} *)

type 'key notify = 'key any -> unit
(** type of functions which notify modification of the verified field *)

val add_external_proof :
  ?notify:'key notify ->
  keygen:'key keygen ->
  obsolete:bool ->
  timelimit:int ->
  edit:string option ->
  'key goal ->
  prover ->
  proof_attempt_status ->
  'key proof_attempt

val remove_external_proof : ?notify:'key notify -> 'key proof_attempt -> unit

val set_proof_state :
  ?notify:'key notify ->
  obsolete:bool ->
  proof_attempt_status ->
  'key proof_attempt -> unit

val set_edited_as : string option -> 'key proof_attempt -> unit

val set_timelimit : int -> 'key proof_attempt -> unit

(** {2 Transformation} *)

val add_transformation :
  keygen:'key keygen ->
François Bobot's avatar
François Bobot committed
299
  goal:('goal -> Ident.ident * expl * Task.task) ->
François Bobot's avatar
François Bobot committed
300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315
  string ->
  'key goal ->
  'goal list ->
  'key transf
(** Add a transformation by its subgoals *)

val add_registered_transformation :
  keygen:'key keygen ->
  'key env_session ->
  string ->
  'key goal ->
  'key transf
(** Apply a real transformation by its why3 name,
    raise NoTask if the goal doesn't contain a task *)

val remove_transformation : ?notify:'key notify -> 'key transf -> unit
François Bobot's avatar
François Bobot committed
316
  (** Remove a transformation *)
François Bobot's avatar
François Bobot committed
317 318 319 320 321 322 323 324

(** {2 File} *)

val add_file :
  keygen:'key keygen ->
  'key env_session ->
  string ->
  'key file
François Bobot's avatar
François Bobot committed
325
(** Add a real file by its filename *)
François Bobot's avatar
François Bobot committed
326 327

val remove_file : 'key file -> unit
François Bobot's avatar
François Bobot committed
328 329 330
(** Remove a file *)

(** {2 Explanation} *)
François Bobot's avatar
François Bobot committed
331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356

val get_explanation : Ident.ident -> Task.task -> expl
val goal_expl_task : Task.task -> Ident.ident * expl * Task.task

(** {2 Iterators} *)

(** {3 recursive} *)

val goal_iter_proof_attempt : ('key proof_attempt -> unit) -> 'key goal -> unit
val transf_iter_proof_attempt :
  ('key proof_attempt -> unit) -> 'key transf -> unit
val theory_iter_proof_attempt :
  ('key proof_attempt -> unit) -> 'key theory -> unit
val transf_iter_proof_attempt :
  ('key proof_attempt -> unit) -> 'key transf -> unit
val file_iter_proof_attempt : ('key proof_attempt -> unit) -> 'key file -> unit
val session_iter_proof_attempt :
  ('key proof_attempt -> unit) -> 'key session -> unit
val iter_proof_attempt :
  ('key proof_attempt -> unit) -> 'key any -> unit

val goal_iter_leaf_goal :
  unproved_only:bool -> ('key goal -> unit) -> 'key goal -> unit
(** iter all the goals which are a leaf
    (no transformations are applied on it) *)

François Bobot's avatar
François Bobot committed
357
(** {3 not recursive} *)
François Bobot's avatar
François Bobot committed
358

François Bobot's avatar
François Bobot committed
359 360 361 362 363 364 365 366 367 368 369 370 371 372
val iter_goal :
  ('key proof_attempt -> unit) -> ('key transf -> unit) -> 'key goal -> unit
val iter_transf :
  ('key goal -> unit) -> 'key transf -> unit


val goal_iter : ('key any -> unit) -> 'key goal -> unit
val transf_iter : ('key any -> unit) -> 'key transf -> unit
val theory_iter : ('key any -> unit) -> 'key theory -> unit
val transf_iter : ('key any -> unit) -> 'key transf -> unit
val file_iter : ('key any -> unit) -> 'key file -> unit
val session_iter : ('key any -> unit) -> 'key session -> unit
val iter : ('key any -> unit) -> 'key any -> unit

François Bobot's avatar
François Bobot committed
373
(** {2 Some functorized interface (not very useful...)}*)
François Bobot's avatar
François Bobot committed
374 375 376 377 378 379 380


module AddTransf (X : sig
  type key
  val keygen : key keygen

  type goal
François Bobot's avatar
François Bobot committed
381
  val goal : goal -> Ident.ident * expl * Task.task
François Bobot's avatar
François Bobot committed
382 383 384 385 386 387 388 389 390 391 392 393

  type transf
  val fold_transf : ('a -> goal -> 'a) -> 'a -> Task.task -> transf -> 'a
end) : sig
  val add_transformation : X.key goal -> string -> X.transf -> X.key transf
end

module AddFile(X : sig
  type key
  val keygen : key keygen

  type goal
François Bobot's avatar
François Bobot committed
394
  val goal : goal -> Ident.ident * expl * Task.task
François Bobot's avatar
François Bobot committed
395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413

  type theory
  val fold_theory : ('a -> goal -> 'a) -> 'a -> theory -> 'a

  type file
  val fold_file :
    ('a -> Ident.ident (** thname *) -> theory -> 'a) ->
    'a -> file -> 'a

end) : sig
  val add_file : X.key session -> string -> X.file -> X.key file
end


(*
Local Variables:
compile-command: "unset LANG; make -C ../.. bin/why3ide.byte"
End:
*)