Skip to content

Commit bb7defe

Browse files
authored
Remove @no_mutable_implied_modalities (#3962)
1 parent a3342a7 commit bb7defe

16 files changed

+60
-91
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 unyielding; }
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
@@ -1236,7 +1236,7 @@ let outcometree_of_type = ref (fun _ -> assert false)
12361236

12371237
let set_outcometree_of_type p = outcometree_of_type := p
12381238

1239-
let outcometree_of_modalities_new = ref (fun _ _ _ -> assert false)
1239+
let outcometree_of_modalities_new = ref (fun _ _ -> assert false)
12401240

12411241
let set_outcometree_of_modalities_new p = outcometree_of_modalities_new := p
12421242

@@ -1731,7 +1731,7 @@ module Const = struct
17311731
in
17321732
( !outcometree_of_type type_expr,
17331733
!outcometree_of_modalities_new
1734-
Types.Immutable []
1734+
Types.Immutable
17351735
(modality_to_ignore_axes axes_ignored_by_modalities) ))
17361736
(With_bounds.to_list actual.with_bounds)
17371737
in
@@ -1891,7 +1891,7 @@ module Const = struct
18911891
| Left_jkind (transl_type, _) ->
18921892
let type_ = transl_type type_ in
18931893
let modality =
1894-
Typemode.transl_modalities ~maturity:Stable Immutable [] modalities
1894+
Typemode.transl_modalities ~maturity:Stable Immutable modalities
18951895
in
18961896
{ layout = base.layout;
18971897
mod_bounds = base.mod_bounds;

typing/jkind.mli

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

646646
val set_outcometree_of_modalities_new :
647647
(Types.mutability ->
648-
Parsetree.attributes ->
649648
Mode.Modality.Value.Const.t ->
650649
Outcometree.out_mode_new list) ->
651650
unit

typing/printtyp.ml

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

1424-
let tree_of_modalities mut attrs t =
1425-
let t = Typemode.untransl_modalities mut attrs t in
1424+
let tree_of_modalities mut t =
1425+
let t = Typemode.untransl_modalities mut t in
14261426
match all_or_none tree_of_modality_old t with
14271427
| Some l -> l
14281428
| None -> List.map tree_of_modality_new t
14291429

1430-
let tree_of_modalities_new mut attrs t =
1431-
let l = Typemode.untransl_modalities mut attrs t in
1430+
let tree_of_modalities_new mut t =
1431+
let l = Typemode.untransl_modalities mut t in
14321432
List.map (fun ({txt = Parsetree.Modality s; _}) -> s) l
14331433

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

16481648
and tree_of_typ_gf {ca_type=ty; ca_modalities=gf; _} =
16491649
(tree_of_typexp Type Alloc.Const.legacy ty,
1650-
tree_of_modalities Immutable [] gf)
1650+
tree_of_modalities Immutable gf)
16511651

