Skip to content

Commit 3f9994c

Browse files
authored
make mode system scale better with more axes (#2395)
* make mode constants scale * make mode checking scale * decompose axis access * reuse existing representation of axis * decompose monadic vs. comonadic
1 parent 0c0a907 commit 3f9994c

File tree

8 files changed

+617
-721
lines changed

8 files changed

+617
-721
lines changed

ocaml/lambda/translmode.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ let transl_locality_mode_r locality =
2929

3030
let transl_alloc_mode_l mode =
3131
(* we only take the locality axis *)
32-
Alloc.locality mode |> transl_locality_mode_l
32+
Alloc.proj (Comonadic Areality) mode |> transl_locality_mode_l
3333

3434
let transl_alloc_mode_r mode =
3535
(* we only take the locality axis *)
36-
Alloc.locality mode |> transl_locality_mode_r
36+
Alloc.proj (Comonadic Areality) mode |> transl_locality_mode_r
3737

3838
let transl_modify_mode locality =
3939
match Locality.zap_to_floor locality with

ocaml/typing/ctype.ml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1583,9 +1583,9 @@ let prim_mode mvar = function
15831583
put in [mode.ml] *)
15841584
let with_locality locality m =
15851585
let m' = Alloc.newvar () in
1586-
Locality.equate_exn (Alloc.locality m') locality;
1587-
Alloc.submode_exn m' (Alloc.join_with_locality Locality.Const.max m);
1588-
Alloc.submode_exn (Alloc.meet_with_locality Locality.Const.min m) m';
1586+
Locality.equate_exn (Alloc.proj (Comonadic Areality) m') locality;
1587+
Alloc.submode_exn m' (Alloc.join_with (Comonadic Areality) Locality.Const.max m);
1588+
Alloc.submode_exn (Alloc.meet_with (Comonadic Areality) Locality.Const.min m) m';
15891589
m'
15901590

15911591
let rec instance_prim_locals locals mvar macc finalret ty =
@@ -5578,7 +5578,7 @@ let mode_cross_left env ty mode =
55785578
now; will return and figure this out later. *)
55795579
let jkind = type_jkind_purely env ty in
55805580
let upper_bounds = Jkind.get_modal_upper_bounds jkind in
5581-
Alloc.meet_with upper_bounds mode
5581+
Alloc.meet_const upper_bounds mode
55825582

55835583
(* CR layouts v2.8: merge with Typecore.expect_mode_cross when [Value]
55845584
and [Alloc] get unified *)

ocaml/typing/env.ml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2958,7 +2958,7 @@ let lookup_ident_module (type a) (load : a load) ~errors ~use ~loc s env =
29582958
let escape_mode ~errors ~env ~loc id vmode escaping_context =
29592959
match
29602960
Mode.Regionality.submode
2961-
(Mode.Value.regionality vmode)
2961+
(Mode.Value.proj (Comonadic Areality) vmode)
29622962
(Mode.Regionality.global)
29632963
with
29642964
| Ok () -> ()
@@ -2969,13 +2969,13 @@ let escape_mode ~errors ~env ~loc id vmode escaping_context =
29692969
let share_mode ~errors ~env ~loc id vmode shared_context =
29702970
match
29712971
Mode.Linearity.submode
2972-
(Mode.Value.linearity vmode)
2972+
(Mode.Value.proj (Comonadic Linearity) vmode)
29732973
Mode.Linearity.many
29742974
with
29752975
| Error _ ->
29762976
may_lookup_error errors loc env
29772977
(Once_value_used_in (id, shared_context))
2978-
| Ok () -> Mode.Value.join [Mode.Value.min_with_uniqueness Mode.Uniqueness.shared; vmode]
2978+
| Ok () -> Mode.Value.join [Mode.Value.min_with (Monadic Uniqueness) Mode.Uniqueness.shared; vmode]
29792979

29802980
let closure_mode ~errors ~env ~loc id {Mode.monadic; comonadic}
29812981
closure_context comonadic0 : Mode.Value.l =
@@ -2998,7 +2998,7 @@ let closure_mode ~errors ~env ~loc id {Mode.monadic; comonadic}
29982998
let exclave_mode ~errors ~env ~loc id vmode =
29992999
match
30003000
Mode.Regionality.submode
3001-
(Mode.Value.regionality vmode)
3001+
(Mode.Value.proj (Comonadic Areality) vmode)
30023002
Mode.Regionality.regional
30033003
with
30043004
| Ok () -> vmode |> Mode.value_to_alloc_r2l |> Mode.alloc_as_value
@@ -3962,15 +3962,15 @@ let report_lookup_error _loc env ppf = function
39623962
| Value_used_in_closure (lid, error, context) ->
39633963
let e0, e1 =
39643964
match error with
3965-
| `Regionality _ -> "local", "might escape"
3966-
| `Linearity _ -> "once", "is many"
3965+
| Error (Areality, _) -> "local", "might escape"
3966+
| Error (Linearity, _) -> "once", "is many"
39673967
in
39683968
fprintf ppf
39693969
"@[The value %a is %s, so cannot be used \
39703970
inside a closure that %s.@]"
39713971
!print_longident lid e0 e1;
39723972
begin match error, context with
3973-
| `Regionality _, Some Tailcall_argument ->
3973+
| Error (Areality, _), Some Tailcall_argument ->
39743974
fprintf ppf "@.@[Hint: The closure might escape because it \
39753975
is an argument to a tail call@]"
39763976
| _ -> ()

0 commit comments

Comments
 (0)