Skip to content

Commit 453a6eb

Browse files
committed
final clean up, I promise
1 parent 3750484 commit 453a6eb

File tree

7 files changed

+64
-55
lines changed

7 files changed

+64
-55
lines changed

ocaml/lambda/translmode.mli

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
val transl_locality_mode_l : (Mode.allowed * 'r) Mode.Locality.t -> Lambda.locality_mode
1+
open Mode
2+
val transl_locality_mode_l : (allowed * 'r) Locality.t -> Lambda.locality_mode
23

3-
val transl_alloc_mode_l : (Mode.allowed * 'r) Mode.Alloc.t -> Lambda.alloc_mode
4-
val transl_alloc_mode_r : ('l * Mode.allowed) Mode.Alloc.t -> Lambda.alloc_mode
4+
val transl_alloc_mode_l : (allowed * 'r) Alloc.t -> Lambda.alloc_mode
5+
val transl_alloc_mode_r : ('l * allowed) Alloc.t -> Lambda.alloc_mode
56

6-
val transl_modify_mode : (Mode.allowed * 'r) Mode.Locality.t -> Lambda.modify_mode
7+
val transl_modify_mode : (allowed * 'r) Locality.t -> Lambda.modify_mode

ocaml/typing/includecore.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ let value_descriptions ~loc env name
125125
with Ctype.Moregen err -> raise (Dont_match (Type err)));
126126
let pc =
127127
{pc_desc = p1; pc_type = vd2.Types.val_type;
128-
pc_poly_mode = Option.map Mode.Locality.disallow_right mode1;
128+
pc_poly_mode = Option.map Mode.Locality.disallow_right mode1;
129129
pc_env = env; pc_loc = vd1.Types.val_loc; } in
130130
Tcoerce_primitive pc
131131
end

ocaml/typing/printtyped.ml

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -212,17 +212,6 @@ let attributes i ppf l =
212212
let layout_annotation i ppf layout =
213213
line i ppf "%s" (Layouts.Layout.string_of_const layout)
214214

215-
let alloc_mode i ppf m =
216-
line i ppf "alloc_mode %a\n" (Mode.Alloc.print ()) m
217-
218-
let alloc_mode_option i ppf m = Option.iter (alloc_mode i ppf) m
219-
220-
let locality_mode i ppf m =
221-
line i ppf "locality_mode %a\n" (Mode.Locality.print ()) m
222-
223-
let value_mode i ppf m =
224-
line i ppf "value_mode %a\n" (Mode.Value.print ()) m
225-
226215
let rec core_type i ppf x =
227216
line i ppf "core_type %a\n" fmt_location x.ctyp_loc;
228217
attributes i ppf x.ctyp_attributes;
@@ -368,6 +357,18 @@ and expression_extra i ppf (x,_,attrs) =
368357
line i ppf "Texp_newtype %a\n" (typevar_layout ~print_quote:false) (s, lay);
369358
attributes i ppf attrs;
370359

360+
and alloc_mode i ppf m =
361+
line i ppf "alloc_mode %a\n" (Mode.Alloc.print ()) m
362+
363+
and alloc_mode_option i ppf m = Option.iter (alloc_mode i ppf) m
364+
365+
and locality_mode i ppf m =
366+
line i ppf "locality_mode %a\n"
367+
(Mode.Locality.print ()) m
368+
369+
and value_mode i ppf m =
370+
line i ppf "value_mode %a\n" (Mode.Value.print ()) m
371+
371372
and expression_alloc_mode i ppf (expr, am) =
372373
alloc_mode i ppf am;
373374
expression i ppf expr

ocaml/typing/typecore.ml

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ open Asttypes
2020
open Parsetree
2121
open Layouts
2222
open Types
23+
open Mode
2324
open Typedtree
2425
open Btype
2526
open Ctype
26-
open Mode
2727
open Uniqueness_analysis
2828

2929
type comprehension_type =
@@ -422,7 +422,6 @@ let _modality_box_right global_flag mode =
422422
|> le_many_right
423423
| Unrestricted -> mode
424424

425-
426425
(* Describes how a modality affects field projection. Returns the mode
427426
of the projection given the mode of the record. *)
428427
let modality_unbox_left global_flag mode =
@@ -456,7 +455,6 @@ let mode_default mode =
456455

457456
let mode_legacy = mode_default Value.legacy
458457

459-
460458
(* used when entering a function;
461459
mode is the mode of the function region *)
462460
let mode_return mode =
@@ -473,10 +471,11 @@ let mode_region mode =
473471
closure_context = None;
474472
}
475473

476-
let mode_max = mode_default Value.max
474+
let mode_max =
475+
mode_default Value.max
477476

478477
let mode_max_with_position position =
479-
{mode_max with position}
478+
{ mode_max with position }
480479

481480
let mode_subcomponent expected_mode =
482481
let mode = alloc_as_value (value_to_alloc_r2g expected_mode.mode) in
@@ -505,10 +504,11 @@ let mode_strictly_local expected_mode =
505504

506505
let mode_unique expected_mode =
507506
let mode = le_unique_right expected_mode.mode in
508-
{expected_mode with mode}
507+
{ expected_mode with mode }
509508

510509
let mode_once expected_mode =
511-
{expected_mode with mode = Value.set_linearity_max expected_mode.mode}
510+
{ expected_mode with
511+
mode = Value.set_linearity_max expected_mode.mode}
512512

513513
let mode_tailcall_function mode =
514514
{ (mode_default mode) with
@@ -521,8 +521,8 @@ let mode_tailcall_argument mode =
521521

522522
let mode_partial_application expected_mode =
523523
let mode = alloc_as_value (value_to_alloc_r2g expected_mode.mode) in
524-
{ expected_mode
525-
with mode;
524+
{ expected_mode with
525+
mode;
526526
closure_context = Some Partial_application }
527527

528528

@@ -780,7 +780,7 @@ let mode_cross_to_min env ty mode =
780780

781781
let expect_mode_cross env ty (expected_mode : expected_mode) =
782782
if mode_cross env ty then
783-
{ expected_mode with
783+
{ expected_mode with
784784
mode = Value.disallow_left Value.max;
785785
exact = None;
786786
strictly_local = false }
@@ -4486,9 +4486,9 @@ let unique_use ~loc ~env mode_l mode_r =
44864486
let uniqueness = Uniqueness.disallow_left (Value.uniqueness mode_r) in
44874487
let linearity = Linearity.disallow_right (Value.linearity mode_l) in
44884488
if not (Language_extension.is_enabled Unique) then begin
4489-
(* if unique extension is not enabled, we will not run uniqueness analysis ;
4490-
instead, we force all uses to be shared and many. This is equivalent to
4491-
running a UA which forces everything *)
4489+
(* if unique extension is not enabled, we will not run uniqueness analysis;
4490+
instead, we force all uses to be shared and many. This is equivalent to
4491+
running a UA which forces everything *)
44924492
(match Uniqueness.submode Uniqueness.shared uniqueness with
44934493
| Ok () -> ()
44944494
| Error () ->
@@ -5292,7 +5292,6 @@ and type_expect_
52925292
else record.exp_type
52935293
in
52945294
let (label_loc, label, newval) =
5295-
(* rmode won't be used because mutable field *)
52965295
type_label_exp false env (mode_default rmode) loc
52975296
ty_record (lid, label, snewval) in
52985297
unify_exp env record ty_record;
@@ -6115,10 +6114,11 @@ and type_ident env ?(recarg=Rejected) lid =
61156114
let ty, mode = instance_prim_mode prim (instance desc.val_type) in
61166115
begin match prim.prim_native_repr_res, mode with
61176116
(* if the locality of returned value of the primitive is poly
6118-
we then register allocation for further optimization *)
6119-
| (Prim_poly, _), Some mode -> register_allocation_mode
6120-
(* TODO: fix this dirty hack *)
6121-
(Alloc.meet [Alloc.max_with_locality mode; Alloc.max_with_linearity Linearity.many])
6117+
we then register allocation for further optimization *)
6118+
| (Prim_poly, _), Some mode ->
6119+
register_allocation_mode
6120+
(Alloc.meet [Alloc.max_with_locality mode;
6121+
Alloc.max_with_linearity Linearity.many])
61226122
| _ -> ()
61236123
end;
61246124
ty, Id_prim (Option.map Locality.disallow_right mode)
@@ -6311,7 +6311,6 @@ and type_function
63116311
exp_desc =
63126312
Texp_function
63136313
{ arg_label; param; cases; partial; region; curry; warnings;
6314-
63156314
arg_mode = Alloc.disallow_right arg_mode; arg_sort;
63166315
alloc_mode = Alloc.disallow_left alloc_mode; ret_sort };
63176316
exp_loc = loc; exp_extra = [];
@@ -8441,7 +8440,9 @@ let escaping_hint failure_reason submode_reason
84418440
let rec loop sureness n ty =
84428441
match get_desc ty with
84438442
| Tarrow ((_, _, res_mode), _, res_ty, _) ->
8444-
begin match Locality.check_const (Alloc.locality res_mode) with
8443+
begin match
8444+
Locality.check_const (Alloc.locality res_mode)
8445+
with
84458446
| Some Global ->
84468447
Some (n+1, true)
84478448
| (None | Some Local) as res_mode ->
@@ -8945,19 +8946,19 @@ let report_error ~loc env = function
89458946
Printtyp.type_expr ty
89468947
| Submode_failed(fail_reason, submode_reason, closure_context, shared_context)
89478948
->
8948-
let sub =
8949-
match fail_reason with
8950-
| `Linearity | `Uniqueness ->
8949+
let sub =
8950+
match fail_reason with
8951+
| `Linearity | `Uniqueness ->
89518952
sharedness_hint fail_reason submode_reason shared_context
8952-
| `Regionality ->
8953+
| `Regionality ->
89538954
escaping_hint fail_reason submode_reason closure_context
8954-
in
8955-
Location.errorf ~loc ~sub begin
8956-
match fail_reason with
8957-
| `Regionality -> "This value escapes its region"
8958-
| `Uniqueness -> "Found a shared value where a unique value was expected"
8959-
| `Linearity -> "Found a once value where a many value was expected"
8960-
end
8955+
in
8956+
Location.errorf ~loc ~sub begin
8957+
match fail_reason with
8958+
| `Regionality -> "This value escapes its region"
8959+
| `Uniqueness -> "Found a shared value where a unique value was expected"
8960+
| `Linearity -> "Found a once value where a many value was expected"
8961+
end
89618962
| Local_application_complete (lbl, loc_kind) ->
89628963
let sub =
89638964
match loc_kind with

ocaml/typing/types.ml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ and type_desc =
4343
| Tpoly of type_expr * type_expr list
4444
| Tpackage of Path.t * (Longident.t * type_expr) list
4545

46-
and arrow_desc = arg_label * Mode.Alloc.lr * Mode.Alloc.lr
46+
and arrow_desc =
47+
arg_label * Mode.Alloc.lr * Mode.Alloc.lr
4748

4849
and row_desc =
4950
{ row_fields: (label * row_field) list;
@@ -607,7 +608,7 @@ type change =
607608
| Ckind : [`var] field_kind_gen -> change
608609
| Ccommu : [`var] commutable_gen -> change
609610
| Cuniv : type_expr option ref * type_expr option -> change
610-
| Cmode : Solver.changes -> change
611+
| Cmodes : Solver.changes -> change
611612

612613
type changes =
613614
Change of change * changes ref
@@ -621,6 +622,8 @@ let log_change ch =
621622
!trail := Change (ch, r');
622623
trail := r'
623624

625+
let () =
626+
Solver.append_changes := (fun changes -> log_change (Cmodes !changes))
624627

625628
(* constructor and accessors for [field_kind] *)
626629

@@ -869,7 +872,7 @@ let undo_change = function
869872
| Ckind (FKvar r) -> r.field_kind <- FKprivate
870873
| Ccommu (Cvar r) -> r.commu <- Cunknown
871874
| Cuniv (r, v) -> r := v
872-
| Cmode c -> Solver.undo_changes c
875+
| Cmodes c -> Solver.undo_changes c
873876

874877
type snapshot = changes ref * int
875878
let last_snapshot = Local_store.s_ref 0
@@ -1028,5 +1031,4 @@ let undo_compress (changes, _old) =
10281031
| _ -> ())
10291032
log
10301033

1031-
let () =
1032-
Solver.append_changes := fun changes -> log_change (Cmode !changes)
1034+

ocaml/typing/types.mli

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,8 @@ and type_desc =
136136
| Tpackage of Path.t * (Longident.t * type_expr) list
137137
(** Type of a first-class module (a.k.a package). *)
138138

139-
and arrow_desc = arg_label * Mode.Alloc.lr * Mode.Alloc.lr
139+
and arrow_desc =
140+
arg_label * Mode.Alloc.lr * Mode.Alloc.lr
140141

141142

142143

ocaml/typing/typetexp.ml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -585,12 +585,15 @@ and transl_type_aux env policy mode styp =
585585
| (l, arg_mode, arg) :: rest ->
586586
check_arg_type arg;
587587
let arg_cty = transl_type env policy arg_mode arg in
588-
let (loc, lin, _) =
588+
let acc_mode =
589589
Alloc.Const.join
590590
(Alloc.Const.close_over arg_mode)
591591
(Alloc.Const.partial_apply acc_mode)
592592
in
593-
let acc_mode = (loc, lin, Uniqueness.Const.Shared) in
593+
let acc_mode =
594+
Alloc.Const.join acc_mode
595+
(Alloc.Const.min_with_uniqueness Uniqueness.Const.Shared)
596+
in
594597
let ret_mode =
595598
match rest with
596599
| [] -> ret_mode

0 commit comments

Comments
 (0)