Skip to content

Commit 2a973e5

Browse files
committed
remove @no_mutable_implied_modalities
1 parent 2f81160 commit 2a973e5

File tree

16 files changed

+58
-88
lines changed

16 files changed

+58
-88
lines changed

parsing/builtin_attributes.ml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ let builtin_attrs =
113113
; "only_generative_effects"
114114
; "error_message"
115115
; "layout_poly"
116-
; "no_mutable_implied_modalities"
117116
; "or_null_reexport"
118117
; "no_recursive_modalities"
119118
; "jane.non_erasable.instances"
@@ -650,9 +649,6 @@ let parse_standard_implementation_attributes attr =
650649
zero_alloc_attribute ~in_signature:false attr;
651650
unsafe_allow_any_mode_crossing_attribute attr
652651

653-
let has_no_mutable_implied_modalities attrs =
654-
has_attribute "no_mutable_implied_modalities" attrs
655-
656652
let has_local_opt attrs =
657653
has_attribute "local_opt" attrs
658654

parsing/builtin_attributes.mli

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,6 @@ val parse_standard_implementation_attributes : Parsetree.attribute -> unit
212212
val curry_attr_name : string
213213
val curry_attr : Location.t -> Parsetree.attribute
214214

215-
val has_no_mutable_implied_modalities: Parsetree.attributes -> bool
216215
val has_local_opt: Parsetree.attributes -> bool
217216
val has_layout_poly: Parsetree.attributes -> bool
218217
val has_curry: Parsetree.attributes -> bool

testsuite/tests/parsetree/source_jane_street.ml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -601,8 +601,8 @@ type t = { x : string @@ global
601601
type t1 = { mutable x : float
602602
; mutable f : float -> float }
603603

604-
type t2 = { mutable x : float [@no_mutable_implied_modalities]
605-
; mutable f : float -> float [@no_mutable_implied_modalities] }
604+
type t2 = { mutable x : float @@ local once
605+
; mutable f : float -> float @@ local once }
606606

607607
[%%expect{|
608608
type t =
@@ -614,7 +614,10 @@ type t = {
614614
z : string @@ global many;
615615
}
616616
type t1 = { mutable x : float; mutable f : float -> float; }
617-
type t2 = { mutable x : float; mutable f : float -> float; }
617+
type t2 = {
618+
mutable x : float @@ local once;
619+
mutable f : float -> float @@ local once;
620+
}
618621
|}]
619622

620623
let f1 (x @ local) (f @ once) : t1 = exclave_ { x; f }

testsuite/tests/typing-modes/mutable.ml

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,9 @@ type r = {mutable s : string @@ unyielding local}
6464
type r = { mutable s : string @@ local; }
6565
|}]
6666

67-
(* [@no_mutable_implied_modalities] disables those implied modalities on the
68-
comonadic axes, and allows us to test [mutable] alone *)
69-
70-
(* Note the attribute is not printed back, which might be confusing.
71-
Considering this is a short-term workaround, let's not worry too much. *)
72-
type 'a r = {mutable s : 'a [@no_mutable_implied_modalities]}
67+
type 'a r = {mutable s : 'a @@ local}
7368
[%%expect{|
74-
type 'a r = { mutable s : 'a; }
69+
type 'a r = { mutable s : 'a @@ local; }
7570
|}]
7671

7772
(* We can now construct a local record using a local field. *)
@@ -104,11 +99,11 @@ let foo (local_ r) =
10499
val foo : local_ string r -> unit = <fun>
105100
|}]
106101

107-
(* We can still add modalities explicitly. Of course, the print-back is
108-
confusing. *)
109-
type r' = {mutable s' : string @@ global [@no_mutable_implied_modalities]}
102+
(* We can still add modalities explicitly. But they might be omitted if they are
103+
the same as the mutable-implied ones. *)
104+
type r' = {mutable s' : string @@ global}
110105
[%%expect{|
111-
type r' = { mutable global_ s' : string; }
106+
type r' = { mutable s' : string; }
112107
|}]
113108

