| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
open Univ |
| 12 |
open Sorts |
| 13 |
|
| 14 |
type t = ElimConstraints.t * UnivConstraints.t |
| 15 |
|
| 16 |
type pconstraints = t |
| 17 |
|
| 18 |
let make q u = (q, u) |
| 19 |
|
| 20 |
let qualities = fst |
| 21 |
|
| 22 |
let univs = snd |
| 23 |
|
| 24 |
let add_quality q (qc, lc) = (ElimConstraints.add q qc, lc) |
| 25 |
|
| 26 |
let add_univ u (qc, lc) = (qc, UnivConstraints.add u lc) |
| 27 |
|
| 28 |
let of_qualities qc = make qc UnivConstraints.empty |
| 29 |
|
| 30 |
let of_univs lc = make ElimConstraints.empty lc |
| 31 |
|
| 32 |
let set_qualities qc (_,lc) = make qc lc |
| 33 |
|
| 34 |
let set_univs lc (qc,_) = make qc lc |
| 35 |
|
| 36 |
let empty = (ElimConstraints.empty, UnivConstraints.empty) |
| 37 |
|
| 38 |
let is_empty (qc, lc) = |
| 39 |
ElimConstraints.is_empty qc && UnivConstraints.is_empty lc |
| 40 |
|
| 41 |
let equal (qc, lc) (qc', lc') = |
| 42 |
ElimConstraints.equal qc qc' && UnivConstraints.equal lc lc' |
| 43 |
|
| 44 |
let union (qc, lc) (qc', lc') = |
| 45 |
(ElimConstraints.union qc qc', UnivConstraints.union lc lc') |
| 46 |
|
| 47 |
let fold (qf, lf) (qc, lc) (x, y) = |
| 48 |
(ElimConstraints.fold qf qc x, UnivConstraints.fold lf lc y) |
| 49 |
|
| 50 |
let diff (qc, lc) (qc', lc') = |
| 51 |
(ElimConstraints.diff qc qc', UnivConstraints.diff lc lc') |
| 52 |
|
| 53 |
let elements (qc, lc) = |
| 54 |
(ElimConstraints.elements qc, UnivConstraints.elements lc) |
| 55 |
|
| 56 |
let filter_qualities f (qc, lc) = |
| 57 |
make (ElimConstraints.filter f qc) lc |
| 58 |
|
| 59 |
let filter_univs f (qc, lc) = |
| 60 |
make qc @@ UnivConstraints.filter f lc |
| 61 |
|
| 62 |
let pr prv prl (qc, lc) = |
| 63 |
let open Pp in |
| 64 |
let sep = if ElimConstraints.is_empty qc || UnivConstraints.is_empty lc |
| 65 |
then mt () |
| 66 |
else pr_comma () in |
| 67 |
v 0 (ElimConstraints.pr prv qc ++ sep ++ UnivConstraints.pr prl lc) |
| 68 |
|
| 69 |
module HPConstraints = |
| 70 |
Hashcons.Make( |
| 71 |
struct |
| 72 |
type t = pconstraints |
| 73 |
let hashcons (qf, uf) = |
| 74 |
let hqf, qf = ElimConstraints.hcons qf in |
| 75 |
let huf, uf = UnivConstraints.hcons uf in |
| 76 |
Hashset.Combine.(combine hqf huf), (qf, uf) |
| 77 |
let eq (qc, uc) (qc', uc') = |
| 78 |
qc == qc' && uc == uc' |
| 79 |
end) |
| 80 |
|
| 81 |
let hcons = |
| 82 |
Hashcons.simple_hcons |
| 83 |
HPConstraints.generate |
| 84 |
HPConstraints.hcons () |
| 85 |
|
| 86 |
|
| 87 |
type 'a constrained = 'a * t |
| 88 |
|
| 89 |
let constraints_of (_, cst) = cst |
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
type 'a constraint_function = 'a -> 'a -> t -> t |
| 94 |
|
| 95 |
let enforce_eq_univ u v c = |
| 96 |
|
| 97 |
if Level.equal u v then c |
| 98 |
else add_univ (u, UnivConstraint.Eq, v) c |
| 99 |
|
| 100 |
let enforce_leq_univ u v c = |
| 101 |
if Level.equal u v then c |
| 102 |
else add_univ (u, UnivConstraint.Le, v) c |
| 103 |
|
| 104 |
let enforce_elim_to q1 q2 csts = |
| 105 |
if QGraph.ElimTable.eliminates_to q1 q2 then csts |
| 106 |
else add_quality (q1, ElimConstraint.ElimTo, q2) csts |