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

Deprecation cleanups #508

Merged
merged 3 commits into from
May 5, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
21 changes: 1 addition & 20 deletions lib_eio/core/eio__core.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -330,18 +323,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,
Expand Down
2 changes: 0 additions & 2 deletions lib_eio/core/fiber.ml
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,6 @@ module List = struct

end

include List

type 'a key = 'a Hmap.key

let create_key () = Hmap.Key.create ()
Expand Down
3 changes: 0 additions & 3 deletions lib_eio/eio.ml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
7 changes: 0 additions & 7 deletions lib_eio/eio.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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 :
Expand Down
2 changes: 0 additions & 2 deletions lib_eio/flow.ml
Original file line number Diff line number Diff line change
Expand Up @@ -107,5 +107,3 @@ class virtual two_way = object (_ : <source; sink; ..>)
end

let shutdown (t : #two_way) = t#shutdown

let read = single_read
3 changes: 0 additions & 3 deletions lib_eio/flow.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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].

Expand Down
3 changes: 0 additions & 3 deletions lib_eio/fs.ml
Original file line number Diff line number Diff line change
@@ -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 =
Expand Down
3 changes: 0 additions & 3 deletions lib_eio/net.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 0 additions & 8 deletions lib_eio/net.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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 :
Expand Down
10 changes: 0 additions & 10 deletions lib_eio/time.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
3 changes: 0 additions & 3 deletions lib_eio/time.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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)]. *)
Expand Down
2 changes: 1 addition & 1 deletion tests/fiber.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
22 changes: 15 additions & 7 deletions tests/switch.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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 ();
Expand All @@ -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
Expand All @@ -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"
Expand All @@ -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"
Expand Down