Skip to content

Commit f37af34

Browse files
committed
still broken
1 parent 9f251f0 commit f37af34

File tree

12 files changed

+228
-282
lines changed

12 files changed

+228
-282
lines changed

testsuite/tests/typing-jkind-bounds/basics.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1157,7 +1157,7 @@ Error: The kind of type "t" is value
11571157
type 'a t : value mod global portable contended many aliased unyielding =
11581158
{ x : 'a @@ global portable contended many aliased } [@@unboxed]
11591159
[%%expect {|
1160-
type 'a t = { x : 'a @@ global many portable aliased contended; } [@@unboxed]
1160+
type 'a t = { x : 'a @@ global many aliased portable contended; } [@@unboxed]
11611161
|}]
11621162
(* CR layouts v2.8: this could be accepted, if we infer ('a : value mod
11631163
unyielding). We do not currently do this, because we finish inference of the

testsuite/tests/typing-layouts/allow_any.ml

+4-4
Original file line numberDiff line numberDiff line change
@@ -385,9 +385,9 @@ Lines 1-2, characters 0-34:
385385
Error: This variant or record definition does not match that of type "'a t"
386386
They have different unsafe mode crossing behavior:
387387
Both specify [@@unsafe_allow_any_mode_crossing], but their bounds are not equal
388-
the original has: mod many portable unyielding stateless contended
388+
the original has: mod many portable contended unyielding stateless
389389
immutable with 'a
390-
but this has: mod many portable unyielding stateless contended
390+
but this has: mod many portable contended unyielding stateless
391391
immutable
392392
|}]
393393

@@ -406,9 +406,9 @@ Error: This variant or record definition does not match that of type
406406
"('a, 'b) arity_2"
407407
They have different unsafe mode crossing behavior:
408408
Both specify [@@unsafe_allow_any_mode_crossing], but their bounds are not equal
409-
the original has: mod many portable unyielding stateless contended
409+
the original has: mod many portable contended unyielding stateless
410410
immutable with 'b
411-
but this has: mod many portable unyielding stateless contended
411+
but this has: mod many portable contended unyielding stateless
412412
immutable with 'a
413413
|}]
414414

testsuite/tests/typing-modes/mutable.ml

+48
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,54 @@ Line 2, characters 31-32:
1616
Error: This value escapes its region.
1717
|}]
1818

19+
(* you can override those implied modalities *)
20+
type r = {mutable s : string @@ local}
21+
let foo (local_ s) = exclave_ {s}
22+
[%%expect{|
23+
type r = { mutable s : string @@ local; }
24+
val foo : local_ string -> local_ r = <fun>
25+
|}]
26+
27+
type r = {mutable s : string @@ global}
28+
[%%expect{|
29+
type r = { mutable s : string; }
30+
|}]
31+
32+
type r = {mutable s : string @@ global yielding}
33+
[%%expect{|
34+
type r = { mutable s : string @@ yielding; }
35+
|}]
36+
37+
type r = {mutable s : string @@ yielding global}
38+
[%%expect{|
39+
type r = { mutable s : string @@ yielding; }
40+
|}]
41+
42+
type r = {mutable s : string @@ yielding}
43+
[%%expect{|
44+
type r = { mutable s : string @@ yielding; }
45+
|}]
46+
47+
type r = {mutable s : string @@ local yielding}
48+
[%%expect{|
49+
type r = { mutable s : string @@ local; }
50+
|}]
51+
52+
type r = {mutable s : string @@ yielding local}
53+
[%%expect{|
54+
type r = { mutable s : string @@ local; }
55+
|}]
56+
57+
type r = {mutable s : string @@ local unyielding}
58+
[%%expect{|
59+
type r = { mutable s : string @@ local; }
60+
|}]
61+
62+
type r = {mutable s : string @@ unyielding local}
63+
[%%expect{|
64+
type r = { mutable s : string @@ local; }
65+
|}]
66+
1967
(* [@no_mutable_implied_modalities] disables those implied modalities on the
2068
comonadic axes, and allows us to test [mutable] alone *)
2169

testsuite/tests/typing-modes/val_modalities.ml

+1-2
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ module type S = sig
4242
portable nonportable
4343
end
4444
[%%expect{|
45-
module type S =
46-
sig val x : string @@ global many portable aliased contended end
45+
module type S = sig val x : string @@ many aliased contended end
4746
|}]
4847

