Skip to content

Commit

Permalink
More thoroughly mark Lwt_sequence deprecated
Browse files Browse the repository at this point in the history
Lwt.add_task_l and Lwt.add_task_r are also deprecated by this.

Part of #361.
  • Loading branch information
aantron committed Nov 10, 2017
1 parent 6170bc1 commit c84b810
Show file tree
Hide file tree
Showing 17 changed files with 116 additions and 12 deletions.
8 changes: 8 additions & 0 deletions src/core/lwt.ml
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,14 @@



(* [Lwt_sequnece] is deprecated to prevent users from using it, but it is used
internally by Lwt. *)
[@@@ocaml.warning "-3"]
module Lwt_sequence = Lwt_sequence
[@@@ocaml.warning "+3"]



(* Some sequence-associated storage types
Sequence-associated storage is defined and documented later, in module
Expand Down
10 changes: 10 additions & 0 deletions src/core/lwt.mli
Original file line number Diff line number Diff line change
Expand Up @@ -1621,7 +1621,12 @@ val waiter_of_wakener : 'a u -> 'a t

(** {3 Linked lists of promises} *)

[@@@ocaml.warning "-3"]

val add_task_r : ('a u) Lwt_sequence.t -> 'a t
[@@ocaml.deprecated
" Deprecated because Lwt_sequence is an implementation detail of Lwt. See
https://github.com/ocsigen/lwt/issues/361"]
(** [Lwt.add_task_r sequence] is equivalent to
{[
Expand All @@ -1638,9 +1643,14 @@ p
optimization, which may be removed. *)

val add_task_l : ('a u) Lwt_sequence.t -> 'a t
[@@ocaml.deprecated
" Deprecated because Lwt_sequence is an implementation detail of Lwt. See
https://github.com/ocsigen/lwt/issues/361"]
(** Like {!Lwt.add_task_r}, but the equivalent code calls {!Lwt_sequence.add_l}
instead. *)

[@@@ocaml.warning "+3"]



(** {3 Pausing} *)
Expand Down
8 changes: 7 additions & 1 deletion src/core/lwt_condition.ml
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,18 @@
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*)

(* [Lwt_sequnece] is deprecated to prevent users from using it, but it is used
internally by Lwt. *)
[@@@ocaml.warning "-3"]
module Lwt_sequence = Lwt_sequence
[@@@ocaml.warning "+3"]

type 'a t = 'a Lwt.u Lwt_sequence.t

let create = Lwt_sequence.create

let wait ?mutex cvar =
let waiter = Lwt.add_task_r cvar in
let waiter = (Lwt.add_task_r [@ocaml.warning "-3"]) cvar in
let () =
match mutex with
| Some m -> Lwt_mutex.unlock m
Expand Down
8 changes: 7 additions & 1 deletion src/core/lwt_mutex.ml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@
* 02111-1307, USA.
*)

(* [Lwt_sequnece] is deprecated to prevent users from using it, but it is used
internally by Lwt. *)
[@@@ocaml.warning "-3"]
module Lwt_sequence = Lwt_sequence
[@@@ocaml.warning "+3"]

open Lwt.Infix

type t = { mutable locked : bool; mutable waiters : unit Lwt.u Lwt_sequence.t }
Expand All @@ -28,7 +34,7 @@ let create () = { locked = false; waiters = Lwt_sequence.create () }

let lock m =
if m.locked then
Lwt.add_task_r m.waiters
(Lwt.add_task_r [@ocaml.warning "-3"]) m.waiters
else begin
m.locked <- true;
Lwt.return_unit
Expand Down
8 changes: 7 additions & 1 deletion src/core/lwt_mvar.ml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*)

(* [Lwt_sequnece] is deprecated to prevent users from using it, but it is used
internally by Lwt. *)
[@@@ocaml.warning "-3"]
module Lwt_sequence = Lwt_sequence
[@@@ocaml.warning "+3"]

type 'a t = {
mutable mvar_contents : 'a option;
(* Current contents *)
Expand Down Expand Up @@ -82,7 +88,7 @@ let take_available mvar =
let take mvar =
match take_available mvar with
| Some v -> Lwt.return v
| None -> Lwt.add_task_r mvar.readers
| None -> (Lwt.add_task_r [@ocaml.warning "-3"]) mvar.readers

let is_empty mvar =
match mvar.mvar_contents with
Expand Down
8 changes: 7 additions & 1 deletion src/core/lwt_pool.ml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*)

(* [Lwt_sequnece] is deprecated to prevent users from using it, but it is used
internally by Lwt. *)
[@@@ocaml.warning "-3"]
module Lwt_sequence = Lwt_sequence
[@@@ocaml.warning "+3"]

open Lwt.Infix

(*
Expand Down Expand Up @@ -131,7 +137,7 @@ let acquire p =
create_member p
else
(* Limit reached: wait for a free one. *)
Lwt.add_task_r p.waiters >>= check_elt p
(Lwt.add_task_r [@ocaml.warning "-3"]) p.waiters >>= check_elt p
else
(* Take the first free member and validate it. *)
let c = Queue.take p.list in
Expand Down
4 changes: 4 additions & 0 deletions src/core/lwt_sequence.mli
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@
doubly-linked list library as an alternative.
*)

[@@@ocaml.deprecated
" This module is an implementation detail of Lwt. See
https://github.com/ocsigen/lwt/issues/361"]

type 'a t
(** Type of a sequence holding values of type ['a] *)

Expand Down
8 changes: 7 additions & 1 deletion src/preemptive/lwt_preemptive.ml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*)

(* [Lwt_sequnece] is deprecated to prevent users from using it, but it is used
internally by Lwt. *)
[@@@ocaml.warning "-3"]
module Lwt_sequence = Lwt_sequence
[@@@ocaml.warning "+3"]

open Lwt.Infix

(* +-----------------------------------------------------------------+
Expand Down Expand Up @@ -143,7 +149,7 @@ let get_worker () =
else if !threads_count < !max_threads then
Lwt.return (make_worker ())
else
Lwt.add_task_r waiters
(Lwt.add_task_r [@ocaml.warning "-3"]) waiters

(* +-----------------------------------------------------------------+
| Initialisation, and dynamic parameters reset |
Expand Down
6 changes: 6 additions & 0 deletions src/unix/lwt_daemon.ml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@
* 02111-1307, USA.
*)

(* [Lwt_sequnece] is deprecated to prevent users from using it, but it is used
internally by Lwt. *)
[@@@ocaml.warning "-3"]
module Lwt_sequence = Lwt_sequence
[@@@ocaml.warning "+3"]

open Lwt.Infix

let rec copy ic logger =
Expand Down
6 changes: 6 additions & 0 deletions src/unix/lwt_engine.ml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@
* 02111-1307, USA.
*)

(* [Lwt_sequnece] is deprecated to prevent users from using it, but it is used
internally by Lwt. *)
[@@@ocaml.warning "-3"]
module Lwt_sequence = Lwt_sequence
[@@@ocaml.warning "+3"]

(* +-----------------------------------------------------------------+
| Events |
+-----------------------------------------------------------------+ *)
Expand Down
6 changes: 6 additions & 0 deletions src/unix/lwt_gc.ml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@
* 02111-1307, USA.
*)

(* [Lwt_sequnece] is deprecated to prevent users from using it, but it is used
internally by Lwt. *)
[@@@ocaml.warning "-3"]
module Lwt_sequence = Lwt_sequence
[@@@ocaml.warning "+3"]

let ensure_termination t =
if Lwt.state t = Lwt.Sleep then begin
let hook = Lwt_sequence.add_l (fun _ -> t) Lwt_main.exit_hooks in
Expand Down
10 changes: 8 additions & 2 deletions src/unix/lwt_io.ml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@
* 02111-1307, USA.
*)

(* [Lwt_sequnece] is deprecated to prevent users from using it, but it is used
internally by Lwt. *)
[@@@ocaml.warning "-3"]
module Lwt_sequence = Lwt_sequence
[@@@ocaml.warning "+3"]

open Lwt.Infix

exception Channel_closed of string
Expand Down Expand Up @@ -372,7 +378,7 @@ let primitive f wrapper = match wrapper.state with
Lwt.return_unit)

| Busy_primitive | Busy_atomic _ | Waiting_for_busy ->
Lwt.add_task_r wrapper.queued >>= fun () ->
(Lwt.add_task_r [@ocaml.warning "-3"]) wrapper.queued >>= fun () ->
begin match wrapper.state with
| Closed ->
(* The channel has been closed while we were waiting *)
Expand Down Expand Up @@ -416,7 +422,7 @@ let atomic f wrapper = match wrapper.state with
Lwt.return_unit)

| Busy_primitive | Busy_atomic _ | Waiting_for_busy ->
Lwt.add_task_r wrapper.queued >>= fun () ->
(Lwt.add_task_r [@ocaml.warning "-3"]) wrapper.queued >>= fun () ->
begin match wrapper.state with
| Closed ->
(* The channel has been closed while we were waiting *)
Expand Down
8 changes: 7 additions & 1 deletion src/unix/lwt_main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,19 @@
* 02111-1307, USA.
*)

