Skip to content

Commit ecd62d1

Browse files
riaqngoldfirere
andauthored
flambda-backend: Remove exact from expected_mode (#2300)
* remove exact from expected_mode * Kill off an Option.get * address comments * improve tests * add comments --------- Co-authored-by: Richard Eisenberg <[email protected]>
1 parent 94790ae commit ecd62d1

File tree

4 files changed

+138
-80
lines changed

4 files changed

+138
-80
lines changed

testsuite/tests/typing-local/exclave.ml

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,27 @@ Error: This function or one of its parameters escape their region
214214
when it is partially applied.
215215
|}]
216216

217+
let f () =
218+
exclave_ (
219+
(fun x -> function | "a" -> () | _ -> ()) : (string -> string -> unit)
220+
)
221+
[%%expect{|
222+
Line 3, characters 4-45:
223+
3 | (fun x -> function | "a" -> () | _ -> ()) : (string -> string -> unit)
224+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
225+
Error: This function or one of its parameters escape their region
226+
when it is partially applied.
227+
|}]
228+
229+
(* For nested functions, inner functions are not constrained *)
230+
let f () =
231+
exclave_ (
232+
(fun x -> fun y -> ()) : (string -> string -> unit)
233+
)
234+
[%%expect{|
235+
val f : unit -> local_ (string -> (string -> unit)) = <fun>
236+
|}]
237+
217238
let f : local_ string -> string =
218239
fun x -> exclave_ s
219240
[%%expect{|
@@ -222,4 +243,4 @@ Line 2, characters 11-21:
222243
^^^^^^^^^^
223244
Error: This expression was expected to be not local, but is an exclave expression,
224245
which must be local.
225-
|}]
246+
|}]

