Debian Codegraph @

vernac/future.mli

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 (* Futures: asynchronous computations.
12 *
13 * A Future.computation is like a lazy_t but with some extra bells and whistles
14 * to deal with eventual delegation to a slave process.
15 *
16 * One difference with lazy_t is that a future computation that produces
17 * and exception can be substituted for another computation of the same type.
18 * Moreover a future computation can be delegated to another execution entity
19 * that will be allowed to set the result. Finally future computations can
20 * always be marshalled: if they were joined before marshalling, they will
21 * hold the computed value (assuming it is itself marshallable), otherwise
22 * they will become invalid and accessing them raises a private exception.
23 *)
24
25 (* Each computation has a unique id that is inherited by each offspring
26 * computation (chain, split, map...). Joined computations lose it. *)
27 module UUID : sig
28 type t
29 val invalid : t
30
31 val compare : t -> t -> int
32 val equal : t -> t -> bool
33 end
34
35 module UUIDMap : Map.S with type key = UUID.t
36 module UUIDSet : Set.S with type elt = UUID.t
37
38 exception NotReady of string
39
40 type 'a computation
41 type 'a value = [ `Val of 'a | `Exn of Exninfo.iexn ]
42
43 type fix_exn = Stateid.exn_info option
44
45 (* Build a computation, no snapshot of the global state is taken. If you need
46 to grab a copy of the state start with from_here () and then chain.
47 fix_exn is used to enrich any exception raised
48 by forcing the computations or any computation that is chained after
49 it. It is used by STM to attach errors to their corresponding states,
50 and to communicate to the code catching the exception a valid state id. *)
51 val create : fix_exn:fix_exn -> (unit -> 'a) -> 'a computation
52
53 (* Usually from_val is used to create "fake" futures, to use the same API
54 as if a real asynchronous computations was there. *)
55 val from_val : 'a -> 'a computation
56
57 (* Run remotely, returns the function to assign.
58 If not blocking (the default) it raises NotReady if forced before the
59 delegate assigns it. *)
60 type 'a assignment = [ `Val of 'a | `Exn of Exninfo.iexn | `Comp of (unit -> 'a)]
61 val create_delegate :
62 ?blocking:bool -> name:string ->
63 fix_exn -> 'a computation * ('a assignment -> unit)
64
65 (* Given a computation that is_exn, replace it by another one *)
66 val replace : 'a computation -> 'a computation -> unit
67
68 (* Inspect a computation *)
69 val is_over : 'a computation -> bool
70 val is_exn : 'a computation -> bool
71 val peek_val : 'a computation -> 'a option
72 val uuid : 'a computation -> UUID.t
73
74 (* [chain c f] chains computation [c] with [f].
75 * [chain] is eager, that is to say, it won't suspend the new computation
76 * if the old one is_over (Exn or Val).
77 *)
78 val chain : 'a computation -> ('a -> 'b) -> 'b computation
79
80 (* Forcing a computation *)
81 val force : 'a computation -> 'a
82 val compute : 'a computation -> 'a value
83
84 (** Debug: print a computation given an inner printing function. *)
85 val print : ('a -> Pp.t) -> 'a computation -> Pp.t