(* [Lwt_sequnece] is deprecated to prevent users from using it, but it is used
internally by Lwt. *)
[@@@ocaml.warning "-3"]
module Lwt_sequence = Lwt_sequence
[@@@ocaml.warning "+3"]

open Lwt.Infix

let enter_iter_hooks = Lwt_sequence.create ()
let leave_iter_hooks = Lwt_sequence.create ()
let yielded = Lwt_sequence.create ()

let yield () = Lwt.add_task_r yielded
let yield () = (Lwt.add_task_r [@ocaml.warning "-3"]) yielded

let rec run t =
(* Wakeup paused threads now. *)
Expand Down
4 changes: 4 additions & 0 deletions src/unix/lwt_main.mli
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ val yield : unit -> unit Lwt.t
(** [yield ()] is a threads which suspends itself and then resumes
as soon as possible and terminates. *)

[@@@ocaml.warning "-3"]

val enter_iter_hooks : (unit -> unit) Lwt_sequence.t
(** Functions that are called before the main iteration. *)

Expand All @@ -56,5 +58,7 @@ val exit_hooks : (unit -> unit Lwt.t) Lwt_sequence.t
- each hook is called exactly one time
- exceptions raised by hooks are ignored *)

[@@@ocaml.warning "+3"]

val at_exit : (unit -> unit Lwt.t) -> unit
(** [at_exit hook] adds hook at the left of [exit_hooks]*)
6 changes: 6 additions & 0 deletions src/unix/lwt_unix.cppo.ml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@
* 02111-1307, USA.
*)

