Skip to content

Commit a8122b7

Browse files
Merge pull request #968 from ocsigen/remove-some-long-deprecated-functions
Remove several deprecated values, especially result-related
2 parents c70e8b6 + 2bc4fbd commit a8122b7

File tree

7 files changed

+52
-223
lines changed

7 files changed

+52
-223
lines changed

CHANGES

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,18 @@
44

55
* Lwt_result.catch now takes a function (unit -> 'a t) rather than a promise ('a t) (#965)
66

7+
* Remove the deprecated Lwt.result type (use Stdlib.result instead) (#968)
8+
9+
* Remove the deprecated Lwt.make_value and Lwt.make_result functions (use Ok and Error instead) (#968)
10+
11+
* Remove the deprecated and unsafe waiter_of_wakener (keep the waiter around when you create the wakener instead) (#968)
12+
13+
* Remove the deprecated Lwt_stream.on_termination and Lwt_stream.on_terminate (bind to Lwt_stream.closed instead) (#968)
14+
15+
* Remove the deprecated Lwt_stream.result type (use Stdlib.result instead) (#968)
16+
17+
* Remove the deprecated Lwt_stream.map_exn function (use wrap_exn instead) (#968)
18+
719
====== Additions ======
820

921
* Lwt.reraise an exception raising function which preserves backtraces, recommended for use in Lwt.catch (#963)

src/core/lwt.ml

Lines changed: 19 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -537,11 +537,6 @@ module Public_types =
537537
struct
538538
type +'a t
539539
type -'a u
540-
(* The contravariance of resolvers is, technically, unsound due to the
541-
existence of [Lwt.waiter_of_wakener]. That is why that function is
542-
deprecated. See
543-
544-
https://github.com/ocsigen/lwt/issues/458 *)
545540

546541
let to_public_promise : ('a, _, _) promise -> 'a t = Obj.magic
547542
let to_public_resolver : ('a, _, _) promise -> 'a u = Obj.magic
@@ -570,18 +565,10 @@ struct
570565
be optimized away even on older versions of OCaml that don't have Flambda
571566
and don't support [[@@ocaml.unboxed]]. *)
572567

573-
574-
575-
(* Internal name of the public [+'a Lwt.result]. The public name is defined
576-
later in the module. This is to avoid potential confusion with
577-
[Stdlib.result]/[Result.result], as the public name would not be
578-
prefixed with [Lwt.] inside this file. *)
579-
type +'a lwt_result = ('a, exn) Result.t
580-
581568
(* This could probably save an allocation by using [Obj.magic]. *)
582569
let state_of_result = function
583-
| Result.Ok x -> Fulfilled x
584-
| Result.Error exn -> Rejected exn
570+
| Ok x -> Fulfilled x
571+
| Error exn -> Rejected exn
585572
end
586573
include Public_types
587574

@@ -1341,11 +1328,11 @@ include Resolution_loop
13411328

13421329
module Resolving :
13431330
sig
1344-
val wakeup_later_result : 'a u -> 'a lwt_result -> unit
1331+
val wakeup_later_result : 'a u -> ('a, exn) result -> unit
13451332
val wakeup_later : 'a u -> 'a -> unit
13461333
val wakeup_later_exn : _ u -> exn -> unit
13471334

1348-
val wakeup_result : 'a u -> 'a lwt_result -> unit
1335+
val wakeup_result : 'a u -> ('a, exn) result -> unit
13491336
val wakeup : 'a u -> 'a -> unit
13501337
val wakeup_exn : _ u -> exn -> unit
13511338

@@ -1373,8 +1360,8 @@ struct
13731360
ignore p
13741361

13751362
let wakeup_result r result = wakeup_general "wakeup_result" r result
1376-
let wakeup r v = wakeup_general "wakeup" r (Result.Ok v)
1377-
let wakeup_exn r exn = wakeup_general "wakeup_exn" r (Result.Error exn)
1363+
let wakeup r v = wakeup_general "wakeup" r (Ok v)
1364+
let wakeup_exn r exn = wakeup_general "wakeup_exn" r (Error exn)
13781365

13791366
let wakeup_later_general api_function_name r result =
13801367
let Internal p = to_internal_resolver r in
@@ -1397,9 +1384,9 @@ struct
13971384
let wakeup_later_result r result =
13981385
wakeup_later_general "wakeup_later_result" r result
13991386
let wakeup_later r v =
1400-
wakeup_later_general "wakeup_later" r (Result.Ok v)
1387+
wakeup_later_general "wakeup_later" r (Ok v)
14011388
let wakeup_later_exn r exn =
1402-
wakeup_later_general "wakeup_later_exn" r (Result.Error exn)
1389+
wakeup_later_general "wakeup_later_exn" r (Error exn)
14031390

14041391

14051392

@@ -1471,15 +1458,15 @@ module Trivial_promises :
14711458
sig
14721459
val return : 'a -> 'a t
14731460
val fail : exn -> _ t
1474-
val of_result : 'a lwt_result -> 'a t
1461+
val of_result : ('a, exn) result -> 'a t
14751462

14761463
val return_unit : unit t
14771464
val return_true : bool t
14781465
val return_false : bool t
14791466
val return_none : _ option t
14801467
val return_some : 'a -> 'a option t
1481-
val return_ok : 'a -> ('a, _) Result.t t
1482-
val return_error : 'e -> (_, 'e) Result.t t
1468+
val return_ok : 'a -> ('a, _) result t
1469+
val return_error : 'e -> (_, 'e) result t
14831470
val return_nil : _ list t
14841471

14851472
val fail_with : string -> _ t
@@ -1501,8 +1488,8 @@ struct
15011488
let return_nil = return []
15021489
let return_true = return true
15031490
let return_false = return false
1504-
let return_ok x = return (Result.Ok x)
1505-
let return_error x = return (Result.Error x)
1491+
let return_ok x = return (Ok x)
1492+
let return_error x = return (Error x)
15061493

15071494
let fail_with msg =
15081495
to_public_promise {state = Rejected (Failure msg)}
@@ -1525,8 +1512,6 @@ sig
15251512
val wait : unit -> 'a t * 'a u
15261513
val task : unit -> 'a t * 'a u
15271514

1528-
val waiter_of_wakener : 'a u -> 'a t
1529-
15301515
val add_task_r : 'a u Lwt_sequence.t -> 'a t
15311516
val add_task_l : 'a u Lwt_sequence.t -> 'a t
15321517

@@ -1565,12 +1550,6 @@ struct
15651550

15661551

15671552

1568-
let waiter_of_wakener r =
1569-
let Internal r = to_internal_resolver r in
1570-
let p = r in
1571-
to_public_promise p
1572-
1573-
15741553

15751554
let cast_sequence_node
15761555
(node : 'a u Lwt_sequence.node)
@@ -2637,7 +2616,7 @@ struct
26372616
let count_resolved_promises_in (ps : 'a t list) =
26382617
let rec count_and_gather_rejected total rejected ps =
26392618
match ps with
2640-
| [] -> Result.Error (total, rejected)
2619+
| [] -> Error (total, rejected)
26412620
| p :: ps ->
26422621
let Internal q = to_internal_promise p in
26432622
match (underlying q).state with
@@ -2647,7 +2626,7 @@ struct
26472626
in
26482627
let rec count_fulfilled total ps =
26492628
match ps with
2650-
| [] -> Result.Ok total
2629+
| [] -> Ok total
26512630
| p :: ps ->
26522631
let Internal q = to_internal_promise p in
26532632
match (underlying q).state with
@@ -2709,7 +2688,7 @@ struct
27092688
invalid_arg
27102689
"Lwt.choose [] would return a promise that is pending forever";
27112690
match count_resolved_promises_in ps with
2712-
| Result.Ok 0 ->
2691+
| Ok 0 ->
27132692
let p = new_pending ~how_to_cancel:(propagate_cancel_to_several ps) in
27142693

27152694
let callback result =
@@ -2723,13 +2702,13 @@ struct
27232702

27242703
to_public_promise p
27252704

2726-
| Result.Ok 1 ->
2705+
| Ok 1 ->
27272706
nth_resolved ps 0
27282707

2729-
| Result.Ok n ->
2708+
| Ok n ->
27302709
nth_resolved ps (Random.State.int (Lazy.force prng) n)
27312710

2732-
| Result.Error (n, ps) ->
2711+
| Error (n, ps) ->
27332712
nth_resolved ps (Random.State.int (Lazy.force prng) n)
27342713

27352714
let pick ps =
@@ -3184,14 +3163,3 @@ struct
31843163
let (let+) x f = map f x
31853164
let (and+) = both
31863165
end
3187-
3188-
3189-
module Lwt_result_type =
3190-
struct
3191-
type +'a result = 'a lwt_result
3192-
3193-
(* Deprecated. *)
3194-
let make_value v = Result.Ok v
3195-
let make_error exn = Result.Error exn
3196-
end
3197-
include Lwt_result_type

src/core/lwt.mli

Lines changed: 5 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1600,45 +1600,26 @@ Lwt.fail (Stdlib.Invalid_argument s)
16001600

16011601
(** {3 Result type} *)
16021602

1603-
type nonrec +'a result = ('a, exn) result
1604-
(** Representation of the content of a resolved promise of type
1605-
['a ]{!Lwt.t}.
1606-
1607-
This type is effectively
1608-
1609-
{[
1610-
type +'a Lwt.result =
1611-
| Ok of 'a
1612-
| Error of exn
1613-
]}
1614-
1603+
(**
16151604
A resolved promise of type ['a ]{!Lwt.t} is either fulfilled with a value of
16161605
type ['a], or rejected with an exception.
16171606
16181607
This corresponds to the cases of a [('a, exn)]{!Stdlib.result}:
16191608
fulfilled corresponds to [Ok of 'a], and rejected corresponds to
16201609
[Error of exn].
16211610
1622-
It's important to note that this type constructor, [Lwt.result], is
1623-
different from [Stdlib.result]. It is a specialization of [Stdlib.result] so
1624-
that the [Error] constructor always carries [exn].
1625-
16261611
For Lwt programming with [result] where the [Error] constructor can carry
1627-
arbitrary error types, see module {!Lwt_result}.
1628-
1629-
The naming conflict between [Lwt.result] and [Stdlib.result] is an
1630-
unfortunate historical accident. [Stdlib.result] did not exist when
1631-
[Lwt.result] was created. *)
1612+
arbitrary error types, see module {!Lwt_result}. *)
16321613

1633-
val of_result : 'a result -> 'a t
1614+
val of_result : ('a, exn) result -> 'a t
16341615
(** [Lwt.of_result r] converts an r to a resolved promise.
16351616
16361617
- If [r] is [Ok v], [Lwt.of_result r] is [Lwt.return v], i.e. a promise
16371618
fulfilled with [v].
16381619
- If [r] is [Error exn], [Lwt.of_result r] is [Lwt.fail exn], i.e. a promise
16391620
rejected with [exn]. *)
16401621

1641-
val wakeup_later_result : 'a u -> 'a result -> unit
1622+
val wakeup_later_result : 'a u -> ('a, exn) result -> unit
16421623
(** [Lwt.wakeup_later_result r result] resolves the pending promise [p]
16431624
associated to resolver [r], according to [result]:
16441625
@@ -1802,43 +1783,12 @@ val wakeup_exn : _ u -> exn -> unit
18021783
(** [Lwt.wakeup_exn r exn] is like {!Lwt.wakeup_later_exn}[ r exn], but has
18031784
the same problems as {!Lwt.wakeup}. *)
18041785

1805-
val wakeup_result : 'a u -> 'a result -> unit
1786+
val wakeup_result : 'a u -> ('a, exn) result -> unit
18061787
(** [Lwt.wakeup_result r result] is like {!Lwt.wakeup_later_result}[ r result],
18071788
but has the same problems as {!Lwt.wakeup}. *)
18081789

18091790

18101791

1811-
(** {3 Helpers for resolving} *)
1812-
1813-
val make_value : 'a -> 'a result
1814-
[@@ocaml.deprecated
1815-
" Use Ok (from Stdlib) instead."]
1816-
(** [Lwt.make_value v] is equivalent to
1817-
{{: https://ocaml.org/api/Stdlib.html#TYPEresult}
1818-
[Ok v]}.
1819-
1820-
@deprecated Use [Ok] instead *)
1821-
1822-
val make_error : exn -> _ result
1823-
[@@ocaml.deprecated
1824-
" Use Error (from Stdlib) instead."]
1825-
(** [Lwt.make_error exn] is equivalent to
1826-
{{: https://ocaml.org/api/Stdlib.html#TYPEresult}
1827-
[Error exn]}.
1828-
1829-
@deprecated Use [Error] (from Stdlib) instead. *)
1830-
1831-
val waiter_of_wakener : 'a u -> 'a t
1832-
[@@ocaml.deprecated
1833-
" This function should be avoided, because it makes subtyping of resolvers
1834-
unsound. See
1835-
https://github.com/ocsigen/lwt/issues/458"]
1836-
(** [Lwt.waiter_of_wakener r] evaluates to the promise associated with resolver
1837-
[r].
1838-
1839-
@deprecated Keep the reference to the promise instead. *)
1840-
1841-
18421792

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

0 commit comments

Comments
 (0)