4948
(* values' comonadic axes must be lower than the module *)

testsuite/tests/typing-modes/yielding.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ let with_global_effect : ((string -> unit) @ yielding -> 'a) -> 'a =
8787

8888
[%%expect{|
8989
type 'a t1 = Mk1 of global_ 'a
90-
type 'a t2 = Mk2 of 'a @@ global yielding
90+
type 'a t2 = Mk2 of global_ 'a
9191
type 'a t3 = Mk3 of 'a @@ unyielding
9292
type 'a t4 = Mk4 of 'a
9393
val with_global_effect : ((string -> unit) @ yielding -> 'a) -> 'a = <fun>

typing/jkind.ml

+4-3
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ let relevant_axes_of_modality ~relevant_for_nullability ~modality =
399399
| Modal axis ->
400400
let (P axis) = Mode.Const.Axis.alloc_as_value (P axis) in
401401
let modality = Mode.Modality.Value.Const.proj axis modality in
402-
not (Mode.Modality.is_constant modality)
402+
not (Mode.Modality.is_constant (Atom (axis, modality)))
403403
(* The kind-inference.md document (in the repo) discusses both constant
404404
modalities and identity modalities. Of course, reality has modalities
405405
(such as [shared]) that are neither constants nor identities. Here, we
@@ -1602,7 +1602,7 @@ module Const = struct
16021602
(fun acc (Axis.Pack axis) ->
16031603
match axis with
16041604
| Modal axis ->
1605-
let then_ : Modality.t =
1605+
let t : Modality.t =
16061606
let (P axis) = Mode.Const.Axis.alloc_as_value (P axis) in
16071607
match axis with
16081608
| Monadic monadic ->
@@ -1613,7 +1613,8 @@ module Const = struct
16131613
( axis,
16141614
Meet_with (Mode.Value.Comonadic.Const.min_axis comonadic) )
16151615
in
1616-
Modality.Value.Const.compose acc ~then_
1616+
let (Atom (axis, a)) = t in
1617+
Modality.Value.Const.set axis a acc
16171618
| Nonmodal _ ->
16181619
(* TODO: don't know how to print *)
16191620
acc)

typing/mode.ml

+46-67
Original file line numberDiff line numberDiff line change
@@ -913,13 +913,13 @@ module Lattices_mono = struct
913913
module Axis = struct
914914
type ('t, 'r) t =
915915
| Areality : ('a comonadic_with, 'a) t
916-
| Linearity : ('areality comonadic_with, Linearity.t) t
917-
| Portability : ('areality comonadic_with, Portability.t) t
918916
| Yielding : ('areality comonadic_with, Yielding.t) t
917+
| Linearity : ('areality comonadic_with, Linearity.t) t
919918
| Statefulness : ('areality comonadic_with, Statefulness.t) t
919+
| Portability : ('areality comonadic_with, Portability.t) t
920920
| Uniqueness : (Monadic_op.t, Uniqueness_op.t) t
921-
| Contention : (Monadic_op.t, Contention_op.t) t
922921
| Visibility : (Monadic_op.t, Visibility_op.t) t
922+
| Contention : (Monadic_op.t, Contention_op.t) t
923923

924924
let print : type p r. _ -> (p, r) t -> unit =
925925
fun ppf -> function
@@ -960,7 +960,7 @@ module Lattices_mono = struct
960960
| Contention -> t.contention
961961
| Visibility -> t.visibility
962962

963-
let update : type p r. (p, r) t -> r -> p -> p =
963+
let set : type p r. (p, r) t -> r -> p -> p =
964964
fun ax r t ->
965965
match ax with
966966
| Areality -> { t with areality = r }
@@ -1319,9 +1319,9 @@ module Lattices_mono = struct
13191319
| Visibility.Read -> Statefulness.Observing
13201320
| Visibility.Read_write -> Statefulness.Stateful
13211321

1322-
let min_with dst ax a = Axis.update ax a (min dst)
1322+
let min_with dst ax a = Axis.set ax a (min dst)
13231323

1324-
let max_with dst ax a = Axis.update ax a (max dst)
1324+
let max_with dst ax a = Axis.set ax a (max dst)
13251325

13261326
let monadic_to_comonadic_min :
13271327
type a. a comonadic_with obj -> Monadic_op.t -> a comonadic_with =
@@ -2078,9 +2078,9 @@ module BiHeyting_Product (L : BiHeyting) = struct
20782078

20792079
type 'a axis = (t, 'a) Axis.t
20802080

2081-
let min_with ax c = Axis.update ax c min
2081+
let min_with ax c = Axis.set ax c min
20822082

2083-
let max_with ax c = Axis.update ax c max
2083+
let max_with ax c = Axis.set ax c max
20842084

20852085
let min_axis ax = Axis.proj ax min
20862086

@@ -2349,10 +2349,11 @@ module Value_with (Areality : Areality) = struct
23492349

23502350
let all =
23512351
[ P (Comonadic Areality);
2352-
P (Monadic Uniqueness);
23532352
P (Comonadic Linearity);
2354-
P (Monadic Contention);
2353+
P (Monadic Uniqueness);
23552354
P (Comonadic Portability);
2355+
P (Monadic Contention);
2356+
P (Comonadic Yielding);
23562357
P (Comonadic Statefulness);
23572358
P (Monadic Visibility) ]
23582359
end
@@ -3023,31 +3024,19 @@ module Modality = struct
30233024
Error
30243025
(Error (ax, { left = Join_with left; right = Join_with right }))
30253026

3026-
let compose : type a. a axis -> a raw -> t -> t =
3027-
fun ax a t ->
3028-
match a, t with
3029-
| Join_with c0, Join_const c ->
3030-
Join_const (Mode.Const.join (Mode.Const.min_with ax c0) c)
3031-
| Meet_with _, Join_const _ -> assert false
3032-
30333027
let concat ~then_ t =
30343028
match then_, t with
30353029
| Join_const c0, Join_const c1 -> Join_const (Mode.Const.join c0 c1)
30363030

30373031
let apply : type l r. t -> (l * r) Mode.t -> (l * r) Mode.t =
30383032
fun t x -> match t with Join_const c -> Mode.join_const c x
30393033

3040-
let to_list = function
3041-
| Join_const c ->
3042-
[ (let ax : _ Axis.t = Uniqueness in
3043-
Atom (Monadic ax, Join_with (Axis.proj ax c)));
3044-
(let ax : _ Axis.t = Contention in
3045-
Atom (Monadic ax, Join_with (Axis.proj ax c)));
3046-
(let ax : _ Axis.t = Visibility in
3047-
Atom (Monadic ax, Join_with (Axis.proj ax c))) ]
3034+
let proj ax (Join_const c) = Join_with (Axis.proj ax c)
30483035

3049-
let proj ax = function
3050-
| Join_const c -> Atom (Monadic ax, Join_with (Axis.proj ax c))
3036+
let set ax a (Join_const c) =
3037+
match a with
3038+
| Join_with a -> Join_const (Axis.set ax a c)
3039+
| Meet_with _ -> assert false
30513040

30523041
let print ppf = function
30533042
| Join_const c -> Format.fprintf ppf "join_const(%a)" Mode.Const.print c
@@ -3178,35 +3167,19 @@ module Modality = struct
31783167
Error
31793168
(Error (ax, { left = Meet_with left; right = Meet_with right }))
31803169

3181-
let compose : type a. a axis -> a raw -> t -> t =
3182-
fun ax a t ->
3183-
match a, t with
3184-
| Meet_with c0, Meet_const c ->
3185-
Meet_const (Mode.Const.meet (Mode.Const.max_with ax c0) c)
3186-
| Join_with _, Meet_const _ -> assert false
3187-
31883170
let concat ~then_ t =
31893171
match then_, t with
31903172
| Meet_const c0, Meet_const c1 -> Meet_const (Mode.Const.meet c0 c1)
31913173

31923174
let apply : type l r. t -> (l * r) Mode.t -> (l * r) Mode.t =
31933175
fun t x -> match t with Meet_const c -> Mode.meet_const c x
31943176

3195-
let to_list = function
3196-
| Meet_const c ->
3197-
[ (let ax : _ Axis.t = Areality in
3198-
Atom (Comonadic ax, Meet_with (Axis.proj ax c)));
3199-
(let ax : _ Axis.t = Linearity in
3200-
Atom (Comonadic ax, Meet_with (Axis.proj ax c)));
3201-
(let ax : _ Axis.t = Portability in
3202-
Atom (Comonadic ax, Meet_with (Axis.proj ax c)));
3203-
(let ax : _ Axis.t = Yielding in
3204-
Atom (Comonadic ax, Meet_with (Axis.proj ax c)));
3205-
(let ax : _ Axis.t = Statefulness in
3206-
Atom (Comonadic ax, Meet_with (Axis.proj ax c))) ]
3207-
3208-
let proj ax = function
3209-
| Meet_const c -> Atom (Comonadic ax, Meet_with (Axis.proj ax c))
3177+
let proj ax (Meet_const c) = Meet_with (Axis.proj ax c)
3178+
3179+
let set ax a (Meet_const c) =
3180+
match a with
3181+
| Meet_with a -> Meet_const (Axis.set ax a c)
3182+
| Join_with _ -> assert false
32103183

32113184
let print ppf = function
32123185
| Meet_const c -> Format.fprintf ppf "meet_const(%a)" Mode.Const.print c
@@ -3342,33 +3315,35 @@ module Modality = struct
33423315
let comonadic = Comonadic.apply t.comonadic comonadic in
33433316
{ monadic; comonadic }
33443317

3345-
let compose ~then_:(Atom (ax, a)) t =
3346-
match ax with
3347-
| Monadic ax ->
3348-
let monadic = Monadic.compose ax a t.monadic in
3349-
{ t with monadic }
3350-
| Comonadic ax ->
3351-
let comonadic = Comonadic.compose ax a t.comonadic in
3352-
{ t with comonadic }
3353-
33543318
let concat ~then_ t =
33553319
let monadic = Monadic.concat ~then_:then_.monadic t.monadic in
33563320
let comonadic = Comonadic.concat ~then_:then_.comonadic t.comonadic in
33573321
{ monadic; comonadic }
33583322

3359-
let of_list = List.fold_left (fun m atom -> compose m ~then_:atom) id
3360-
3361-
let singleton a = compose ~then_:a id
3362-
3363-
let to_list { monadic; comonadic } =
3364-
Comonadic.to_list comonadic @ Monadic.to_list monadic
3365-
33663323
let proj (type a d0 d1) (ax : (a, d0, d1) Value.Axis.t)
33673324
{ monadic; comonadic } =
33683325
match ax with
33693326
| Monadic ax -> Monadic.proj ax monadic
33703327
| Comonadic ax -> Comonadic.proj ax comonadic
33713328

3329+
let set (type a d0 d1) (ax : (a, d0, d1) Value.Axis.t) (a : a raw)
3330+
{ monadic; comonadic } =
3331+
match ax with
3332+
| Monadic ax ->
3333+
let monadic = Monadic.set ax a monadic in
3334+
{ monadic; comonadic }
3335+
| Comonadic ax ->
3336+
let comonadic = Comonadic.set ax a comonadic in
3337+
{ monadic; comonadic }
3338+
3339+
let diff t0 t1 =
3340+
List.filter_map
3341+
(fun (Value.Axis.P ax) ->
3342+
let a0 = proj ax t0 in
3343+
let a1 = proj ax t1 in
3344+
if a0 = a1 then None else Some (Atom (ax, a1)))
3345+
Value.Axis.all
3346+
33723347
let print ppf { monadic; comonadic } =
33733348
Format.fprintf ppf "%a;%a" Monadic.print monadic Comonadic.print
33743349
comonadic
@@ -3589,8 +3564,12 @@ module Crossing = struct
35893564
| Modality.Atom (ax, Meet_with c) -> C.print (Value.proj_obj ax) ppf c
35903565
in
35913566
let l =
3592-
t |> Modality.Value.Const.to_list
3593-
|> List.filter (fun t -> not @@ Modality.is_id t)
3567+
List.filter_map
3568+
(fun (Value.Axis.P ax) ->
3569+
let a = Modality.Value.Const.proj ax t in
3570+
let a = Modality.Atom (ax, a) in
3571+
if Modality.is_id a then None else Some a)
3572+
Value.Axis.all
35943573
in
35953574
Format.(pp_print_list ~pp_sep:pp_print_space print_atom ppf l)
35963575
end

0 commit comments

Comments
 (0)