(* [Lwt_sequnece] is deprecated to prevent users from using it, but it is used
internally by Lwt. *)
[@@@ocaml.warning "-3"]
module Lwt_sequence = Lwt_sequence
[@@@ocaml.warning "+3"]

open Lwt.Infix

(* +-----------------------------------------------------------------+
Expand Down
14 changes: 10 additions & 4 deletions test/core/test_lwt.ml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@
* 02111-1307, USA.
*)

(* [Lwt_sequnece] is deprecated to prevent users from using it, but it is used
internally by Lwt. *)
[@@@ocaml.warning "-3"]
module Lwt_sequence = Lwt_sequence
[@@@ocaml.warning "+3"]

open Test


Expand Down Expand Up @@ -3311,8 +3317,8 @@ let lwt_sequence_contains sequence list =
let lwt_sequence_tests = suite "add_task_l and add_task_r" [
test "add_task_r" begin fun () ->
let sequence = Lwt_sequence.create () in
let p = Lwt.add_task_r sequence in
let p' = Lwt.add_task_r sequence in
let p = (Lwt.add_task_r [@ocaml.warning "-3"]) sequence in
let p' = (Lwt.add_task_r [@ocaml.warning "-3"]) sequence in
assert (Lwt.state p = Lwt.Sleep);
assert (lwt_sequence_contains sequence [Obj.magic p; Obj.magic p']);
Lwt.cancel p;
Expand All @@ -3323,8 +3329,8 @@ let lwt_sequence_tests = suite "add_task_l and add_task_r" [

test "add_task_l" begin fun () ->
let sequence = Lwt_sequence.create () in
let p = Lwt.add_task_l sequence in
let p' = Lwt.add_task_l sequence in
let p = (Lwt.add_task_l [@ocaml.warning "-3"]) sequence in
let p' = (Lwt.add_task_l [@ocaml.warning "-3"]) sequence in
assert (Lwt.state p = Lwt.Sleep);
assert (lwt_sequence_contains sequence [Obj.magic p'; Obj.magic p]);
Lwt.cancel p;
Expand Down
6 changes: 6 additions & 0 deletions test/unix/test_lwt_io.ml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@
* 02111-1307, USA.
*)

(* [Lwt_sequnece] is deprecated to prevent users from using it, but it is used
internally by Lwt. *)
[@@@ocaml.warning "-3"]
module Lwt_sequence = Lwt_sequence
[@@@ocaml.warning "+3"]

open Test
open Lwt.Infix

Expand Down

0 comments on commit c84b810

Please sign in to comment.