@@ -930,52 +930,29 @@ let has_poly_constraint spat =
930
930
end
931
931
| _ -> false
932
932
933
- (* * Cross a left mode according to a type wrapped in modalities. *)
934
- let mode_cross_left_value env ty ?modalities mode =
935
- if not (is_principal ty) then
936
- Value. disallow_right mode
937
- else begin
938
- let jkind = type_jkind_purely env ty in
939
- let jkind_of_type = type_jkind_purely_if_principal env in
940
- let crossing = Jkind. get_mode_crossing ~jkind_of_type jkind in
941
- let crossing =
942
- match modalities with
943
- | None -> crossing
944
- | Some m -> Crossing. modality m crossing
945
- in
946
- mode
947
- |> Value. disallow_right
948
- |> Crossing. apply_left crossing
949
- end
950
-
951
933
let actual_mode_cross_left env ty (actual_mode : Env.actual_mode )
952
934
: Env.actual_mode =
953
- let mode = mode_cross_left_value env ty actual_mode.mode in
935
+ let mode = cross_left env ty actual_mode.mode in
954
936
{actual_mode with mode}
955
937
956
938
(* * Mode cross a mode whose monadic fragment is a right mode, and whose comonadic
957
939
fragment is a left mode. *)
958
940
let alloc_mode_cross_to_max_min env ty { monadic; comonadic } =
959
941
let monadic = Alloc.Monadic. disallow_left monadic in
960
942
let comonadic = Alloc.Comonadic. disallow_right comonadic in
961
- if not (is_principal ty) then { monadic; comonadic } else
962
- let jkind = type_jkind_purely env ty in
963
- let jkind_of_type = type_jkind_purely_if_principal env in
964
- let crossing = Jkind. get_mode_crossing ~jkind_of_type jkind in
943
+ let crossing = crossing_of_ty env ty in
965
944
Crossing. apply_left_right_alloc crossing { monadic; comonadic }
966
945
967
946
(* * Mode cross a right mode *)
968
947
(* This is very similar to Ctype.mode_cross_right. Any bugs here are likely bugs
969
948
there, too. *)
970
949
let expect_mode_cross_jkind env jkind (expected_mode : expected_mode ) =
971
- let jkind_of_type = type_jkind_purely_if_principal env in
972
- let crossing = Jkind. get_mode_crossing ~jkind_of_type jkind in
950
+ let crossing = crossing_of_jkind env jkind in
973
951
mode_morph (Crossing. apply_right crossing) expected_mode
974
952
975
953
let expect_mode_cross env ty (expected_mode : expected_mode ) =
976
- if not (is_principal ty) then expected_mode else
977
- let jkind = type_jkind_purely env ty in
978
- expect_mode_cross_jkind env jkind expected_mode
954
+ let crossing = crossing_of_ty env ty in
955
+ mode_morph (Crossing. apply_right crossing) expected_mode
979
956
980
957
(* * The expected mode for objects *)
981
958
let mode_object = expect_mode_cross_jkind Env. empty Jkind. for_object mode_legacy
@@ -1018,7 +995,7 @@ let check_construct_mutability ~loc ~env mutability ty ?modalities block_mode =
1018
995
| Immutable -> ()
1019
996
| Mutable m0 ->
1020
997
let m0 = mutable_mode m0 in
1021
- let m0 = mode_cross_left_value env ty ?modalities m0 in
998
+ let m0 = cross_left env ty ?modalities m0 in
1022
999
submode ~loc ~env m0 block_mode
1023
1000
1024
1001
(* * The [expected_mode] of the record when projecting a mutable field. *)
@@ -2815,7 +2792,7 @@ and type_pat_aux
2815
2792
| Ppat_var name ->
2816
2793
let ty = instance expected_ty in
2817
2794
let alloc_mode =
2818
- mode_cross_left_value !! penv expected_ty alloc_mode.mode
2795
+ cross_left !! penv expected_ty alloc_mode.mode
2819
2796
in
2820
2797
let id, uid =
2821
2798
enter_variable tps loc name alloc_mode ty sp.ppat_attributes
@@ -2858,7 +2835,7 @@ and type_pat_aux
2858
2835
| Ppat_alias (sq , name ) ->
2859
2836
let q = type_pat tps Value sq expected_ty in
2860
2837
let ty_var, mode = solve_Ppat_alias ~mode: alloc_mode.mode !! penv q in
2861
- let mode = mode_cross_left_value !! penv expected_ty mode in
2838
+ let mode = cross_left !! penv expected_ty mode in
2862
2839
let id, uid =
2863
2840
enter_variable ~is_as_variable: true tps name.loc name mode ty_var
2864
2841
sp.ppat_attributes
@@ -6052,14 +6029,14 @@ and type_expect_
6052
6029
match is_float_boxing with
6053
6030
| true ->
6054
6031
let alloc_mode, argument_mode = register_allocation expected_mode in
6055
- let mode = mode_cross_left_value env Predef. type_unboxed_float mode in
6032
+ let mode = cross_left env Predef. type_unboxed_float mode in
6056
6033
submode ~loc ~env mode argument_mode;
6057
6034
let uu =
6058
6035
unique_use ~loc ~env mode (as_single_mode argument_mode)
6059
6036
in
6060
6037
Boxing (alloc_mode, uu)
6061
6038
| false ->
6062
- let mode = mode_cross_left_value env ty_arg mode in
6039
+ let mode = cross_left env ty_arg mode in
6063
6040
submode ~loc ~env mode expected_mode;
6064
6041
let uu = unique_use ~loc ~env mode (as_single_mode expected_mode) in
6065
6042
Non_boxing uu
@@ -6098,7 +6075,7 @@ and type_expect_
6098
6075
(Error (loc, env, Record_projection_not_rep (record.exp_type, err)))
6099
6076
in
6100
6077
let mode = Modality.Value.Const. apply label.lbl_modalities rmode in
6101
- let mode = mode_cross_left_value env ty_arg mode in
6078
+ let mode = cross_left env ty_arg mode in
6102
6079
submode ~loc ~env mode expected_mode;
6103
6080
let uu = unique_use ~loc ~env mode (as_single_mode expected_mode) in
6104
6081
rue {
@@ -7054,7 +7031,7 @@ and type_ident env ?(recarg=Rejected) lid =
7054
7031
7055
7032
Therefore, we need to cross modes upon look-up. Ideally that should be done in
7056
7033
[Env], but that is difficult due to cyclic dependency between jkind and env. *)
7057
- let mode = mode_cross_left_value env desc.val_type mode in
7034
+ let mode = cross_left env desc.val_type mode in
7058
7035
(* There can be locks between the definition and a use of a value. For
7059
7036
example, if a function closes over a value, there will be Closure_lock between
7060
7037
the value's definition and the value's use in the function. Walking the locks
@@ -7525,7 +7502,7 @@ and type_label_access
7525
7502
let label =
7526
7503
wrap_disambiguate " This expression has" (mk_expected ty_exp)
7527
7504
(label_disambiguate record_form usage lid env expected_type) labels in
7528
- (record, mode, label, expected_type)
7505
+ (record, Mode.Value. disallow_right mode, label, expected_type)
7529
7506
7530
7507
(* Typing format strings for printing or reading.
7531
7508
These formats are used by functions in modules Printf, Format, and Scanf.
@@ -8191,15 +8168,16 @@ and type_application env app_loc expected_mode position_and_mode
8191
8168
filter_arrow_mono env (instance funct.exp_type) Nolabel
8192
8169
) ~post: (fun {ty_ret; _} -> generalize_structure ty_ret)
8193
8170
in
8171
+ let ret_mode = Alloc. disallow_right ret_mode in
8194
8172
let type_sort ~why ty =
8195
8173
match Ctype. type_sort ~why ~fixed: false env ty with
8196
8174
| Ok sort -> sort
8197
8175
| Error err -> raise (Error (app_loc, env, Function_type_not_rep (ty, err)))
8198
8176
in
8199
8177
let arg_sort = type_sort ~why: Function_argument ty_arg in
8200
- let ap_mode = Locality. disallow_right ( Alloc. proj (Comonadic Areality ) ret_mode) in
8178
+ let ap_mode = Alloc. proj (Comonadic Areality ) ret_mode in
8201
8179
let mode_res =
8202
- mode_cross_left_value env ty_ret (alloc_as_value ret_mode)
8180
+ cross_left env ty_ret (alloc_as_value ret_mode)
8203
8181
in
8204
8182
submode ~loc: app_loc ~env ~reason: Other
8205
8183
mode_res expected_mode;
@@ -8256,9 +8234,10 @@ and type_application env app_loc expected_mode position_and_mode
8256
8234
ty_ret, mode_ret, args, position_and_mode
8257
8235
end ~post: (fun (ty_ret , _ , _ , _ ) -> generalize_structure ty_ret)
8258
8236
in
8259
- let ap_mode = Locality. disallow_right (Alloc. proj (Comonadic Areality ) mode_ret) in
8237
+ let mode_ret = Alloc. disallow_right mode_ret in
8238
+ let ap_mode = Alloc. proj (Comonadic Areality ) mode_ret in
8260
8239
let mode_ret =
8261
- mode_cross_left_value env ty_ret (alloc_as_value mode_ret)
8240
+ cross_left env ty_ret (alloc_as_value mode_ret)
8262
8241
in
8263
8242
submode ~loc: app_loc ~env ~reason: (Application ty_ret)
8264
8243
mode_ret expected_mode;
0 commit comments