Skip to content

Commit 947eefe

Browse files
committed
trivial changes
1 parent f4fcb3e commit 947eefe

13 files changed

+37
-67
lines changed

ocaml/.depend

+1
Original file line numberDiff line numberDiff line change
@@ -991,6 +991,7 @@ typing/includecore.cmi : \
991991
typing/types.cmi \
992992
typing/typedtree.cmi \
993993
typing/path.cmi \
994+
typing/mode.cmi \
994995
parsing/location.cmi \
995996
typing/jkind.cmi \
996997
typing/ident.cmi \

ocaml/ocamldoc/odoc_sig.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ module Analyser =
492492
let record comments
493493
{ Typedtree.ld_id; ld_mutable; ld_type; ld_loc; ld_attributes } =
494494
get_field env comments @@
495-
{Types.ld_id; ld_mutable; ld_global = Unrestricted;
495+
{Types.ld_id; ld_mutable; ld_modalities = Mode.Modality.Vector.id;
496496
ld_jkind=Jkind.any ~why:Dummy_jkind (* ignored *);
497497
ld_type=ld_type.Typedtree.ctyp_type;
498498
ld_loc; ld_attributes; ld_uid=Types.Uid.internal_not_actually_unique} in

ocaml/typing/ctype.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3123,7 +3123,7 @@ and mcomp_record_description type_pairs env =
31233123
mcomp type_pairs env l1.ld_type l2.ld_type;
31243124
if Ident.name l1.ld_id = Ident.name l2.ld_id &&
31253125
l1.ld_mutable = l2.ld_mutable &&
3126-
l1.ld_global = l2.ld_global
3126+
l1.ld_modalities = l2.ld_modalities
31273127
then iter xs ys
31283128
else raise Incompatible
31293129
| [], [] -> ()

ocaml/typing/ctype.mli

+1-1
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ type existential_treatment =
186186

187187
val instance_constructor: existential_treatment ->
188188
constructor_description ->
189-
(type_expr * Global_flag.t) list * type_expr * type_expr list
189+
(type_expr * Modality.Vector.t) list * type_expr * type_expr list
190190
(* Same, for a constructor. Also returns existentials. *)
191191
val instance_parameterized_type:
192192
?keep_names:bool ->

ocaml/typing/datarepr.ml

+3-3
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ let constructor_args ~current_unit priv cd_args cd_res path rep =
9595
}
9696
in
9797
existentials,
98-
[ newgenconstr path type_params, Global_flag.Unrestricted ],
98+
[ newgenconstr path type_params, Modality.Vector.id ],
9999
Some tdecl
100100

101101
let constructor_descrs ~current_unit ty_path decl cstrs rep =
@@ -199,7 +199,7 @@ let none =
199199

