From df197a82ce3ef1fef223911c8bdbd16695261c2e Mon Sep 17 00:00:00 2001 From: Thomas Leonard Date: Thu, 4 May 2023 20:55:22 +0100 Subject: [PATCH 1/3] Remove some deprecated APIs These were all already marked as deprecated in Eio 0.8. --- lib_eio/core/eio__core.mli | 12 ------------ lib_eio/core/fiber.ml | 2 -- lib_eio/eio.ml | 3 --- lib_eio/eio.mli | 7 ------- lib_eio/flow.ml | 2 -- lib_eio/flow.mli | 3 --- lib_eio/fs.ml | 3 --- lib_eio/net.ml | 3 --- lib_eio/net.mli | 8 -------- lib_eio/time.ml | 10 ---------- lib_eio/time.mli | 3 --- 11 files changed, 56 deletions(-) diff --git a/lib_eio/core/eio__core.mli b/lib_eio/core/eio__core.mli index 1e0a9d0fc..e15b887c7 100644 --- a/lib_eio/core/eio__core.mli +++ b/lib_eio/core/eio__core.mli @@ -330,18 +330,6 @@ module Fiber : sig @param max_fibers Maximum number of fibers to run concurrently *) end - val filter : ?max_fibers:int -> ('a -> bool) -> 'a list -> 'a list - [@@ocaml.deprecated "Use `Eio.Fiber.List.filter` instead."] - - val map : ?max_fibers:int -> ('a -> 'b) -> 'a list -> 'b list - [@@ocaml.deprecated "Use `Eio.Fiber.List.map instead."] - - val filter_map : ?max_fibers:int -> ('a -> 'b option) -> 'a list -> 'b list - [@@ocaml.deprecated "Use `Eio.Fiber.List.filter_map instead."] - - val iter : ?max_fibers:int -> ('a -> unit) -> 'a list -> unit - [@@ocaml.deprecated "Use `Eio.Fiber.List.iter instead."] - (** {2 Fiber-local variables} Each fiber maintains a map of additional variables associated with it, diff --git a/lib_eio/core/fiber.ml b/lib_eio/core/fiber.ml index 687ec8118..7ed9101a2 100644 --- a/lib_eio/core/fiber.ml +++ b/lib_eio/core/fiber.ml @@ -271,8 +271,6 @@ module List = struct end -include List - type 'a key = 'a Hmap.key let create_key () = Hmap.Key.create () diff --git a/lib_eio/eio.ml b/lib_eio/eio.ml index edf5a041f..a86d2afaa 100644 --- a/lib_eio/eio.ml +++ b/lib_eio/eio.ml @@ -1,14 +1,11 @@ include Eio__core -module Fibre = Fiber - module Debug = Private.Debug let traceln = Debug.traceln module Std = struct module Promise = Promise module Fiber = Fiber - module Fibre = Fiber module Switch = Switch let traceln = Debug.traceln end diff --git a/lib_eio/eio.mli b/lib_eio/eio.mli index 03aea967b..ab7d0616e 100644 --- a/lib_eio/eio.mli +++ b/lib_eio/eio.mli @@ -24,10 +24,6 @@ module Promise = Eio__core.Promise (** A fiber is a light-weight thread. *) module Fiber = Eio__core.Fiber -(**/**) -module Fibre = Fiber [@@deprecated "Now spelt Fiber"] -(**/**) - (** A counting semaphore. *) module Semaphore = Semaphore @@ -47,9 +43,6 @@ module Cancel = Eio__core.Cancel module Std : sig module Promise = Promise module Fiber = Fiber - (**/**) - module Fibre = Fiber [@@deprecated "Now spelt Fiber"] - (**/**) module Switch = Switch val traceln : diff --git a/lib_eio/flow.ml b/lib_eio/flow.ml index 6c34fc78a..cbb461771 100644 --- a/lib_eio/flow.ml +++ b/lib_eio/flow.ml @@ -107,5 +107,3 @@ class virtual two_way = object (_ : ) end let shutdown (t : #two_way) = t#shutdown - -let read = single_read diff --git a/lib_eio/flow.mli b/lib_eio/flow.mli index 6f3cbd9eb..31832b2ef 100644 --- a/lib_eio/flow.mli +++ b/lib_eio/flow.mli @@ -15,9 +15,6 @@ class virtual source : object method virtual read_into : Cstruct.t -> int end -val read : #source -> Cstruct.t -> int -[@@deprecated "Use single_read if you really want this."] - val single_read : #source -> Cstruct.t -> int (** [single_read src buf] reads one or more bytes into [buf]. diff --git a/lib_eio/fs.ml b/lib_eio/fs.ml index 0f8410927..4897a9fef 100644 --- a/lib_eio/fs.ml +++ b/lib_eio/fs.ml @@ -1,8 +1,5 @@ (** Defines types used by file-systems. *) -(** Tranditional Unix permissions. *) -module Unix_perm = File.Unix_perm [@@deprecated "Moved to File.Unix_perm"] - type path = string type error = diff --git a/lib_eio/net.ml b/lib_eio/net.ml index b7cac362d..c9e77ffa3 100644 --- a/lib_eio/net.ml +++ b/lib_eio/net.ml @@ -188,9 +188,6 @@ let accept_fork ~sw (t : #listening_socket) ~on_error handle = ) ) -let accept_sub ~sw (t : #listening_socket) ~on_error handle = - accept_fork ~sw t ~on_error (fun flow addr -> Switch.run (fun sw -> handle ~sw flow addr)) - class virtual datagram_socket = object inherit socket method virtual send : Sockaddr.datagram -> Cstruct.t -> unit diff --git a/lib_eio/net.mli b/lib_eio/net.mli index 506c4bfcc..d9397f55a 100644 --- a/lib_eio/net.mli +++ b/lib_eio/net.mli @@ -211,14 +211,6 @@ val accept_fork : If you don't want to handle connection errors, use [~on_error:raise] to cancel the caller's context. *) -val accept_sub : - sw:Switch.t -> - #listening_socket -> - on_error:(exn -> unit) -> - (sw:Switch.t -> stream_socket -> Sockaddr.stream -> unit) -> - unit -[@@deprecated "Use accept_fork instead"] - (** {2 Running Servers} *) val run_server : diff --git a/lib_eio/time.ml b/lib_eio/time.ml index 049980f51..4e4feadf9 100644 --- a/lib_eio/time.ml +++ b/lib_eio/time.ml @@ -49,7 +49,6 @@ let with_timeout_exn t d = Fiber.first (fun () -> sleep t d; raise Timeout) module Timeout = struct type t = | Timeout of Mono.t * Mtime.Span.t - | Deprecated of clock * float | Unlimited let none = Unlimited @@ -58,24 +57,17 @@ module Timeout = struct let seconds clock time = v clock (Mono.span_of_s time) - let of_s clock time = - Deprecated ((clock :> clock), time) - let run t fn = match t with | Unlimited -> fn () | Timeout (clock, d) -> Fiber.first (fun () -> Mono.sleep_span clock d; Error `Timeout) fn - | Deprecated (clock, d) -> - Fiber.first (fun () -> sleep clock d; Error `Timeout) fn let run_exn t fn = match t with | Unlimited -> fn () | Timeout (clock, d) -> Fiber.first (fun () -> Mono.sleep_span clock d; raise Timeout) fn - | Deprecated (clock, d) -> - Fiber.first (fun () -> sleep clock d; raise Timeout) fn let pp_duration f d = if d >= 0.001 && d < 0.1 then @@ -90,6 +82,4 @@ module Timeout = struct | Timeout (_clock, d) -> let d = Mtime.Span.to_float_ns d /. 1e9 in pp_duration f d - | Deprecated (_clock, d) -> - pp_duration f d end diff --git a/lib_eio/time.mli b/lib_eio/time.mli index 5018e82bb..0d2739e16 100644 --- a/lib_eio/time.mli +++ b/lib_eio/time.mli @@ -56,9 +56,6 @@ val with_timeout_exn : #clock -> float -> (unit -> 'a) -> 'a module Timeout : sig type t - val of_s : #clock -> float -> t - [@@deprecated "Use [seconds] instead, with a monotonic clock"] - val v : #Mono.t -> Mtime.Span.t -> t (** [v clock duration] is a timeout of [duration], as measured by [clock]. Internally, this is just the tuple [(clock, duration)]. *) From 357a8f7169fce30e147174afb98b9fd292b7f21f Mon Sep 17 00:00:00 2001 From: Thomas Leonard Date: Fri, 5 May 2023 12:05:39 +0100 Subject: [PATCH 2/3] Deprecate Fiber.fork_sub Originally, you needed the parent switch to create the child one, but that happens automatically now, so we don't need a special function for this. --- lib_eio/core/eio__core.mli | 9 +-------- tests/fiber.md | 2 +- tests/switch.md | 22 +++++++++++++++------- 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/lib_eio/core/eio__core.mli b/lib_eio/core/eio__core.mli index e15b887c7..4b842da63 100644 --- a/lib_eio/core/eio__core.mli +++ b/lib_eio/core/eio__core.mli @@ -235,14 +235,7 @@ module Fiber : sig The calling fiber is placed at the head of the run queue, ahead of any previous items. *) val fork_sub : sw:Switch.t -> on_error:(exn -> unit) -> (Switch.t -> unit) -> unit - (** [fork_sub ~sw ~on_error fn] is like [fork], but it creates a new sub-switch for the fiber. - - This means that you can cancel the child switch without cancelling the parent. - This is a convenience function for running {!Switch.run} inside a {!fork}. - - @param on_error This is called if the fiber raises an exception. - If it raises in turn, the parent switch is failed. - It is not called if the parent [sw] itself is cancelled. *) + [@@deprecated "Use Fiber.fork and Switch.run separately instead"] val fork_promise : sw:Switch.t -> (unit -> 'a) -> 'a Promise.or_exn (** [fork_promise ~sw fn] schedules [fn ()] to run in a new fiber and returns a promise for its result. diff --git a/tests/fiber.md b/tests/fiber.md index 877af7681..53cdf7662 100644 --- a/tests/fiber.md +++ b/tests/fiber.md @@ -218,7 +218,7 @@ Exception: Stdlib.Exit. Exception: Failure "simulated error". ``` -# Fiber.fork +# Fiber.fork_promise `Fiber.fork_promise ~sw` inherits the cancellation context from `sw`, not from the current fiber: diff --git a/tests/switch.md b/tests/switch.md index df1fed936..cbe3bbbb2 100644 --- a/tests/switch.md +++ b/tests/switch.md @@ -10,6 +10,14 @@ open Eio.Std let run (fn : Switch.t -> _) = Eio_mock.Backend.run @@ fun () -> Switch.run fn + +let fork_sub ~sw ~on_error fn = + Fiber.fork ~sw (fun () -> + try Switch.run fn + with + | Eio.Cancel.Cancelled _ -> () + | ex -> on_error ex + ) ``` # Test cases @@ -200,8 +208,8 @@ Child switches are cancelled when the parent is cancelled, but `on_error` isn't # run (fun sw -> let p, _ = Promise.create () in let on_error ex = traceln "child: %s" (Printexc.to_string ex) in - Fiber.fork_sub ~sw ~on_error (fun sw -> traceln "Child 1"; Promise.await p); - Fiber.fork_sub ~sw ~on_error (fun sw -> traceln "Child 2"; Promise.await p); + fork_sub ~sw ~on_error (fun sw -> traceln "Child 1"; Promise.await p); + fork_sub ~sw ~on_error (fun sw -> traceln "Child 2"; Promise.await p); Switch.fail sw (Failure "Cancel parent") );; +Child 1 @@ -216,8 +224,8 @@ A child can fail independently of the parent: let p1, r1 = Promise.create () in let p2, r2 = Promise.create () in let on_error ex = traceln "child: %s" (Printexc.to_string ex) in - Fiber.fork_sub ~sw ~on_error (fun sw -> traceln "Child 1"; Promise.await_exn p1); - Fiber.fork_sub ~sw ~on_error (fun sw -> traceln "Child 2"; Promise.await_exn p2); + fork_sub ~sw ~on_error (fun sw -> traceln "Child 1"; Promise.await_exn p1); + fork_sub ~sw ~on_error (fun sw -> traceln "Child 2"; Promise.await_exn p2); Promise.resolve_error r1 (Failure "Child error"); Promise.resolve_ok r2 (); Fiber.yield (); @@ -237,7 +245,7 @@ A child can be cancelled independently of the parent: let p, _ = Promise.create () in let on_error ex = traceln "child: %s" (Printexc.to_string ex) in let child = ref None in - Fiber.fork_sub ~sw ~on_error (fun sw -> + fork_sub ~sw ~on_error (fun sw -> traceln "Child 1"; child := Some sw; Promise.await ~sw p @@ -258,7 +266,7 @@ A child error handler raises: # run (fun sw -> let p, r = Promise.create () in let on_error = raise in - Fiber.fork_sub ~sw ~on_error (fun sw -> traceln "Child"; Promise.await_exn p); + fork_sub ~sw ~on_error (fun sw -> traceln "Child"; Promise.await_exn p); Promise.resolve_error r (Failure "Child error escapes"); Fiber.yield (); traceln "Not reached" @@ -273,7 +281,7 @@ A child error handler deals with the exception: # run (fun sw -> let p, r = Promise.create () in let on_error = traceln "caught: %a" Fmt.exn in - Fiber.fork_sub ~sw ~on_error (fun sw -> traceln "Child"; Promise.await_exn p); + fork_sub ~sw ~on_error (fun sw -> traceln "Child"; Promise.await_exn p); Promise.resolve_error r (Failure "Child error is caught"); Fiber.yield (); traceln "Still running" From bc1603828514b3dc80a6fc1c37739326d7dce85d Mon Sep 17 00:00:00 2001 From: Thomas Leonard Date: Fri, 5 May 2023 12:07:27 +0100 Subject: [PATCH 3/3] Fix Process link in README Link to the mli, not the ml file. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1a8d321d2..7b5bb0d4a 100644 --- a/README.md +++ b/README.md @@ -1875,4 +1875,4 @@ Some background about the effects system can be found in: [kcas]: https://github.com/ocaml-multicore/kcas [Meio]: https://github.com/tarides/meio [Lambda Capabilities]: https://roscidus.com/blog/blog/2023/04/26/lambda-capabilities/ -[Eio.Process]: https://github.com/ocaml-multicore/eio/blob/main/lib_eio/process.ml +[Eio.Process]: https://github.com/ocaml-multicore/eio/blob/main/lib_eio/process.mli