114109
let foo (local_ s') = exclave_ {s'}
@@ -152,7 +147,7 @@ Error: This value is "aliased" but expected to be "unique".
152147
|}]
153148

154149
module M : sig
155-
type t = { mutable s : string [@no_mutable_implied_modalities] }
150+
type t = { mutable s : string @@ local }
156151
end = struct
157152
type t = { mutable s : string }
158153
end
@@ -165,39 +160,39 @@ Error: Signature mismatch:
165160
Modules do not match:
166161
sig type t = { mutable s : string; } end
167162
is not included in
168-
sig type t = { mutable s : string; } end
163+
sig type t = { mutable s : string @@ local; } end
169164
Type declarations do not match:
170165
type t = { mutable s : string; }
171166
is not included in
172-
type t = { mutable s : string; }
167+
type t = { mutable s : string @@ local; }
173168
Fields do not match:
174169
"mutable s : string;"
175170
is not the same as:
176-
"mutable s : string;"
171+
"mutable s : string @@ local;"
177172
The first is global and the second is not.
178173
|}]
179174

180175
module M : sig
181176
type t = { mutable s : string }
182177
end = struct
183-
type t = { mutable s : string [@no_mutable_implied_modalities] }
178+
type t = { mutable s : string @@ local}
184179
end
185180
[%%expect{|
186181
Lines 3-5, characters 6-3:
187182
3 | ......struct
188-
4 | type t = { mutable s : string [@no_mutable_implied_modalities] }
183+
4 | type t = { mutable s : string @@ local}
189184
5 | end
190185
Error: Signature mismatch:
191186
Modules do not match:
192-
sig type t = { mutable s : string; } end
187+
sig type t = { mutable s : string @@ local; } end
193188
is not included in
194189
sig type t = { mutable s : string; } end
195190
Type declarations do not match:
196-
type t = { mutable s : string; }
191+
type t = { mutable s : string @@ local; }
197192
is not included in
198193
type t = { mutable s : string; }
199194
Fields do not match:
200-
"mutable s : string;"
195+
"mutable s : string @@ local;"
201196
is not the same as:
202197
"mutable s : string;"
203198
The second is global and the first is not.

testsuite/tests/warnings/w53.compilers.reference

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
File "w53.ml", line 9, characters 24-53:
2-
9 | type r0 = {s : string [@no_mutable_implied_modalities]} (* rejected *)
3-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4-
Warning 53 [misplaced-attribute]: the "no_mutable_implied_modalities" attribute cannot appear in this context
5-
61
File "w53.ml", line 15, characters 16-21:
72
15 | val x : int [@alert foo "foo"] (* rejected *)
83
^^^^^

testsuite/tests/warnings/w53.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
check-ocamlc.byte-output;
77
*)
88

9-
type r0 = {s : string [@no_mutable_implied_modalities]} (* rejected *)
10-
type r1 = {mutable s : string [@no_mutable_implied_modalities]} (* accepted *)
9+
10+
1111

1212
module type TestAlertSig = sig
1313
type t1 = Foo1 [@alert foo "foo"] (* accepted *)

typing/jkind.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1209,7 +1209,7 @@ let outcometree_of_type = ref (fun _ -> assert false)
12091209

12101210
let set_outcometree_of_type p = outcometree_of_type := p
12111211

1212-
let outcometree_of_modalities_new = ref (fun _ _ _ -> assert false)
1212+
let outcometree_of_modalities_new = ref (fun _ _ -> assert false)
12131213

12141214
let set_outcometree_of_modalities_new p = outcometree_of_modalities_new := p
12151215

@@ -1638,7 +1638,7 @@ module Const = struct
16381638
in
16391639
( !outcometree_of_type type_expr,
16401640
!outcometree_of_modalities_new
1641-
Types.Immutable []
1641+
Types.Immutable
16421642
(modality_to_ignore_axes axes_ignored_by_modalities) ))
16431643
(With_bounds.to_list actual.with_bounds)
16441644
in
@@ -1819,7 +1819,7 @@ module Const = struct
18191819
| Left_jkind (transl_type, _) ->
18201820
let type_ = transl_type type_ in
18211821
let modality =
1822-
Typemode.transl_modalities ~maturity:Stable Immutable [] modalities
1822+
Typemode.transl_modalities ~maturity:Stable Immutable modalities
18231823
in
18241824
{ layout = base.layout;
18251825
mod_bounds = base.mod_bounds;

typing/jkind.mli

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,6 @@ val set_outcometree_of_type : (Types.type_expr -> Outcometree.out_type) -> unit
637637

638638
val set_outcometree_of_modalities_new :
639639
(Types.mutability ->
640-
Parsetree.attributes ->
641640
Mode.Modality.Value.Const.t ->
642641
Outcometree.out_mode_new list) ->
643642
unit

typing/printtyp.ml

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1419,14 +1419,14 @@ let tree_of_modality_old (t: Parsetree.modality loc) =
14191419
| Modality "global" -> Some (Ogf_legacy Ogf_global)
14201420
| _ -> None
14211421

1422-
let tree_of_modalities mut attrs t =
1423-
let t = Typemode.untransl_modalities mut attrs t in
1422+
let tree_of_modalities mut t =
1423+
let t = Typemode.untransl_modalities mut t in
14241424
match all_or_none tree_of_modality_old t with
14251425
| Some l -> l
14261426
| None -> List.map tree_of_modality_new t
14271427

1428-
let tree_of_modalities_new mut attrs t =
1429-
let l = Typemode.untransl_modalities mut attrs t in
1428+
let tree_of_modalities_new mut t =
1429+
let l = Typemode.untransl_modalities mut t in
14301430
List.map (fun ({txt = Parsetree.Modality s; _}) -> s) l
14311431

14321432
(** [tree_of_mode m l] finds the outcome node in [l] that corresponds to [m].
@@ -1643,7 +1643,7 @@ and tree_of_labeled_typlist mode tyl =
16431643

16441644
and tree_of_typ_gf {ca_type=ty; ca_modalities=gf; _} =
16451645
(tree_of_typexp Type Alloc.Const.legacy ty,
1646-
tree_of_modalities Immutable [] gf)
1646+
tree_of_modalities Immutable gf)
16471647

16481648
(** We are on the RHS of an arrow type, where [ty] is the return type, and [m]
16491649
is the return mode. This function decides the printed modes on [ty].
@@ -1842,9 +1842,7 @@ let tree_of_label l =
18421842
mut
18431843
| Immutable -> Om_immutable
18441844
in
1845-
let ld_modalities =
1846-
tree_of_modalities l.ld_mutable l.ld_attributes l.ld_modalities
1847-
in
1845+
let ld_modalities = tree_of_modalities l.ld_mutable l.ld_modalities in
18481846
(Ident.name l.ld_id, mut, tree_of_typexp Type l.ld_type, ld_modalities)
18491847
18501848
let tree_of_constructor_arguments = function
@@ -2266,7 +2264,7 @@ let tree_of_value_description id decl =
22662264
{ oval_name = id;
22672265
oval_type = Otyp_poly(qtvs, ty);
22682266
oval_modalities =
2269-
tree_of_modalities_new Immutable decl.val_attributes moda;
2267+
tree_of_modalities_new Immutable moda;
22702268
oval_prims = [];
22712269
oval_attributes = attrs
22722270
}

typing/typecore.ml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2647,7 +2647,7 @@ and type_pat_aux
26472647
solve_Ppat_array ~refine:false loc penv mutability expected_ty
26482648
in
26492649
let modalities =
2650-
Typemode.transl_modalities ~maturity:Stable mutability [] []
2650+
Typemode.transl_modalities ~maturity:Stable mutability []
26512651
in
26522652
check_project_mutability ~loc ~env:!!penv mutability alloc_mode.mode;
26532653
let alloc_mode = Modality.Value.Const.apply modalities alloc_mode.mode in
@@ -9515,9 +9515,7 @@ and type_generic_array
95159515
if Types.is_mutable mutability then Predef.type_array
95169516
else Predef.type_iarray
95179517
in
9518-
let modalities =
9519-
Typemode.transl_modalities ~maturity:Stable mutability [] []
9520-
in
9518+
let modalities = Typemode.transl_modalities ~maturity:Stable mutability [] in
95219519
let argument_mode = mode_modality modalities array_mode in
95229520
let jkind, elt_sort = Jkind.of_new_legacy_sort_var ~why:Array_element in
95239521
let ty = newgenvar jkind in

typing/typedecl.ml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ let transl_labels (type rep) ~(record_form : rep record_form) ~new_var_jkind
490490
| Unboxed_product -> raise(Error(loc, Unboxed_mutable_label))
491491
in
492492
let modalities =
493-
Typemode.transl_modalities ~maturity:Stable mut attrs modalities
493+
Typemode.transl_modalities ~maturity:Stable mut modalities
494494
in
495495
let arg = Ast_helper.Typ.force_poly arg in
496496
let cty = transl_simple_type ~new_var_jkind env ?univars ~closed Mode.Alloc.Const.legacy arg in
@@ -531,8 +531,7 @@ let transl_types_gf ~new_var_jkind env loc univars closed cal kloc =
531531
Mode.Alloc.Const.legacy arg.pca_type
532532
in
533533
let gf =
534-
Typemode.transl_modalities ~maturity:Stable Immutable []
535-
arg.pca_modalities
534+
Typemode.transl_modalities ~maturity:Stable Immutable arg.pca_modalities
536535
in
537536
{ca_modalities = gf; ca_type = cty; ca_loc = arg.pca_loc}
538537
in
@@ -3656,8 +3655,7 @@ let transl_value_decl env loc ~sig_modalities valdecl =
36563655
let modalities =
36573656
match valdecl.pval_modalities with
36583657
| [] -> sig_modalities
3659-
| l -> Typemode.transl_modalities ~maturity:Stable Immutable
3660-
valdecl.pval_attributes l
3658+
| l -> Typemode.transl_modalities ~maturity:Stable Immutable l
36613659
in
36623660
let modalities = Mode.Modality.Value.of_const modalities in
36633661
(* CR layouts v5: relax this to check for representability. *)

typing/typemod.ml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,7 +1062,7 @@ let apply_pmd_modalities env sig_modalities pmd_modalities mty =
10621062
match pmd_modalities with
10631063
| [] -> sig_modalities
10641064
| _ :: _ ->
1065-
Typemode.transl_modalities ~maturity:Stable Immutable [] pmd_modalities
1065+
Typemode.transl_modalities ~maturity:Stable Immutable pmd_modalities
10661066
in
10671067
(*
10681068
Workaround for pmd_modalities
@@ -1268,7 +1268,7 @@ and approx_sig_items env ssg=
12681268
| [] -> sg
12691269
| _ ->
12701270
let modalities =
1271-
Typemode.transl_modalities ~maturity:Stable Immutable [] moda
1271+
Typemode.transl_modalities ~maturity:Stable Immutable moda
12721272
in
12731273
let recursive =
12741274
not @@ Builtin_attributes.has_attribute "no_recursive_modalities" attrs
@@ -1770,7 +1770,7 @@ and transl_signature env {psg_items; psg_modalities; psg_loc} =
17701770
let names = Signature_names.create () in
17711771

17721772
let sig_modalities =
1773-
Typemode.transl_modalities ~maturity:Stable Immutable [] psg_modalities
1773+
Typemode.transl_modalities ~maturity:Stable Immutable psg_modalities
17741774
in
17751775

17761776
let transl_include ~loc env sig_acc sincl modalities =
@@ -1796,7 +1796,7 @@ and transl_signature env {psg_items; psg_modalities; psg_loc} =
17961796
match modalities with
17971797
| [] -> sig_modalities
17981798
| _ ->
1799-
Typemode.transl_modalities ~maturity:Stable Immutable [] modalities
1799+
Typemode.transl_modalities ~maturity:Stable Immutable modalities
18001800
in
18011801
let sg =
18021802
if not @@ Mode.Modality.Value.Const.is_id modalities then

typing/typemode.ml

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -407,11 +407,10 @@ let untransl_modality (a : Modality.t) : Parsetree.modality loc =
407407

408408
(* For now, mutable implies legacy modalities for both comonadic axes and
409409
monadic axes. In the future, implications on the comonadic axes will be
410-
removed (and can be experimented currently with using
411-
@no_mutable_implied_modalities). The implications on the monadic axes will
412-
stay. *)
410+
removed. The implications on the monadic axes will stay. Implied modalities
411+
can be overriden. *)
413412
(* CR zqian: decouple mutable and comonadic modalities *)
414-
let mutable_implied_modalities (mut : Types.mutability) attrs =
413+
let mutable_implied_modalities (mut : Types.mutability) =
415414
let comonadic : Modality.t list =
416415
[ Atom (Comonadic Areality, Meet_with Regionality.Const.legacy);
417416
Atom (Comonadic Linearity, Meet_with Linearity.Const.legacy);
@@ -424,15 +423,10 @@ let mutable_implied_modalities (mut : Types.mutability) attrs =
424423
Atom (Monadic Contention, Join_with Contention.Const.legacy);
425424
Atom (Monadic Visibility, Join_with Visibility.Const.legacy) ]
426425
in
427-
match mut with
428-
| Immutable -> []
429-
| Mutable _ ->
430-
if Builtin_attributes.has_no_mutable_implied_modalities attrs
431-
then monadic
432-
else monadic @ comonadic
426+
match mut with Immutable -> [] | Mutable _ -> monadic @ comonadic
433427

434-
let mutable_implied_modalities (mut : Types.mutability) attrs =
435-
let l = mutable_implied_modalities mut attrs in
428+
let mutable_implied_modalities (mut : Types.mutability) =
429+
let l = mutable_implied_modalities mut in
436430
List.fold_left
437431
(fun t (Modality.Atom (ax, a)) -> Modality.Value.Const.set ax a t)
438432
Modality.Value.Const.id l
@@ -466,8 +460,8 @@ let implied_modalities (Atom (ax, a) : Modality.t) : Modality.t list =
466460
[Atom (Comonadic Portability, Meet_with b)]
467461
| _ -> []
468462

469-
let transl_modalities ~maturity mut attrs modalities =
470-
let mut_modalities = mutable_implied_modalities mut attrs in
463+
let transl_modalities ~maturity mut modalities =
464+
let mut_modalities = mutable_implied_modalities mut in
471465
let modalities = List.map (transl_modality ~maturity) modalities in
472466
(* axes listed in the order of implication. *)
473467
let modalities =
@@ -489,8 +483,8 @@ let transl_modalities ~maturity mut attrs modalities =
489483
m (implied_modalities t))
490484
mut_modalities modalities
491485

492-
let untransl_modalities mut attrs t =
493-
let mut_modalities = mutable_implied_modalities mut attrs in
486+
let untransl_modalities mut t =
487+
let mut_modalities = mutable_implied_modalities mut in
494488
let l = Modality.Value.Const.diff mut_modalities t in
495489
let implied = List.concat_map implied_modalities l in
496490
l

0 commit comments

Comments
 (0)