200200
let dummy_label =
201201
{ lbl_name = ""; lbl_res = none; lbl_arg = none;
202-
lbl_mut = Immutable; lbl_global = Unrestricted;
202+
lbl_mut = Immutable; lbl_modalities = Modality.Vector.id;
203203
lbl_jkind = Jkind.any ~why:Dummy_jkind;
204204
lbl_num = -1; lbl_pos = -1; lbl_all = [||];
205205
lbl_repres = Record_unboxed;
@@ -220,7 +220,7 @@ let label_descrs ty_res lbls repres priv =
220220
lbl_res = ty_res;
221221
lbl_arg = l.ld_type;
222222
lbl_mut = l.ld_mutable;
223-
lbl_global = l.ld_global;
223+
lbl_modalities = l.ld_modalities;
224224
lbl_jkind = l.ld_jkind;
225225
lbl_pos = if is_void then lbl_pos_void else pos;
226226
lbl_num = num;

ocaml/typing/outcometree.mli

+3-5
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,7 @@ type out_mutable_or_global =
7171
| Ogom_global
7272
| Ogom_immutable
7373

74-
type out_global =
75-
| Ogf_global
76-
| Ogf_unrestricted
74+
type out_modality = Ogf_global
7775

7876
(* should be empty if all the jkind annotations are missing *)
7977
type out_vars_jkinds = (string * out_jkind option) list
@@ -102,7 +100,7 @@ type out_type =
102100

103101
and out_constructor = {
104102
ocstr_name: string;
105-
ocstr_args: (out_type * out_global) list;
103+
ocstr_args: (out_type * out_modality list) list;
106104
ocstr_return_type: (out_vars_jkinds * out_type) option;
107105
}
108106

@@ -176,7 +174,7 @@ and out_extension_constructor =
176174
{ oext_name: string;
177175
oext_type_name: string;
178176
oext_type_params: string list;
179-
oext_args: (out_type * out_global) list;
177+
oext_args: (out_type * out_modality list) list;
180178
oext_ret_type: (out_vars_jkinds * out_type) option;
181179
oext_private: Asttypes.private_flag }
182180
and out_type_extension =

ocaml/typing/predef.ml

+4-4
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ let build_initial_env add_type add_extension empty_env =
265265
add_extension id
266266
{ ext_type_path = path_exn;
267267
ext_type_params = [];
268-
ext_args = Cstr_tuple (List.map (fun x -> (x, Global_flag.Unrestricted)) args);
268+
ext_args = Cstr_tuple (List.map (fun x -> (x, Modality.Vector.id)) args);
269269
ext_arg_jkinds = jkinds;
270270
ext_constant = args = [];
271271
ext_ret_type = None;
@@ -310,8 +310,8 @@ let build_initial_env add_type add_extension empty_env =
310310
~separability:Separability.Ind
311311
~kind:(fun tvar ->
312312
variant [cstr ident_nil [];
313-
cstr ident_cons [tvar, Unrestricted;
314-
type_list tvar, Unrestricted]]
313+
cstr ident_cons [tvar, Modality.Vector.id;
314+
type_list tvar, Modality.Vector.id]]
315315
[| [| |]; [| list_argument_jkind;
316316
Jkind.value ~why:Boxed_variant |] |] )
317317
~jkind:(Jkind.value ~why:Boxed_variant)
@@ -320,7 +320,7 @@ let build_initial_env add_type add_extension empty_env =
320320
~variance:Variance.covariant
321321
~separability:Separability.Ind
322322
~kind:(fun tvar ->
323-
variant [cstr ident_none []; cstr ident_some [tvar, Unrestricted]]
323+
variant [cstr ident_none []; cstr ident_some [tvar, Modality.Vector.id]]
324324
[| [| |]; [| option_argument_jkind |] |])
325325
~jkind:(Jkind.value ~why:Boxed_variant)
326326
|> add_type ident_string

ocaml/typing/subst.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ let label_declaration copy_scope s l =
400400
{
401401
ld_id = l.ld_id;
402402
ld_mutable = l.ld_mutable;
403-
ld_global = l.ld_global;
403+
ld_modalities = l.ld_modalities;
404404
ld_jkind = apply_prepare_jkind s l.ld_jkind l.ld_loc;
405405
ld_type = typexp copy_scope s l.ld_loc l.ld_type;
406406
ld_loc = loc s l.ld_loc;

ocaml/typing/typecore.ml

+10-39
Original file line numberDiff line numberDiff line change
@@ -418,12 +418,6 @@ let meet_global mode =
418418
let meet_unique mode =
419419
Value.meet [mode; (Value.max_with_uniqueness Uniqueness.unique)]
420420

421-
let meet_many mode =
422-
Value.meet [mode; (Value.max_with_linearity Linearity.many)]
423-
424-
let join_shared mode =
425-
Value.join [mode; Value.min_with_uniqueness Uniqueness.shared]
426-
427421
let value_regional_to_local mode =
428422
mode
429423
|> value_to_alloc_r2l
@@ -434,29 +428,6 @@ let value_regional_to_global mode =
434428
|> value_to_alloc_r2g
435429
|> alloc_as_value
436430

437-
(* Describes how a modality affects field projection. Returns the mode
438-
of the projection given the mode of the record. *)
439-
let modality_unbox_left global_flag mode =
440-
let mode = Value.disallow_right mode in
441-
match global_flag with
442-
| Global_flag.Global ->
443-
mode
444-
|> Value.meet_with_regionality Regionality.Const.Global
445-
|> join_shared
446-
|> Value.meet_with_linearity Linearity.Const.Many
447-
| Global_flag.Unrestricted -> mode
448-
449-
(* Describes how a modality affects record construction. Gives the
450-
expected mode of the field given the expected mode of the record. *)
451-
let modality_box_right global_flag mode =
452-
match global_flag with
453-
| Global_flag.Global ->
454-
mode
455-
|> meet_global
456-
|> Value.join_with_uniqueness Uniqueness.Const.max
457-
|> meet_many
458-
| Global_flag.Unrestricted -> mode
459-
460431
let mode_default mode =
461432
{ position = RNontail;
462433
closure_context = None;
@@ -495,8 +466,8 @@ let mode_subcomponent expected_mode =
495466
let mode = alloc_as_value (value_to_alloc_r2g expected_mode.mode) in
496467
mode_default mode
497468

498-
let mode_box_modality gf expected_mode =
499-
mode_default (modality_box_right gf expected_mode.mode)
469+
let mode_box_modalities gf expected_mode =
470+
mode_default (Modality.Vector.apply_right gf expected_mode.mode)
500471

501472
let mode_global expected_mode =
502473
let mode = meet_global expected_mode.mode in
@@ -2672,7 +2643,7 @@ and type_pat_aux
26722643
let args =
26732644
List.map2
26742645
(fun p (ty, gf) ->
2675-
let alloc_mode = modality_unbox_left gf alloc_mode.mode in
2646+
let alloc_mode = Modality.Vector.apply_left gf alloc_mode.mode in
26762647
let alloc_mode = simple_pat_mode alloc_mode in
26772648
type_pat ~alloc_mode tps Value p ty)
26782649
sargs (List.combine ty_args_ty ty_args_gf)
@@ -2716,7 +2687,7 @@ and type_pat_aux
27162687
let ty_arg =
27172688
solve_Ppat_record_field ~refine loc env label label_lid record_ty in
27182689
let alloc_mode =
2719-
modality_unbox_left label.lbl_global alloc_mode.mode
2690+
Modality.Vector.apply_left label.lbl_modalities alloc_mode.mode
27202691
in
27212692
let alloc_mode = simple_pat_mode alloc_mode in
27222693
(label_lid, label, type_pat tps Value ~alloc_mode sarg ty_arg)
@@ -5623,14 +5594,14 @@ and type_expect_
56235594
unify_exp_types loc env ty_arg1 ty_arg2;
56245595
with_explanation (fun () ->
56255596
unify_exp_types loc env (instance ty_expected) ty_res2);
5626-
let mode = modality_unbox_left lbl.lbl_global mode in
5597+
let mode = Modality.Vector.apply_left lbl.lbl_modalities mode in
56275598
let rmode =
56285599
(* We skip a potential [mode_subcomponent] since
56295600
it does not affect uniqueness. *)
56305601
expected_mode
56315602
in
56325603
let expected_mode =
5633-
mode_box_modality lbl.lbl_global rmode
5604+
mode_box_modalities lbl.lbl_modalities rmode
56345605
in
56355606
Kept (ty_arg1, lbl.lbl_mut,
56365607
unique_use ~loc ~env mode expected_mode.mode)
@@ -5671,7 +5642,7 @@ and type_expect_
56715642
| Record_float -> Some (register_allocation expected_mode)
56725643
| _ -> None
56735644
in
5674-
let mode = modality_unbox_left label.lbl_global rmode in
5645+
let mode = Modality.Vector.apply_left label.lbl_modalities rmode in
56755646
let ty_arg =
56765647
with_local_level_if_principal begin fun () ->
56775648
(* ty_arg is the type of field *)
@@ -5693,7 +5664,7 @@ and type_expect_
56935664
exp_attributes = sexp.pexp_attributes;
56945665
exp_env = env }
56955666
| Pexp_setfield(srecord, lid, snewval) ->
5696-
let (record, rmode, label, expected_type) =
5667+
let (record, (rmode : Value.lr), label, expected_type) =
56975668
type_label_access env srecord Env.Mutation lid in
56985669
let ty_record =
56995670
if expected_type = None
@@ -7158,7 +7129,7 @@ and type_label_exp create env (expected_mode : expected_mode) loc ty_expected
71587129
expected_mode
71597130
| _ -> mode_subcomponent expected_mode
71607131
in
7161-
let arg_mode = mode_box_modality label.lbl_global rmode in
7132+
let arg_mode = mode_box_modalities label.lbl_modalities rmode in
71627133
(* #4682: we try two type-checking approaches for [arg] using backtracking:
71637134
- first try: we try with [ty_arg] as expected type;
71647135
- second try; if that fails, we backtrack and try without
@@ -7741,7 +7712,7 @@ and type_construct env (expected_mode : expected_mode) loc lid sarg
77417712
let args =
77427713
List.map2
77437714
(fun e ((ty, gf),t0) ->
7744-
let argument_mode = mode_box_modality gf argument_mode in
7715+
let argument_mode = mode_box_modalities gf argument_mode in
77457716
type_argument ~recarg env argument_mode e ty t0)
77467717
sargs (List.combine ty_args ty_args0)
77477718
in

ocaml/typing/typedtree.ml

+2-2
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,7 @@ and label_declaration =
663663
ld_id: Ident.t;
664664
ld_name: string loc;
665665
ld_mutable: mutable_flag;
666-
ld_global: Global_flag.t;
666+
ld_modalities: Modality.Vector.t;
667667
ld_type: core_type;
668668
ld_loc: Location.t;
669669
ld_attributes: attribute list;
@@ -681,7 +681,7 @@ and constructor_declaration =
681681
}
682682

683683
and constructor_arguments =
684-
| Cstr_tuple of (core_type * Global_flag.t) list
684+
| Cstr_tuple of (core_type * Modality.Vector.t) list
685685
| Cstr_record of label_declaration list
686686

687687
and type_extension =

ocaml/typing/typedtree.mli

+2-2
Original file line numberDiff line numberDiff line change
@@ -893,7 +893,7 @@ and label_declaration =
893893
ld_id: Ident.t;
894894
ld_name: string loc;
895895
ld_mutable: mutable_flag;
896-
ld_global: Mode.Global_flag.t;
896+
ld_modalities: Mode.Modality.Vector.t;
897897
ld_type: core_type;
898898
ld_loc: Location.t;
899899
ld_attributes: attributes;
@@ -911,7 +911,7 @@ and constructor_declaration =
911911
}
912912

913913
and constructor_arguments =
914-
| Cstr_tuple of (core_type * Mode.Global_flag.t) list
914+
| Cstr_tuple of (core_type * Mode.Modality.Vector.t) list
915915
| Cstr_record of label_declaration list
916916

917917
and type_extension =

ocaml/typing/types.ml

+4-4
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ and label_declaration =
277277
{
278278
ld_id: Ident.t;
279279
ld_mutable: mutable_flag;
280-
ld_global: Mode.Global_flag.t;
280+
ld_modalities: Mode.Modality.Vector.t;
281281
ld_type: type_expr;
282282
ld_jkind : Jkind.t;
283283
ld_loc: Location.t;
@@ -296,7 +296,7 @@ and constructor_declaration =
296296
}
297297

298298
and constructor_arguments =
299-
| Cstr_tuple of (type_expr * Mode.Global_flag.t) list
299+
| Cstr_tuple of (type_expr * Mode.Modality.Vector.t) list
300300
| Cstr_record of label_declaration list
301301

302302
type extension_constructor =
@@ -516,7 +516,7 @@ type constructor_description =
516516
{ cstr_name: string; (* Constructor name *)
517517
cstr_res: type_expr; (* Type of the result *)
518518
cstr_existentials: type_expr list; (* list of existentials *)
519-
cstr_args: (type_expr * Mode.Global_flag.t) list; (* Type of the arguments *)
519+
cstr_args: (type_expr * Mode.Modality.Vector.t) list; (* Type of the arguments *)
520520
cstr_arg_jkinds: Jkind.t array; (* Jkinds of the arguments *)
521521
cstr_arity: int; (* Number of arguments *)
522522
cstr_tag: tag; (* Tag for heap blocks *)
@@ -602,7 +602,7 @@ type label_description =
602602
lbl_res: type_expr; (* Type of the result *)
603603
lbl_arg: type_expr; (* Type of the argument *)
604604
lbl_mut: mutable_flag; (* Is this a mutable field? *)
605-
lbl_global: Mode.Global_flag.t; (* Is this a global field? *)
605+
lbl_modalities: Mode.Modality.Vector.t;(* Is this a global field? *)
606606
lbl_jkind : Jkind.t; (* Jkind of the argument *)
607607
lbl_pos: int; (* Position in block *)
608608
lbl_num: int; (* Position in type *)

ocaml/typing/types.mli

+4-4
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ and label_declaration =
560560
{
561561
ld_id: Ident.t;
562562
ld_mutable: mutable_flag;
563-
ld_global: Mode.Global_flag.t;
563+
ld_modalities: Mode.Modality.Vector.t;
564564
ld_type: type_expr;
565565
ld_jkind : Jkind.t;
566566
ld_loc: Location.t;
@@ -579,7 +579,7 @@ and constructor_declaration =
579579
}
580580

581581
and constructor_arguments =
582-
| Cstr_tuple of (type_expr * Mode.Global_flag.t) list
582+
| Cstr_tuple of (type_expr * Mode.Modality.Vector.t) list
583583
| Cstr_record of label_declaration list
584584

585585
val tys_of_constr_args : constructor_arguments -> type_expr list
@@ -753,7 +753,7 @@ type constructor_description =
753753
{ cstr_name: string; (* Constructor name *)
754754
cstr_res: type_expr; (* Type of the result *)
755755
cstr_existentials: type_expr list; (* list of existentials *)
756-
cstr_args: (type_expr * Mode.Global_flag.t) list; (* Type of the arguments *)
756+
cstr_args: (type_expr * Mode.Modality.Vector.t) list; (* Type of the arguments *)
757757
cstr_arg_jkinds: Jkind.t array; (* Jkinds of the arguments *)
758758
cstr_arity: int; (* Number of arguments *)
759759
cstr_tag: tag; (* Tag for heap blocks *)
@@ -790,7 +790,7 @@ type label_description =
790790
lbl_res: type_expr; (* Type of the result *)
791791
lbl_arg: type_expr; (* Type of the argument *)
792792
lbl_mut: mutable_flag; (* Is this a mutable field? *)
793-
lbl_global: Mode.Global_flag.t; (* Is this a global field? *)
793+
lbl_modalities: Mode.Modality.Vector.t; (* Modalities on the field *)
794794
lbl_jkind : Jkind.t; (* Jkind of the argument *)
795795
lbl_pos: int; (* Position in block *)
796796
lbl_num: int; (* Position in the type *)

0 commit comments

Comments
 (0)