Skip to content

Commit f953a5b

Browse files
improve names and documentation
1 parent 5928b4b commit f953a5b

File tree

10 files changed

+30
-27
lines changed

10 files changed

+30
-27
lines changed

src/core/lwt.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -712,14 +712,14 @@ open Basic_helpers
712712

713713
(* Small helpers to avoid catching ocaml-runtime exceptions *)
714714
type exception_filter = exn -> bool
715-
let catch_all_filter = fun _ -> true
716-
let catch_not_runtime_filter = function
715+
let catch_filter__all = fun _ -> true
716+
let catch_filter__all_except_runtime = function
717717
| Out_of_memory -> false
718718
| Stack_overflow -> false
719719
| _ -> true
720720
let exception_filter =
721721
(* Default value: the legacy behaviour to avoid breaking programs *)
722-
ref catch_all_filter
722+
ref catch_filter__all
723723
let set_exception_filter f = exception_filter := f
724724
let filter_exception e = !exception_filter e
725725

src/core/lwt.mli

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2003,10 +2003,10 @@ val ignore_result : _ t -> unit
20032003
20042004
Depending on the kind of programs that you write, you may need to treat
20052005
exceptions thrown by the OCaml runtime (namely [Out_of_memory] and
2006-
[Stack_overflow] differently. This is because (a) these exceptions are not
2007-
reproducible (in that they are thrown at different points of your program
2008-
depending on the machine that your program runs on) and (b) recovering
2009-
from these errors may be impossible.
2006+
[Stack_overflow]) differently than all the other exceptions. This is because
2007+
(a) these exceptions are not reproducible (in that they are thrown at
2008+
different points of your program depending on the machine that your program
2009+
runs on) and (b) recovering from these errors may be impossible.
20102010
20112011
The helpers below allow you to change the way that Lwt handles the two OCaml
20122012
runtime exceptions [Out_of_memory] and [Stack_overflow]. *)
@@ -2016,15 +2016,15 @@ val ignore_result : _ t -> unit
20162016
immediately. *)
20172017
type exception_filter
20182018

