Skip to content

Commit

Permalink
Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
d-kalinichenko committed Jan 6, 2025
1 parent 137fbf0 commit c35a392
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,13 @@ let rec fib = function | 0 | 1 -> 1 | n -> (fib (n - 1)) + (fib (n - 2))
<def_rec>
pattern (test_locations.ml[17,534+8]..test_locations.ml[17,534+11])
Tpat_var "fib"
value_mode global,many,nonportable;join(aliased,contended)(modevar#1[aliased,uncontended .. unique,uncontended])
value_mode global,many,nonportable,unyielding;join(aliased,contended)(modevar#1[aliased,uncontended .. unique,uncontended])
expression (test_locations.ml[17,534+14]..test_locations.ml[19,572+34])
Texp_function
alloc_mode global,many,nonportable;id(modevar#7[aliased,contended .. unique,uncontended])
alloc_mode global,many,nonportable,unyielding;id(modevar#7[aliased,contended .. unique,uncontended])
[]
Tfunction_cases (test_locations.ml[17,534+14]..test_locations.ml[19,572+34])
alloc_mode global,many,nonportable;aliased,uncontended
alloc_mode global,many,nonportable,unyielding;aliased,uncontended
value
[
<case>
Expand All @@ -110,7 +110,7 @@ let rec fib = function | 0 | 1 -> 1 | n -> (fib (n - 1)) + (fib (n - 2))
<case>
pattern (test_locations.ml[19,572+4]..test_locations.ml[19,572+5])
Tpat_var "n"
value_mode global,many,portable;unique,uncontended
value_mode global,many,portable,unyielding;unique,uncontended
expression (test_locations.ml[19,572+9]..test_locations.ml[19,572+34])
Texp_apply
apply_mode Tail
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,13 @@ let rec fib = function | 0 | 1 -> 1 | n -> (fib (n - 1)) + (fib (n - 2))
<def_rec>
pattern
Tpat_var "fib"
value_mode global,many,nonportable;join(aliased,contended)(modevar#1[aliased,uncontended .. unique,uncontended])
value_mode global,many,nonportable,unyielding;join(aliased,contended)(modevar#1[aliased,uncontended .. unique,uncontended])
expression
Texp_function
alloc_mode global,many,nonportable;id(modevar#7[aliased,contended .. unique,uncontended])
alloc_mode global,many,nonportable,unyielding;id(modevar#7[aliased,contended .. unique,uncontended])
[]
Tfunction_cases
alloc_mode global,many,nonportable;aliased,uncontended
alloc_mode global,many,nonportable,unyielding;aliased,uncontended
value
[
<case>
Expand All @@ -110,7 +110,7 @@ let rec fib = function | 0 | 1 -> 1 | n -> (fib (n - 1)) + (fib (n - 2))
<case>
pattern
Tpat_var "n"
value_mode global,many,portable;unique,uncontended
value_mode global,many,portable,unyielding;unique,uncontended
expression
Texp_apply
apply_mode Tail
Expand Down
8 changes: 4 additions & 4 deletions testsuite/tests/typing-layouts/jkinds.ml
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,8 @@ Error: Layout void is more experimental than allowed by the enabled layouts exte
|}]

type a : immediate
type b : value mod global unique many uncontended portable external_ = a
type c : value mod global unique many uncontended portable external_
type b : value mod global unique many uncontended portable unyielding external_ = a
type c : value mod global unique many uncontended portable unyielding external_
type d : immediate = c
[%%expect{|
type a : immediate
Expand All @@ -290,8 +290,8 @@ type d = c
|}]

type a : immediate64
type b : value mod global unique many uncontended portable external64 = a
type c : value mod global unique many uncontended portable external64
type b : value mod global unique many uncontended portable unyielding external64 = a
type c : value mod global unique many uncontended portable unyielding external64
type d : immediate64 = c
[%%expect{|
type a : immediate64
Expand Down
80 changes: 80 additions & 0 deletions testsuite/tests/typing-modes/yielding.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
(* TEST
expect;
*)

(* CR dkalinichenko: allow [yielding] at toplevel? *)
let my_effect : unit -> unit @@ yielding = print_endline "Hello, world!"
[%%expect{|
Line 1, characters 4-72:
1 | let my_effect : unit -> unit @@ yielding = print_endline "Hello, world!"
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error: This value is "yielding" but expected to be "unyielding".
|}]

let storage = ref ""

let with_effect : ((string -> unit) @ local yielding -> 'a) -> 'a =
fun f -> f ((:=) storage)

[%%expect{|
val storage : string ref = {contents = ""}
val with_effect : (local_ (string -> unit) @ yielding -> 'a) -> 'a = <fun>
|}]

let () = with_effect (fun k -> k "Hello, world!")

let _ = !storage

[%%expect{|
- : string = "Hello, world!"
|}]

let run_yielding : (string -> unit) @ local yielding -> unit = fun f -> f "my string"

let () = with_effect (fun k -> run_yielding k)

let _ = !storage

[%%expect{|
val run_yielding : local_ (string -> unit) @ yielding -> unit = <fun>
- : string = "my string"
|}]

let run_unyielding : (string -> unit) @ local unyielding -> unit = fun f -> f "another string"

let () = with_effect (fun k -> run_unyielding k)

[%%expect{|
val run_unyielding : local_ (string -> unit) -> unit = <fun>
Line 3, characters 46-47:
3 | let () = with_effect (fun k -> run_unyielding k)
^
Error: This value is "yielding" but expected to be "unyielding".
|}]

(* CR dkalinichenko: default [local] arguments to [yielding]. *)

let run_default : (string -> unit) @ local -> unit = fun f -> f "some string"

let () = with_effect (fun k -> run_default k)

[%%expect{|
val run_default : local_ (string -> unit) -> unit = <fun>
Line 3, characters 43-44:
3 | let () = with_effect (fun k -> run_default k)
^
Error: This value is "yielding" but expected to be "unyielding".
|}]

(* A closure over a [yielding] value must be [yielding]. *)

let () = with_effect (fun k ->
let closure @ local unyielding = fun () -> k () in
run_unyielding k)

[%%expect{|
Line 2, characters 45-46:
2 | let closure @ local unyielding = fun () -> k () in
^
Error: The value "k" is yielding, so cannot be used inside a function that may not yield.
|}]

0 comments on commit c35a392

Please sign in to comment.