| 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 | (** Graphs representing strict orders *) |
| 12 | |
| 13 | type constraint_type = Lt | Le | Eq |
| 14 | |
| 15 | module type Point = sig |
| 16 | type t |
| 17 | |
| 18 | module Set : CSig.USetS with type elt = t |
| 19 | module Map : CMap.UExtS with type key = t and module Set := Set |
| 20 | |
| 21 | val equal : t -> t -> bool |
| 22 | val compare : t -> t -> int |
| 23 | |
| 24 | val raw_pr : t -> Pp.t |
| 25 | |
| 26 | (* Parameters of the anomaly raised when repr node not found. *) |
| 27 | val anomaly_err : t -> Pp.t |
| 28 | end |
| 29 | |
| 30 | module Make (Point:Point) : sig |
| 31 | |
| 32 | type t |
| 33 | |
| 34 | val empty : t |
| 35 | |
| 36 | val check_invariants : required_canonical:(Point.t -> bool) -> t -> unit |
| 37 | |
| 38 | exception AlreadyDeclared |
| 39 | val add : ?rank:int -> Point.t -> t -> t |
| 40 | (** All points must be pre-declared through this function before |
| 41 | they can be mentioned in the others. NB: use a large [rank] to |
| 42 | keep the node canonical *) |
| 43 | |
| 44 | val check_declared : t -> Point.Set.t -> (unit, Point.Set.t) result |
| 45 | (** @raise Undeclared if one of the points is not present in the graph. *) |
| 46 | |
| 47 | type 'a check_function = t -> 'a -> 'a -> bool |
| 48 | |
| 49 | val check_eq : Point.t check_function |
| 50 | val check_leq : Point.t check_function |
| 51 | val check_lt : Point.t check_function |
| 52 | |
| 53 | val enforce_eq : Point.t -> Point.t -> t -> t option |
| 54 | val enforce_leq : Point.t -> Point.t -> t -> t option |
| 55 | val enforce_lt : Point.t -> Point.t -> t -> t option |
| 56 | |
| 57 | (** Type explanation is used to decorate error messages to provide a |
| 58 | useful explanation why a given constraint is rejected. It is composed |
| 59 | of a starting universe [u0] and a path of universes and relation kinds |
| 60 | [(r1,u1);..;(rn,un)] meaning [u0 <(r1) u1 <(r2) ... <(rn) un] |
| 61 | (where [<(ri)] is the relation symbol denoted by ri). |
| 62 | When the rejected constraint is a [a <= b] or [a < b] then the path is from[b] to [a], |
| 63 | ie [u0 == b] and [un == a]. |
| 64 | when the rejected constraint is an equality the path may go in either direction. |
| 65 | Note that each step does not necessarily correspond to an actual constraint, |
| 66 | but reflect how the system stores the graph |
| 67 | and may result from combination of several UnivConstraints.t... |
| 68 | *) |
| 69 | type explanation = Point.t * (constraint_type * Point.t) list |
| 70 | |
| 71 | val get_explanation : (Point.t * constraint_type * Point.t) -> t -> explanation |
| 72 | (** Assuming that the corresponding call to [enforce_*] returned [None], this |
| 73 | will give a trace for the failure. *) |
| 74 | |
| 75 | type 'a constraint_fold = Point.t * constraint_type * Point.t -> 'a -> 'a |
| 76 | |
| 77 | val constraints_of : t -> 'a constraint_fold -> 'a -> 'a * Point.Set.t list |
| 78 | |
| 79 | val constraints_for : kept:Point.Set.t -> t -> 'a constraint_fold -> 'a -> 'a |
| 80 | |
| 81 | val domain : t -> Point.Set.t |
| 82 | |
| 83 | val choose : (Point.t -> bool) -> t -> Point.t -> Point.t option |
| 84 | |
| 85 | (** {5 High-level representation} *) |
| 86 | |
| 87 | type node = |
| 88 | | Alias of Point.t |
| 89 | | Node of bool Point.Map.t (** Nodes v s.t. u < v (true) or u <= v (false) *) |
| 90 | type repr = node Point.Map.t |
| 91 | val repr : t -> repr |
| 92 | |
| 93 | end |