@@ -20,10 +20,10 @@ open Asttypes
20
20
open Parsetree
21
21
open Layouts
22
22
open Types
23
+ open Mode
23
24
open Typedtree
24
25
open Btype
25
26
open Ctype
26
- open Mode
27
27
open Uniqueness_analysis
28
28
29
29
type comprehension_type =
@@ -422,7 +422,6 @@ let _modality_box_right global_flag mode =
422
422
|> le_many_right
423
423
| Unrestricted -> mode
424
424
425
-
426
425
(* Describes how a modality affects field projection. Returns the mode
427
426
of the projection given the mode of the record. *)
428
427
let modality_unbox_left global_flag mode =
@@ -456,7 +455,6 @@ let mode_default mode =
456
455
457
456
let mode_legacy = mode_default Value. legacy
458
457
459
-
460
458
(* used when entering a function;
461
459
mode is the mode of the function region *)
462
460
let mode_return mode =
@@ -473,10 +471,11 @@ let mode_region mode =
473
471
closure_context = None ;
474
472
}
475
473
476
- let mode_max = mode_default Value. max
474
+ let mode_max =
475
+ mode_default Value. max
477
476
478
477
let mode_max_with_position position =
479
- {mode_max with position}
478
+ { mode_max with position }
480
479
481
480
let mode_subcomponent expected_mode =
482
481
let mode = alloc_as_value (value_to_alloc_r2g expected_mode.mode) in
@@ -505,10 +504,11 @@ let mode_strictly_local expected_mode =
505
504
506
505
let mode_unique expected_mode =
507
506
let mode = le_unique_right expected_mode.mode in
508
- {expected_mode with mode}
507
+ { expected_mode with mode }
509
508
510
509
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}
512
512
513
513
let mode_tailcall_function mode =
514
514
{ (mode_default mode) with
@@ -521,8 +521,8 @@ let mode_tailcall_argument mode =
521
521
522
522
let mode_partial_application expected_mode =
523
523
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;
526
526
closure_context = Some Partial_application }
527
527
528
528
@@ -780,7 +780,7 @@ let mode_cross_to_min env ty mode =
780
780
781
781
let expect_mode_cross env ty (expected_mode : expected_mode ) =
782
782
if mode_cross env ty then
783
- { expected_mode with
783
+ { expected_mode with
784
784
mode = Value. disallow_left Value. max;
785
785
exact = None ;
786
786
strictly_local = false }
@@ -4486,9 +4486,9 @@ let unique_use ~loc ~env mode_l mode_r =
4486
4486
let uniqueness = Uniqueness. disallow_left (Value. uniqueness mode_r) in
4487
4487
let linearity = Linearity. disallow_right (Value. linearity mode_l) in
4488
4488
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 *)
4492
4492
(match Uniqueness. submode Uniqueness. shared uniqueness with
4493
4493
| Ok () -> ()
4494
4494
| Error () ->
@@ -5292,7 +5292,6 @@ and type_expect_
5292
5292
else record.exp_type
5293
5293
in
5294
5294
let (label_loc, label, newval) =
5295
- (* rmode won't be used because mutable field *)
5296
5295
type_label_exp false env (mode_default rmode) loc
5297
5296
ty_record (lid, label, snewval) in
5298
5297
unify_exp env record ty_record;
@@ -6115,10 +6114,11 @@ and type_ident env ?(recarg=Rejected) lid =
6115
6114
let ty, mode = instance_prim_mode prim (instance desc.val_type) in
6116
6115
begin match prim.prim_native_repr_res, mode with
6117
6116
(* 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])
6122
6122
| _ -> ()
6123
6123
end ;
6124
6124
ty, Id_prim (Option. map Locality. disallow_right mode)
@@ -6311,7 +6311,6 @@ and type_function
6311
6311
exp_desc =
6312
6312
Texp_function
6313
6313
{ arg_label; param; cases; partial; region; curry; warnings;
6314
-
6315
6314
arg_mode = Alloc. disallow_right arg_mode; arg_sort;
6316
6315
alloc_mode = Alloc. disallow_left alloc_mode; ret_sort };
6317
6316
exp_loc = loc; exp_extra = [] ;
@@ -8441,7 +8440,9 @@ let escaping_hint failure_reason submode_reason
8441
8440
let rec loop sureness n ty =
8442
8441
match get_desc ty with
8443
8442
| 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
8445
8446
| Some Global ->
8446
8447
Some (n+ 1 , true )
8447
8448
| (None | Some Local ) as res_mode ->
@@ -8945,19 +8946,19 @@ let report_error ~loc env = function
8945
8946
Printtyp. type_expr ty
8946
8947
| Submode_failed (fail_reason, submode_reason, closure_context, shared_context)
8947
8948
->
8948
- let sub =
8949
- match fail_reason with
8950
- | `Linearity | `Uniqueness ->
8949
+ let sub =
8950
+ match fail_reason with
8951
+ | `Linearity | `Uniqueness ->
8951
8952
sharedness_hint fail_reason submode_reason shared_context
8952
- | `Regionality ->
8953
+ | `Regionality ->
8953
8954
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
8961
8962
| Local_application_complete (lbl , loc_kind ) ->
8962
8963
let sub =
8963
8964
match loc_kind with
0 commit comments