2019-
(** [catch_all_filter] is the default filter. With it the all the exceptions
2019+
(** [catch_filter__all] is the default filter. With it the all the exceptions
20202020
(including [Out_of_memory] and [Stack_overflow]) are caught and transformed
20212021
into rejected promises. *)
2022-
val catch_all_filter : exception_filter
2022+
val catch_filter__all : exception_filter
20232023

2024-
(** [catch_not_runtime_filter] is a filter which lets the OCaml runtime
2024+
(** [catch_filter__all_except_runtime] is a filter which lets the OCaml runtime
20252025
exceptions ([Out_of_memory] and [Stack_overflow]) go through all the Lwt
20262026
abstractions and bubble all the way out of the call to [Lwt_main.run]. *)
2027-
val catch_not_runtime_filter : exception_filter
2027+
val catch_filter__all_except_runtime : exception_filter
20282028

20292029
(** [set_exception_filter] sets the given exception filter globally. *)
20302030
val set_exception_filter : exception_filter -> unit

src/unix/lwt_main.mli

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,16 @@ let () = Lwt_main.run (main ())
3939
[Lwt_main.run] will raise [Failure]. This should be considered a logic
4040
error (i.e., code making such a call is inherently broken).
4141
42-
In addition, note that Lwt does not attempt to catch exceptions thrown by
43-
the OCaml runtime. Specifically, Lwt lets [Out_of_memory] and
44-
[Stack_overflow] exceptions traverse all of its functions and bubble up to
45-
the caller of [Lwt_main.run]. Moreover because these exceptions are left
46-
to traverse the call stack, they leave the internal data-structures in an
47-
inconsistent state. For this reason, calling [Lwt_main.run] again after
48-
such an exception will raise [Failure].
42+
In addition, note that if you have set the exception filter to let runtime
43+
exceptions bubble up (via
44+
[Lwt.set_exception_filter catch_filter__all_except_runtime]) then Lwt does
45+
not attempt to catch exceptions thrown by the OCaml runtime. Specifically,
46+
in this case, Lwt lets [Out_of_memory] and [Stack_overflow] exceptions
47+
traverse all of its functions and bubble up to the caller of
48+
[Lwt_main.run]. Moreover because these exceptions are left to traverse the
49+
call stack, they leave the internal data-structures in an inconsistent
50+
state. For this reason, calling [Lwt_main.run] again after such an
51+
exception will raise [Failure].
4952
5053
It is not safe to call [Lwt_main.run] in a function registered with
5154
[Stdlib.at_exit], use {!Lwt_main.at_exit} instead. *)

test/core/test_lwt.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,7 @@ let catch_tests = suite "catch" [
638638

639639

640640
test "catch with ocaml-runtime exception" begin fun () ->
641-
Lwt.set_exception_filter Lwt.catch_not_runtime_filter;
641+
Lwt.set_exception_filter Lwt.catch_filter__all_except_runtime;
642642
try
643643
Lwt.catch
644644
(fun () -> raise Out_of_memory)
@@ -648,7 +648,7 @@ let catch_tests = suite "catch" [
648648
end;
649649

650650
test "try_bind with ocaml-runtime exception" begin fun () ->
651-
Lwt.set_exception_filter Lwt.catch_not_runtime_filter;
651+
Lwt.set_exception_filter Lwt.catch_filter__all_except_runtime;
652652
try
653653
Lwt.try_bind
654654
(fun () -> raise Out_of_memory)
@@ -659,7 +659,7 @@ let catch_tests = suite "catch" [
659659
end;
660660

661661
test "try_bind(2) with ocaml-runtime exception" begin fun () ->
662-
Lwt.set_exception_filter Lwt.catch_not_runtime_filter;
662+
Lwt.set_exception_filter Lwt.catch_filter__all_except_runtime;
663663
try
664664
let _ =
665665
Lwt.try_bind

test/unix/ocaml_runtime_exc_1.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
details, or visit https://github.com/ocsigen/lwt/blob/master/LICENSE.md. *)
33

44
(* set the exception filter being tested *)
5-
let () = Lwt.set_exception_filter Lwt.catch_not_runtime_filter
5+
let () = Lwt.set_exception_filter Lwt.catch_filter__all_except_runtime
66

77
(* OCaml runtime exceptions (out-of-memory, stack-overflow) are fatal in a
88
different way than other exceptions and they leave the Lwt main loop in an

test/unix/ocaml_runtime_exc_2.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
details, or visit https://github.com/ocsigen/lwt/blob/master/LICENSE.md. *)
33

44
(* set the exception filter being tested *)
5-
let () = Lwt.set_exception_filter Lwt.catch_not_runtime_filter
5+
let () = Lwt.set_exception_filter Lwt.catch_filter__all_except_runtime
66

77
(* OCaml runtime exceptions (out-of-memory, stack-overflow) are fatal in a
88
different way than other exceptions and they leave the Lwt main loop in an

test/unix/ocaml_runtime_exc_3.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
details, or visit https://github.com/ocsigen/lwt/blob/master/LICENSE.md. *)
33

44
(* set the exception filter being tested *)
5-
let () = Lwt.set_exception_filter Lwt.catch_not_runtime_filter
5+
let () = Lwt.set_exception_filter Lwt.catch_filter__all_except_runtime
66

77
(* OCaml runtime exceptions (out-of-memory, stack-overflow) are fatal in a
88
different way than other exceptions and they leave the Lwt main loop in an

test/unix/ocaml_runtime_exc_4.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
details, or visit https://github.com/ocsigen/lwt/blob/master/LICENSE.md. *)
33

44
(* set the exception filter being tested *)
5-
let () = Lwt.set_exception_filter Lwt.catch_not_runtime_filter
5+
let () = Lwt.set_exception_filter Lwt.catch_filter__all_except_runtime
66

77
(* OCaml runtime exceptions (out-of-memory, stack-overflow) are fatal in a
88
different way than other exceptions and they leave the Lwt main loop in an

test/unix/ocaml_runtime_exc_5.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
details, or visit https://github.com/ocsigen/lwt/blob/master/LICENSE.md. *)
33

44
(* set the exception filter being tested *)
5-
let () = Lwt.set_exception_filter Lwt.catch_not_runtime_filter
5+
let () = Lwt.set_exception_filter Lwt.catch_filter__all_except_runtime
66

77
(* OCaml runtime exceptions (out-of-memory, stack-overflow) are fatal in a
88
different way than other exceptions and they leave the Lwt main loop in an

test/unix/ocaml_runtime_exc_6.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
details, or visit https://github.com/ocsigen/lwt/blob/master/LICENSE.md. *)
33

44
(* set the exception filter being tested *)
5-
let () = Lwt.set_exception_filter Lwt.catch_not_runtime_filter
5+
let () = Lwt.set_exception_filter Lwt.catch_filter__all_except_runtime
66

77
(* OCaml runtime exceptions (out-of-memory, stack-overflow) are fatal in a
88
different way than other exceptions and they leave the Lwt main loop in an

0 commit comments

Comments
 (0)