Skip to content

Commit 9f251f0

Browse files
committed
more clean up
1 parent 506965c commit 9f251f0

File tree

7 files changed

+131
-150
lines changed

7 files changed

+131
-150
lines changed

typing/includecore.ml

+2-2
Original file line numberDiff line numberDiff line change
@@ -692,9 +692,9 @@ module Record_diffing = struct
692692
| Immutable, Mutable _ -> Some Second
693693
| Mutable m1, Mutable m2 ->
694694
let open Mode.Alloc.Comonadic.Const in
695-
(if not (eq m1 legacy) then
695+
(if not (Misc.Le_result.equal ~le m1 legacy) then
696696
Misc.fatal_errorf "Unexpected mutable(%a)" print m1);
697-
(if not (eq m2 legacy) then
697+
(if not (Misc.Le_result.equal ~le m2 legacy) then
698698
Misc.fatal_errorf "Unexpected mutable(%a)" print m2);
699699
None
700700
in

typing/jkind_axis.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ module Axis = struct
142142

143143
let get (type a) : a t -> (module Axis_ops with type t = a) = function
144144
| Modal axis ->
145-
(module Accent_lattice ((val Mode.Alloc.lattice_of_axis axis)))
145+
(module Accent_lattice ((val Mode.Alloc.Const.lattice_of_axis axis)))
146146
| Nonmodal Externality -> (module Externality)
147147
| Nonmodal Nullability -> (module Nullability)
148148

typing/mode.ml

+52-54
Original file line numberDiff line numberDiff line change
@@ -1753,6 +1753,14 @@ module Comonadic_gen (Obj : Obj) = struct
17531753

17541754
let of_const : type l r. const -> (l * r) t = fun a -> Solver.of_const obj a
17551755

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+
17561764
module Guts = struct
17571765
let get_floor m = Solver.get_floor obj m
17581766

@@ -1827,6 +1835,14 @@ module Monadic_gen (Obj : Obj) = struct
18271835

18281836
let of_const : type l r. const -> (l * r) t = fun a -> Solver.of_const obj a
18291837

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+
18301846
module Guts = struct
18311847
let _get_floor m = Solver.get_ceil obj m
18321848

@@ -2057,6 +2073,20 @@ module type Areality = sig
20572073
val zap_to_legacy : (Const.t, allowed * 'r) Solver.mode -> Const.t
20582074
end
20592075

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+
20602090
module Comonadic_with (Areality : Areality) = struct
20612091
module Obj = struct
20622092
type const = Areality.Const.t C.comonadic_with
@@ -2075,28 +2105,16 @@ module Comonadic_with (Areality : Areality) = struct
20752105
let proj_obj ax = C.proj_obj ax Obj.obj
20762106

20772107
module Const = struct
2078-
include C.Comonadic_with (Areality.Const)
2108+
include BiHeyting_Product (C.Comonadic_with (Areality.Const))
20792109

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
20812113

20822114
let le_axis ax a b =
20832115
let obj = proj_obj ax in
20842116
C.le obj a b
20852117

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-
21002118
let lattice_of_axis (type a) (axis : (t, a) Axis.t) :
21012119
(module Lattice with type t = a) =
21022120
match axis with
@@ -2109,19 +2127,15 @@ module Comonadic_with (Areality : Areality) = struct
21092127

21102128
let proj ax m = Solver.apply (proj_obj ax) (Proj (Obj.obj, ax)) m
21112129

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-
21162130
let min_with ax m =
21172131
Solver.apply Obj.obj (Min_with ax) (Solver.disallow_right m)
21182132

21192133
let max_with ax m =
21202134
Solver.apply Obj.obj (Max_with ax) (Solver.disallow_left m)
21212135

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
21232137

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
21252139

21262140
let zap_to_legacy m : Const.t =
21272141
let areality = proj Areality m |> Areality.zap_to_legacy in
@@ -2134,10 +2148,6 @@ module Comonadic_with (Areality : Areality) = struct
21342148
let yielding = proj Yielding m |> Yielding.zap_to_legacy ~global in
21352149
{ areality; linearity; portability; yielding; statefulness }
21362150

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-
21412151
let legacy = of_const Const.legacy
21422152

21432153
let axis_of_error (err : Obj.const Solver.error) : error =
@@ -2219,20 +2229,11 @@ module Monadic = struct
22192229
let proj_obj ax = C.proj_obj ax Obj.obj
22202230

22212231
module Const = struct
2222-
include C.Monadic
2232+
include BiHeyting_Product (C.Monadic)
22232233

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 =
22342235
let obj = proj_obj ax in
2235-
C.min obj
2236+
C.print obj ppf a
22362237

22372238
let le_axis ax a b =
22382239
let obj = proj_obj ax in
@@ -2252,23 +2253,15 @@ module Monadic = struct
22522253

22532254
(* The monadic fragment is inverted. *)
22542255

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-
22592256
let max_with ax m =
22602257
Solver.apply Obj.obj (Min_with ax) (Solver.disallow_right m)
22612258

22622259
let min_with ax m =
22632260
Solver.apply Obj.obj (Max_with ax) (Solver.disallow_left m)
22642261

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
22702263

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
22722265

22732266
let zap_to_legacy m : Const.t =
22742267
let uniqueness = proj Uniqueness m |> Uniqueness.zap_to_legacy in
@@ -2364,12 +2357,6 @@ module Value_with (Areality : Areality) = struct
23642357
P (Monadic Visibility) ]
23652358
end
23662359

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-
23732360
let proj_obj : type a d0 d1. (a, d0, d1) Axis.t -> a C.obj = function
23742361
| Monadic ax -> Monadic.proj_obj ax
23752362
| Comonadic ax -> Comonadic.proj_obj ax
@@ -2481,6 +2468,12 @@ module Value_with (Areality : Areality) = struct
24812468
let comonadic = Comonadic.join m0.comonadic m1.comonadic in
24822469
merge { monadic; comonadic }
24832470

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+
24842477
module Option = struct
24852478
type some = t
24862479

@@ -2856,6 +2849,11 @@ module Value_with (Areality : Areality) = struct
28562849
let comonadic = Comonadic.zap_to_ceil comonadic in
28572850
merge { monadic; comonadic }
28582851

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+
28592857
let zap_to_legacy { comonadic; monadic } =
28602858
let monadic = Monadic.zap_to_legacy monadic in
28612859
let comonadic = Comonadic.zap_to_legacy comonadic in

0 commit comments

Comments
 (0)