@@ -1753,6 +1753,14 @@ module Comonadic_gen (Obj : Obj) = struct
1753
1753
1754
1754
let of_const : type l r. const -> (l * r) t = fun a -> Solver. of_const obj a
1755
1755
1756
+ let meet_const c m = Solver. apply obj (Meet_with c) m
1757
+
1758
+ let join_const c m = Solver. apply obj (Join_with c) m
1759
+
1760
+ let imply c m = Solver. apply obj (Imply c) (Solver. disallow_left m)
1761
+
1762
+ let subtract c m = Solver. apply obj (Subtract c) (Solver. disallow_right m)
1763
+
1756
1764
module Guts = struct
1757
1765
let get_floor m = Solver. get_floor obj m
1758
1766
@@ -1827,6 +1835,14 @@ module Monadic_gen (Obj : Obj) = struct
1827
1835
1828
1836
let of_const : type l r. const -> (l * r) t = fun a -> Solver. of_const obj a
1829
1837
1838
+ let meet_const c m = Solver. apply Obj. obj (Join_with c) m
1839
+
1840
+ let join_const c m = Solver. apply Obj. obj (Meet_with c) m
1841
+
1842
+ let imply c m = Solver. apply obj (Subtract c) (Solver. disallow_right m)
1843
+
1844
+ let subtract c m = Solver. apply obj (Imply c) (Solver. disallow_left m)
1845
+
1830
1846
module Guts = struct
1831
1847
let _get_floor m = Solver. get_ceil obj m
1832
1848
@@ -2057,6 +2073,20 @@ module type Areality = sig
2057
2073
val zap_to_legacy : (Const .t , allowed * 'r ) Solver .mode -> Const .t
2058
2074
end
2059
2075
2076
+ module BiHeyting_Product (L : BiHeyting ) = struct
2077
+ include L
2078
+
2079
+ type 'a axis = (t , 'a ) Axis .t
2080
+
2081
+ let min_with ax c = Axis. update ax c min
2082
+
2083
+ let max_with ax c = Axis. update ax c max
2084
+
2085
+ let min_axis ax = Axis. proj ax min
2086
+
2087
+ let max_axis ax = Axis. proj ax max
2088
+ end
2089
+
2060
2090
module Comonadic_with (Areality : Areality ) = struct
2061
2091
module Obj = struct
2062
2092
type const = Areality.Const .t C .comonadic_with
@@ -2075,28 +2105,16 @@ module Comonadic_with (Areality : Areality) = struct
2075
2105
let proj_obj ax = C. proj_obj ax Obj. obj
2076
2106
2077
2107
module Const = struct
2078
- include C. Comonadic_with (Areality. Const )
2108
+ include BiHeyting_Product ( C. Comonadic_with (Areality. Const ) )
2079
2109
2080
- let eq a b = le a b && le b a
2110
+ let print_axis ax ppf a =
2111
+ let obj = proj_obj ax in
2112
+ C. print obj ppf a
2081
2113
2082
2114
let le_axis ax a b =
2083
2115
let obj = proj_obj ax in
2084
2116
C. le obj a b
2085
2117
2086
- let min_axis ax =
2087
- let obj = proj_obj ax in
2088
- C. min obj
2089
-
2090
- let max_axis ax =
2091
- let obj = proj_obj ax in
2092
- C. max obj
2093
-
2094
- let max_with ax c = Axis. update ax c (C. max Obj. obj)
2095
-
2096
- let print_axis ax ppf a =
2097
- let obj = proj_obj ax in
2098
- C. print obj ppf a
2099
-
2100
2118
let lattice_of_axis (type a ) (axis : (t, a) Axis.t ) :
2101
2119
(module Lattice with type t = a ) =
2102
2120
match axis with
@@ -2109,19 +2127,15 @@ module Comonadic_with (Areality : Areality) = struct
2109
2127
2110
2128
let proj ax m = Solver. apply (proj_obj ax) (Proj (Obj. obj, ax)) m
2111
2129
2112
- let meet_const c m = Solver. apply Obj. obj (Meet_with c) m
2113
-
2114
- let join_const c m = Solver. apply Obj. obj (Join_with c) m
2115
-
2116
2130
let min_with ax m =
2117
2131
Solver. apply Obj. obj (Min_with ax) (Solver. disallow_right m)
2118
2132
2119
2133
let max_with ax m =
2120
2134
Solver. apply Obj. obj (Max_with ax) (Solver. disallow_left m)
2121
2135
2122
- let join_with ax c m = join_const (C . min_with Obj. obj ax c) m
2136
+ let join_with ax c m = join_const (Const . min_with ax c) m
2123
2137
2124
- let meet_with ax c m = meet_const (C . max_with Obj. obj ax c) m
2138
+ let meet_with ax c m = meet_const (Const . max_with ax c) m
2125
2139
2126
2140
let zap_to_legacy m : Const.t =
2127
2141
let areality = proj Areality m |> Areality. zap_to_legacy in
@@ -2134,10 +2148,6 @@ module Comonadic_with (Areality : Areality) = struct
2134
2148
let yielding = proj Yielding m |> Yielding. zap_to_legacy ~global in
2135
2149
{ areality; linearity; portability; yielding; statefulness }
2136
2150
2137
- let imply c m = Solver. apply Obj. obj (Imply c) (Solver. disallow_left m)
2138
-
2139
- let subtract c m = Solver. apply Obj. obj (Subtract c) (Solver. disallow_right m)
2140
-
2141
2151
let legacy = of_const Const. legacy
2142
2152
2143
2153
let axis_of_error (err : Obj.const Solver.error ) : error =
@@ -2219,20 +2229,11 @@ module Monadic = struct
2219
2229
let proj_obj ax = C. proj_obj ax Obj. obj
2220
2230
2221
2231
module Const = struct
2222
- include C. Monadic
2232
+ include BiHeyting_Product ( C. Monadic )
2223
2233
2224
- (* CR zqian: The flipping logic leaking to here is bad. Refactoring needed. *)
2225
-
2226
- (* Monadic fragment is flipped, so are the following definitions. *)
2227
- let min_with ax c = Axis. update ax c (C. max Obj. obj)
2228
-
2229
- let min_axis ax =
2230
- let obj = proj_obj ax in
2231
- C. max obj
2232
-
2233
- let max_axis ax =
2234
+ let print_axis ax ppf a =
2234
2235
let obj = proj_obj ax in
2235
- C. min obj
2236
+ C. print obj ppf a
2236
2237
2237
2238
let le_axis ax a b =
2238
2239
let obj = proj_obj ax in
@@ -2252,23 +2253,15 @@ module Monadic = struct
2252
2253
2253
2254
(* The monadic fragment is inverted. *)
2254
2255
2255
- let meet_const c m = Solver. apply Obj. obj (Join_with c) m
2256
-
2257
- let join_const c m = Solver. apply Obj. obj (Meet_with c) m
2258
-
2259
2256
let max_with ax m =
2260
2257
Solver. apply Obj. obj (Min_with ax) (Solver. disallow_right m)
2261
2258
2262
2259
let min_with ax m =
2263
2260
Solver. apply Obj. obj (Max_with ax) (Solver. disallow_left m)
2264
2261
2265
- let join_with ax c m = join_const (C. max_with Obj. obj ax c) m
2266
-
2267
- let meet_with ax c m = meet_const (C. min_with Obj. obj ax c) m
2268
-
2269
- let imply c m = Solver. apply Obj. obj (Subtract c) (Solver. disallow_right m)
2262
+ let join_with ax c m = join_const (Const. min_with ax c) m
2270
2263
2271
- let subtract c m = Solver. apply Obj. obj ( Imply c) ( Solver. disallow_left m)
2264
+ let meet_with ax c m = meet_const ( Const. max_with ax c) m
2272
2265
2273
2266
let zap_to_legacy m : Const.t =
2274
2267
let uniqueness = proj Uniqueness m |> Uniqueness. zap_to_legacy in
@@ -2364,12 +2357,6 @@ module Value_with (Areality : Areality) = struct
2364
2357
P (Monadic Visibility ) ]
2365
2358
end
2366
2359
2367
- let lattice_of_axis (type a d0 d1 ) (axis : (a, d0, d1) Axis.t ) :
2368
- (module Lattice with type t = a ) =
2369
- match axis with
2370
- | Comonadic ax -> Comonadic.Const. lattice_of_axis ax
2371
- | Monadic ax -> Monadic.Const. lattice_of_axis ax
2372
-
2373
2360
let proj_obj : type a d0 d1. (a, d0, d1) Axis.t -> a C.obj = function
2374
2361
| Monadic ax -> Monadic. proj_obj ax
2375
2362
| Comonadic ax -> Comonadic. proj_obj ax
@@ -2481,6 +2468,12 @@ module Value_with (Areality : Areality) = struct
2481
2468
let comonadic = Comonadic. join m0.comonadic m1.comonadic in
2482
2469
merge { monadic; comonadic }
2483
2470
2471
+ let lattice_of_axis (type a d0 d1 ) (axis : (a, d0, d1) Axis.t ) :
2472
+ (module Lattice with type t = a ) =
2473
+ match axis with
2474
+ | Comonadic ax -> Comonadic. lattice_of_axis ax
2475
+ | Monadic ax -> Monadic. lattice_of_axis ax
2476
+
2484
2477
module Option = struct
2485
2478
type some = t
2486
2479
@@ -2856,6 +2849,11 @@ module Value_with (Areality : Areality) = struct
2856
2849
let comonadic = Comonadic. zap_to_ceil comonadic in
2857
2850
merge { monadic; comonadic }
2858
2851
2852
+ let zap_to_floor { comonadic; monadic } =
2853
+ let monadic = Monadic. zap_to_floor monadic in
2854
+ let comonadic = Comonadic. zap_to_floor comonadic in
2855
+ merge { monadic; comonadic }
2856
+
2859
2857
let zap_to_legacy { comonadic; monadic } =
2860
2858
let monadic = Monadic. zap_to_legacy monadic in
2861
2859
let comonadic = Comonadic. zap_to_legacy comonadic in
0 commit comments