testsuite/tests/typing-local/local.ml

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2751,27 +2751,36 @@ Error: Signature mismatch:
27512751
27522752
(* Escaping uncurried functions *)
27532753
2754-
(* Valid; [local_ int -> int -> int] is [local_ int -> local_ (int -> int)] *)
2755-
let f () = ((fun x y -> x + y) : (local_ int -> int -> int));;
2754+
(* Valid; [local_ string -> string -> string] is [local_ string -> local_ (string -> string)] *)
2755+
let f () = ((fun x y -> "") : (local_ string -> string -> string));;
27562756
[%%expect{|
2757-
val f : unit -> local_ int -> int -> int = <fun>
2757+
val f : unit -> local_ string -> string -> string = <fun>
27582758
|}];;
27592759
2760-
(* Illegal: the return mode on (int -> int) is global. *)
2761-
let f () = ((fun x y -> x + y) : (local_ int -> (int -> int)));;
2760+
(* Illegal: the return mode on (string -> string) is global. *)
2761+
let f () = ((fun x y -> "") : (local_ string -> (string -> string)));;
27622762
[%%expect{|
2763-
Line 1, characters 12-30:
2764-
1 | let f () = ((fun x y -> x + y) : (local_ int -> (int -> int)));;
2765-
^^^^^^^^^^^^^^^^^^
2763+
Line 1, characters 12-27:
2764+
1 | let f () = ((fun x y -> "") : (local_ string -> (string -> string)));;
2765+
^^^^^^^^^^^^^^^
2766+
Error: This function or one of its parameters escape their region
2767+
when it is partially applied.
2768+
|}];;
2769+
2770+
let f () = ((fun x -> function | y -> "") : (local_ string -> (string -> string)));;
2771+
[%%expect{|
2772+
Line 1, characters 12-41:
2773+
1 | let f () = ((fun x -> function | y -> "") : (local_ string -> (string -> string)));;
2774+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
27662775
Error: This function or one of its parameters escape their region
27672776
when it is partially applied.
27682777
|}];;
27692778
27702779
(* ok if curried *)
2771-
let f () = ((fun x -> (fun y -> x + y) [@extension.curry])
2772-
: (local_ int -> (int -> int)));;
2780+
let f () = ((fun x -> (fun y -> "") [@extension.curry])
2781+
: (local_ string -> (string -> string)));;
27732782
[%%expect{|
2774-
val f : unit -> local_ int -> (int -> int) = <fun>
2783+
val f : unit -> local_ string -> (string -> string) = <fun>
27752784
|}];;
27762785
27772786
(* Illegal: the expected mode is global *)
@@ -2784,6 +2793,26 @@ Error: This function or one of its parameters escape their region
27842793
when it is partially applied.
27852794
|}];;
27862795
2796+
let f () = local_ ((fun x -> function | 0 -> x | y -> x + y) : (_ -> _));;
2797+
[%%expect{|
2798+
Line 1, characters 19-60:
2799+
1 | let f () = local_ ((fun x -> function | 0 -> x | y -> x + y) : (_ -> _));;
2800+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2801+
Error: This function or one of its parameters escape their region
2802+
when it is partially applied.
2803+
|}];;
2804+
2805+
(* For nested functions, inner functions are not constrained *)
2806+
let f () = ((fun x -> fun y -> "") : (local_ string -> (string -> string)));;
2807+
[%%expect{|
2808+
val f : unit -> local_ string -> (string -> string) = <fun>
2809+
|}];;
2810+
2811+
let f () = local_ ((fun x -> fun y -> x + y) : (_ -> _));;
2812+
[%%expect{|
2813+
val f : unit -> local_ (int -> (int -> int)) = <fun>
2814+
|}];;
2815+
27872816
(* ok if curried *)
27882817
let f () = local_ ((fun x -> (fun y -> x + y) [@extension.curry]) : (_ -> _));;
27892818
[%%expect{|

testsuite/tests/typing-unique/unique.ml

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -542,25 +542,40 @@ type box = { x : int }
542542
type box = { x : int; }
543543
|}]
544544
545-
let curry (unique_ b1 : box) (unique_ b2 : box) = b1
545+
let curry (unique_ b1 : box) (unique_ b2 : box) = ()
546546
[%%expect{|
547-
val curry : unique_ box -> unique_ box -> box = <fun>
547+
val curry : unique_ box -> unique_ box -> unit = <fun>
548548
|}]
549549
550-
let curry : unique_ box -> unique_ box -> unique_ box = fun b1 b2 -> b1
550+
let curry : unique_ box -> unique_ box -> unit = fun b1 b2 -> ()
551551
[%%expect{|
552-
val curry : unique_ box -> unique_ box -> unique_ box = <fun>
552+
val curry : unique_ box -> unique_ box -> unit = <fun>
553553
|}]
554554
555-
let curry : unique_ box -> (unique_ box -> unique_ box) = fun b1 b2 -> b1
555+
let curry : unique_ box -> (unique_ box -> unit) = fun b1 b2 -> ()
556556
[%%expect{|
557-
Line 1, characters 58-73:
558-
1 | let curry : unique_ box -> (unique_ box -> unique_ box) = fun b1 b2 -> b1
559-
^^^^^^^^^^^^^^^
557+
Line 1, characters 51-66:
558+
1 | let curry : unique_ box -> (unique_ box -> unit) = fun b1 b2 -> ()
559+
^^^^^^^^^^^^^^^
560560
Error: This function when partially applied returns a once value,
561561
but expected to be many.
562562
|}]
563563
564+
let curry : unique_ box -> (unique_ box -> unit) = fun b1 -> function | b2 -> ()
565+
[%%expect{|
566+
Line 1, characters 51-80:
567+
1 | let curry : unique_ box -> (unique_ box -> unit) = fun b1 -> function | b2 -> ()
568+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
569+
Error: This function when partially applied returns a once value,
570+
but expected to be many.
571+
|}]
572+
573+
(* For nested functions, inner functions are not constrained *)
574+
let no_curry : unique_ box -> (unique_ box -> unit) = fun b1 -> fun b2 -> ()
575+
[%%expect{|
576+
val no_curry : unique_ box -> (unique_ box -> unit) = <fun>
577+
|}]
578+
564579
(* If both type and mode are wrong, complain about type *)
565580
let f () =
566581
let id2 (x : string) = shared_id x in
@@ -615,4 +630,4 @@ Line 5, characters 16-17:
615630
5 | in Node (x, x)
616631
^
617632
618-
|}]
633+
|}]

0 commit comments

Comments
 (0)