Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename Effect.{eff => t} #11044

Merged
merged 2 commits into from Feb 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 11 additions & 11 deletions stdlib/effect.ml
Expand Up @@ -12,8 +12,8 @@
(* *)
(**************************************************************************)

type _ eff = ..
external perform : 'a eff -> 'a = "%perform"
type _ t = ..
external perform : 'a t -> 'a = "%perform"

type ('a, 'b) stack

Expand All @@ -30,7 +30,7 @@ module Deep = struct
external alloc_stack :
('a -> 'b) ->
(exn -> 'b) ->
('c eff -> ('c, 'b) continuation -> last_fiber -> 'b) ->
('c t -> ('c, 'b) continuation -> last_fiber -> 'b) ->
('a, 'b) stack = "caml_alloc_stack"

let continue k v = resume (take_cont_noexc k) (fun x -> x) v
Expand All @@ -43,10 +43,10 @@ module Deep = struct
type ('a,'b) handler =
{ retc: 'a -> 'b;
exnc: exn -> 'b;
effc: 'c.'c eff -> (('c,'b) continuation -> 'b) option }
effc: 'c.'c t -> (('c,'b) continuation -> 'b) option }

external reperform :
'a eff -> ('a, 'b) continuation -> last_fiber -> 'b = "%reperform"
'a t -> ('a, 'b) continuation -> last_fiber -> 'b = "%reperform"

let match_with comp arg handler =
let effc eff k last_fiber =
Expand All @@ -58,7 +58,7 @@ module Deep = struct
runstack s comp arg

type 'a effect_handler =
{ effc: 'b. 'b eff -> (('b,'a) continuation -> 'a) option }
{ effc: 'b. 'b t -> (('b,'a) continuation -> 'a) option }

let try_with comp arg handler =
let effc' eff k last_fiber =
Expand All @@ -82,12 +82,12 @@ module Shallow = struct
external alloc_stack :
('a -> 'b) ->
(exn -> 'b) ->
('c eff -> ('c, 'b) continuation -> last_fiber -> 'b) ->
('c t -> ('c, 'b) continuation -> last_fiber -> 'b) ->
('a, 'b) stack = "caml_alloc_stack"


let fiber : type a b. (a -> b) -> (a, b) continuation = fun f ->
let module M = struct type _ eff += Initial_setup__ : a eff end in
let module M = struct type _ t += Initial_setup__ : a t end in
let exception E of (a,b) continuation in
let f' () = f (perform M.Initial_setup__) in
let error _ = failwith "impossible" in
Expand All @@ -102,17 +102,17 @@ module Shallow = struct
type ('a,'b) handler =
{ retc: 'a -> 'b;
exnc: exn -> 'b;
effc: 'c.'c eff -> (('c,'a) continuation -> 'b) option }
effc: 'c.'c t -> (('c,'a) continuation -> 'b) option }

external update_handler :
('a,'b) continuation ->
('b -> 'c) ->
(exn -> 'c) ->
('d eff -> ('d,'b) continuation -> last_fiber -> 'c) ->
('d t -> ('d,'b) continuation -> last_fiber -> 'c) ->
('a,'c) stack = "caml_continuation_use_and_update_handler_noexc" [@@noalloc]

external reperform :
'a eff -> ('a, 'b) continuation -> last_fiber -> 'c = "%reperform"
'a t -> ('a, 'b) continuation -> last_fiber -> 'c = "%reperform"

let continue_with k v handler =
let effc eff k last_fiber =
Expand Down
16 changes: 10 additions & 6 deletions stdlib/effect.mli
Expand Up @@ -12,10 +12,14 @@
(* *)
(**************************************************************************)

type _ eff = ..
(* Type of effects *)
(** Effects.

external perform : 'a eff -> 'a = "%perform"
@since 5.00.0 *)

type _ t = ..
(** The type of effects. *)

external perform : 'a t -> 'a = "%perform"
(** [perform e] performs an effect [e].

@raise Unhandled if there is no active handler. *)
Expand Down Expand Up @@ -52,7 +56,7 @@ module Deep : sig
type ('a,'b) handler =
{ retc: 'a -> 'b;
exnc: exn -> 'b;
effc: 'c.'c eff -> (('c,'b) continuation -> 'b) option }
effc: 'c.'c t -> (('c,'b) continuation -> 'b) option }
(** [('a,'b) handler] is a handler record with three fields -- [retc]
is the value handler, [exnc] handles exceptions, and [effc] handles the
effects performed by the computation enclosed by the handler. *)
Expand All @@ -61,7 +65,7 @@ module Deep : sig
(** [match_with f v h] runs the computation [f v] in the handler [h]. *)

type 'a effect_handler =
{ effc: 'b. 'b eff -> (('b, 'a) continuation -> 'a) option }
{ effc: 'b. 'b t -> (('b, 'a) continuation -> 'a) option }
(** ['a effect_handler] is a deep handler with an identity value handler
[fun x -> x] and an exception handler that raises any exception
[fun e -> raise e]. *)
Expand Down Expand Up @@ -89,7 +93,7 @@ module Shallow : sig
type ('a,'b) handler =
{ retc: 'a -> 'b;
exnc: exn -> 'b;
effc: 'c.'c eff -> (('c,'a) continuation -> 'b) option }
effc: 'c.'c t -> (('c,'a) continuation -> 'b) option }
(** [('a,'b) handler] is a handler record with three fields -- [retc]
is the value handler, [exnc] handles exceptions, and [effc] handles the
effects performed by the computation enclosed by the handler. *)
Expand Down
4 changes: 2 additions & 2 deletions testsuite/tests/backtrace/backtrace_effects.ml
Expand Up @@ -7,7 +7,7 @@
open Effect
open Effect.Deep

type _ eff += E : unit eff
type _ t += E : unit t

let bar i =
if i < 0 then begin
Expand All @@ -29,7 +29,7 @@ let baz () =
match_with foo 10
{ retc = (fun x -> ());
exnc = (fun e -> raise e);
effc = fun (type a) (e : a eff) ->
effc = fun (type a) (e : a t) ->
match e with
| E -> Some (fun (k : (a, _) continuation) ->
print_endline "(** get_continuation_callstack **)";
Expand Down
8 changes: 4 additions & 4 deletions testsuite/tests/backtrace/backtrace_effects_nested.ml
Expand Up @@ -13,8 +13,8 @@ reference = "${test_source_directory}/backtrace_effects_nested.flambda.reference
open Effect
open Effect.Deep

type _ eff += E : unit eff
| Inc : unit eff
type _ t += E : unit t
| Inc : unit t

let blorp () =
perform Inc;
Expand All @@ -23,7 +23,7 @@ let blorp () =

let baz () =
try_with blorp ()
{ effc = fun (type a) (e : a eff) ->
{ effc = fun (type a) (e : a t) ->
match e with
| Inc -> Some (fun (k : (a, _) continuation) ->
1 + continue k ())
Expand All @@ -33,7 +33,7 @@ let f () =
match_with baz ()
{ retc = (fun x -> Printf.printf "%d\n" x);
exnc = (fun e -> raise e);
effc = fun (type a) (e : a eff) ->
effc = fun (type a) (e : a t) ->
match e with
| E -> Some (fun (k : (a, _) continuation) ->
Deep.get_callstack k 100 |>
Expand Down
6 changes: 3 additions & 3 deletions testsuite/tests/callback/nested_fiber.ml
Expand Up @@ -11,7 +11,7 @@ external caml_to_c : (unit -> 'a) -> 'a = "caml_to_c"
open Effect
open Effect.Deep

type _ eff += E : unit eff
type _ t += E : unit t

type 'a tree = Empty | Node of 'a tree * 'a tree

Expand All @@ -34,7 +34,7 @@ let f () =
match_with g ()
{ retc = (fun () -> Printf.printf "g() returned: %d\n%!" !z);
exnc = (fun e -> raise e);
effc = fun (type a) (e : a eff) ->
effc = fun (type a) (e : a t) ->
match e with
| E -> Some (fun (k : (a, _) continuation) -> assert false)
| _ -> None };
Expand All @@ -46,7 +46,7 @@ let () =
match_with f ()
{ retc = (fun () -> Printf.printf "f() returned: %d\n%!" !z);
exnc = (fun e -> raise e);
effc = fun (type a) (e : a eff) ->
effc = fun (type a) (e : a t) ->
match e with
| E -> Some (fun k -> assert false)
| _ -> None };
Expand Down
4 changes: 2 additions & 2 deletions testsuite/tests/callback/stack_overflow.ml
Expand Up @@ -17,15 +17,15 @@ let rec deep = function
open Effect
open Effect.Deep

type _ eff += E : unit eff
type _ t += E : unit t

let () =
Printf.printf "%d\n%d\n%!"
(!(deep 1000))
(match_with deep 1000
{ retc = (fun x -> !x);
exnc = (fun e -> raise e);
effc = fun (type a) (e : a eff) ->
effc = fun (type a) (e : a t) ->
match e with
| E -> Some (fun k -> assert false)
| _ -> None })
4 changes: 2 additions & 2 deletions testsuite/tests/callback/test7.ml
Expand Up @@ -13,7 +13,7 @@
open Effect
open Effect.Deep

type _ eff += E : unit eff
type _ t += E : unit t

let printf = Printf.printf

Expand All @@ -36,7 +36,7 @@ let _ =
perform E)
end;
printf "[Caml] Return from caml_to_c\n%!") ()
{ effc = fun (type a) (e : a eff) ->
{ effc = fun (type a) (e : a t) ->
match e with
| E -> Some (fun k -> printf "[Caml] Caught effect\n%!")
| _ -> None }
4 changes: 2 additions & 2 deletions testsuite/tests/effects/backtrace.ml
Expand Up @@ -22,7 +22,7 @@ let rec bar i =
end
[@@inline never]

type _ eff += Wait : unit eff
type _ t += Wait : unit t

let task1 () =
try
Expand All @@ -45,7 +45,7 @@ let main () =
exnc = (fun e ->
let open Printexc in
print_raw_backtrace stdout (get_raw_backtrace ()));
effc = fun (type a) (e : a eff) ->
effc = fun (type a) (e : a t) ->
match e with
| Wait -> Some (fun (k : (a, _) continuation) ->
discontinue_with_backtrace k x bt)
Expand Down
4 changes: 2 additions & 2 deletions testsuite/tests/effects/cmphash.ml
Expand Up @@ -4,11 +4,11 @@
open Effect
open Effect.Deep

type _ eff += E : unit eff
type _ t += E : unit t

let () =
try_with perform E
{ effc = fun (type a) (e : a eff) ->
{ effc = fun (type a) (e : a t) ->
match e with
| E -> Some (fun k ->
begin match k = k with
Expand Down
4 changes: 2 additions & 2 deletions testsuite/tests/effects/evenodd.ml
Expand Up @@ -4,12 +4,12 @@
open Effect
open Effect.Deep

type _ eff += E : unit eff
type _ t += E : unit t

let rec even n =
if n = 0 then true
else try_with odd (n-1)
{ effc = fun (type a) (e : a eff) ->
{ effc = fun (type a) (e : a t) ->
match e with
| E -> Some (fun k -> assert false)
| _ -> None }
Expand Down
2 changes: 1 addition & 1 deletion testsuite/tests/effects/issue479.compilers.reference
Expand Up @@ -3,7 +3,7 @@ type ('a, 'container) iterator = ('a -> unit) -> 'container -> unit
type 'a generator = unit -> 'a option
type ('a, 'container) iter2gen =
('a, 'container) iterator -> 'container -> 'a generator
type _ Stdlib.Effect.eff += Hold : unit Effect.eff
type _ Stdlib.Effect.t += Hold : unit Effect.t
val iter2gen : (int, 'a) iter2gen = <fun>
val f : unit -> unit = <fun>
Hold 1
Expand Down
4 changes: 2 additions & 2 deletions testsuite/tests/effects/issue479.ml
Expand Up @@ -19,7 +19,7 @@ type ('a,'container) iter2gen =
-> 'container
-> 'a generator;;

type _ eff += Hold: unit eff
type _ t += Hold: unit t

let iter2gen : _ iter2gen = fun iter c ->
let r = ref None in
Expand All @@ -31,7 +31,7 @@ let iter2gen : _ iter2gen = fun iter c ->
match_with (iter suspending_f) c
{ retc = (fun _ -> fun () -> None);
exnc = (fun e -> raise e);
effc = fun (type a) (e : a eff) ->
effc = fun (type a) (e : a t) ->
match e with
| Hold -> Some (fun (k : (a,_) continuation) ->
fun () ->
Expand Down
4 changes: 2 additions & 2 deletions testsuite/tests/effects/overflow.ml
Expand Up @@ -4,7 +4,7 @@
open Effect
open Effect.Deep

type _ eff += E : unit eff
type _ t += E : unit t

let f a b c d e f g h =
let bb = b + b in
Expand Down Expand Up @@ -34,7 +34,7 @@ let () =
match_with (fun _ -> f 1 2 3 4 5 6 7 8) ()
{ retc = (fun n -> Printf.printf "%d\n" n);
exnc = (fun e -> raise e);
effc = fun (type a) (e : a eff) ->
effc = fun (type a) (e : a t) ->
match e with
| E -> Some (fun k -> assert false)
| _ -> None }
6 changes: 3 additions & 3 deletions testsuite/tests/effects/partial.ml
Expand Up @@ -4,12 +4,12 @@
open Effect
open Effect.Deep

type _ eff += E : unit eff
type _ t += E : unit t
exception Done

let handle_partial f =
try_with f ()
{ effc = fun (type a) (e : a eff) ->
{ effc = fun (type a) (e : a t) ->
match e with
| E -> Some (fun k -> assert false)
| _ -> None }
Expand All @@ -22,7 +22,7 @@ let () =
exnc = (function
| Done -> print_string "ok\n"
| e -> raise e);
effc = fun (type a) (e : a eff) ->
effc = fun (type a) (e : a t) ->
match e with
| E -> Some (fun (k : (a, _) continuation) -> discontinue k Done)
| _ -> None }
10 changes: 5 additions & 5 deletions testsuite/tests/effects/reperform.ml
Expand Up @@ -4,16 +4,16 @@
open Effect
open Effect.Deep

type _ eff += E : int -> int eff
| F : unit eff
type _ t += E : int -> int t
| F : unit t

let rec nest = function
| 0 -> perform (E 42)
| n ->
match_with (fun _ -> Printf.printf "[%d\n" n; nest (n - 1)) ()
{ retc = (fun x -> Printf.printf " %d]\n" n; x);
exnc = (fun e -> Printf.printf " !%d]\n" n; raise e);
effc = fun (type a) (e : a eff) ->
effc = fun (type a) (e : a t) ->
match e with
| F -> Some (fun k -> assert false)
| _ -> None }
Expand All @@ -22,7 +22,7 @@ let () =
match_with nest 5
{ retc = (fun x -> Printf.printf "= %d\n" x);
exnc = (fun e -> raise e);
effc = fun (type a) (e : a eff) ->
effc = fun (type a) (e : a t) ->
match e with
| E n -> Some (fun (k : (a, _) continuation) -> continue k (n + 100))
| _ -> None }
Expand All @@ -31,7 +31,7 @@ let () =
match_with nest 5
{ retc = (fun x -> assert false);
exnc = (fun e -> Printf.printf "%s\n" (Printexc.to_string e));
effc = fun (type a) (e : a eff) ->
effc = fun (type a) (e : a t) ->
match e with
| F -> Some (fun k -> assert false)
| _ -> None }