1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
open Core
open! Import
type 'a t =
| Always
| Never
| Phys_equal
| Compare of ('a -> 'a -> int)
| Equal of ('a -> 'a -> bool)
| F of (old_value:'a -> new_value:'a -> bool)
[@@deriving sexp_of]
let invariant _ t =
Invariant.invariant [%here] t [%sexp_of: _ t] (fun () ->
match t with
| Always | Never | Phys_equal | Compare _ | Equal _ | F _ -> ())
;;
let create f = F f
let of_compare f = Compare f
let of_equal f = Equal f
let never = Never
let always = Always
let poly_equal = Equal Poly.equal
let should_cutoff t ~old_value ~new_value =
match t with
| Phys_equal -> phys_equal old_value new_value
| Never -> false
| Always -> true
| Compare f -> f old_value new_value = 0
| Equal f -> f old_value new_value
| F f -> f ~old_value ~new_value
;;
let equal t1 t2 =
match t1, t2 with
| Always, Always -> true
| Always, _ -> false
| Never, Never -> true
| Never, _ -> false
| Phys_equal, Phys_equal -> true
| Phys_equal, _ -> false
| Compare f1, Compare f2 -> phys_equal f1 f2
| Compare _, _ -> false
| Equal f1, Equal f2 -> phys_equal f1 f2
| Equal _, _ -> false
| F f1, F f2 -> phys_equal f1 f2
| F _, _ -> false
;;
let phys_equal = Phys_equal
module For_analyzer = struct
type 'a t' = 'a t
type t =
| Always
| Never
| Phys_equal
| Compare
| Equal
| F
[@@deriving sexp, equal]
let of_cutoff (c : _ t') =
match c with
| Always -> Always
| Never -> Never
| Phys_equal -> Phys_equal
| Compare _ -> Compare
| Equal _ -> Equal
| F _ -> F
;;
let to_string t = Sexp.to_string ([%sexp_of: t] t)
end