16521652
(** We are on the RHS of an arrow type, where [ty] is the return type, and [m]
16531653
is the return mode. This function decides the printed modes on [ty].
@@ -1846,9 +1846,7 @@ let tree_of_label l =
18461846
mut
18471847
| Immutable -> Om_immutable
18481848
in
1849-
let ld_modalities =
1850-
tree_of_modalities l.ld_mutable l.ld_attributes l.ld_modalities
1851-
in
1849+
let ld_modalities = tree_of_modalities l.ld_mutable l.ld_modalities in
18521850
(Ident.name l.ld_id, mut, tree_of_typexp Type l.ld_type, ld_modalities)
18531851
18541852
let tree_of_constructor_arguments = function
@@ -2269,8 +2267,7 @@ let tree_of_value_description id decl =
22692267
let vd =
22702268
{ oval_name = id;
22712269
oval_type = Otyp_poly(qtvs, ty);
2272-
oval_modalities =
2273-
tree_of_modalities_new Immutable decl.val_attributes moda;
2270+
oval_modalities = tree_of_modalities_new Immutable moda;
22742271
oval_prims = [];
22752272
oval_attributes = attrs
22762273
}

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
@@ -9529,9 +9529,7 @@ and type_generic_array
95299529
if Types.is_mutable mutability then Predef.type_array
95309530
else Predef.type_iarray
95319531
in
9532-
let modalities =
9533-
Typemode.transl_modalities ~maturity:Stable mutability [] []
9534-
in
9532+
let modalities = Typemode.transl_modalities ~maturity:Stable mutability [] in
95359533
let argument_mode = mode_modality modalities array_mode in
95369534
let jkind, elt_sort = Jkind.of_new_legacy_sort_var ~why:Array_element in
95379535
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: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -462,11 +462,10 @@ let untransl_modality (a : Modality.t) : Parsetree.modality loc =
462462

463463
(* For now, mutable implies legacy modalities for both comonadic axes and
464464
monadic axes. In the future, implications on the comonadic axes will be
465-
removed (and can be experimented currently with using
466-
@no_mutable_implied_modalities). The implications on the monadic axes will
467-
stay. *)
465+
removed. The implications on the monadic axes will stay. Implied modalities
466+
can be overriden. *)
468467
(* CR zqian: decouple mutable and comonadic modalities *)
469-
let mutable_implied_modalities (mut : Types.mutability) attrs =
468+
let mutable_implied_modalities (mut : Types.mutability) =
470469
let comonadic : Modality.t list =
471470
[ Atom (Comonadic Areality, Meet_with Regionality.Const.legacy);
472471
Atom (Comonadic Linearity, Meet_with Linearity.Const.legacy);
@@ -479,15 +478,10 @@ let mutable_implied_modalities (mut : Types.mutability) attrs =
479478
Atom (Monadic Contention, Join_with Contention.Const.legacy);
480479
Atom (Monadic Visibility, Join_with Visibility.Const.legacy) ]
481480
in
482-
match mut with
483-
| Immutable -> []
484-
| Mutable _ ->
485-
if Builtin_attributes.has_no_mutable_implied_modalities attrs
486-
then monadic
487-
else monadic @ comonadic
481+
match mut with Immutable -> [] | Mutable _ -> monadic @ comonadic
488482

489-
let mutable_implied_modalities (mut : Types.mutability) attrs =
490-
let l = mutable_implied_modalities mut attrs in
483+
let mutable_implied_modalities (mut : Types.mutability) =
484+
let l = mutable_implied_modalities mut in
491485
List.fold_left
492486
(fun t (Modality.Atom (ax, a)) -> Modality.Value.Const.set ax a t)
493487
Modality.Value.Const.id l
@@ -521,8 +515,8 @@ let implied_modalities (Atom (ax, a) : Modality.t) : Modality.t list =
521515
[Atom (Comonadic Portability, Meet_with b)]
522516
| _ -> []
523517

524-
let least_modalities_implying mut attrs (t : Modality.Value.Const.t) =
525-
let baseline = mutable_implied_modalities mut attrs in
518+
let least_modalities_implying mut (t : Modality.Value.Const.t) =
519+
let baseline = mutable_implied_modalities mut in
526520
let annotated = Modality.Value.Const.(diff baseline t) in
527521
let implied = List.concat_map implied_modalities annotated in
528522
let exclude_implied =
@@ -565,8 +559,8 @@ let sort_dedup_modalities ~warn l =
565559
in
566560
l |> List.stable_sort compare |> dedup ~on_dup |> List.map fst
567561

568-
let transl_modalities ~maturity mut attrs modalities =
569-
let mut_modalities = mutable_implied_modalities mut attrs in
562+
let transl_modalities ~maturity mut modalities =
563+
let mut_modalities = mutable_implied_modalities mut in
570564
let modalities = List.map (transl_modality ~maturity) modalities in
571565
(* axes listed in the order of implication. *)
572566
let modalities = sort_dedup_modalities ~warn:true modalities in
@@ -582,9 +576,9 @@ let transl_modalities ~maturity mut attrs modalities =
582576
m (implied_modalities t))
583577
mut_modalities modalities
584578

585-
let untransl_modalities mut attrs t =
579+
let untransl_modalities mut t =
586580
t
587-
|> least_modalities_implying mut attrs
581+
|> least_modalities_implying mut
588582
|> List.map (fun x -> x, Location.none)
589583
|> sort_dedup_modalities ~warn:false
590584
|> List.map untransl_modality

0 commit comments

Comments
 (0)