Skip to content

Commit

Permalink
sexp_of_lazy_t
Browse files Browse the repository at this point in the history
  • Loading branch information
lukstafi committed Feb 25, 2024
1 parent b5bdbea commit c584a60
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- `forget_printbox`
- `snapshot` in the PrintBox backend as in [#21](https://github.com/lukstafi/ppx_minidebug/issues/21).
- Optionally, `snapshot ()` at the end of a `log_value` call if elapsed time since last snapshot is greater than given threshold.
- A replacement `Minidebug_runtime.sexp_of_lazy_t` that does not force the thunk (but prints content if available).

### Changed

Expand Down
4 changes: 4 additions & 0 deletions minidebug_runtime.ml
Original file line number Diff line number Diff line change
Expand Up @@ -893,3 +893,7 @@ let debug_flushing ?debug_ch:d_ch ?filename ?(time_tagged = false)
(module Flushing ((val log_to)))

let forget_printbox (module Runtime : PrintBox_runtime) = (module Runtime : Debug_runtime)

let sexp_of_lazy_t sexp_of_a l =
if Lazy.is_val l then Sexplib0.Sexp.List [ Atom "lazy"; sexp_of_a @@ Lazy.force l ]
else Sexplib0.Sexp.List [ Atom "lazy"; Atom "<thunk>" ]
4 changes: 4 additions & 0 deletions minidebug_runtime.mli
Original file line number Diff line number Diff line change
Expand Up @@ -248,3 +248,7 @@ val debug_flushing :

val forget_printbox : (module PrintBox_runtime) -> (module Debug_runtime)
(** Upcasts the runtime. *)

val sexp_of_lazy_t : ('a -> Sexplib0.Sexp.t) -> 'a lazy_t -> Sexplib0.Sexp.t
(** Unlike [Lazy.sexp_of_t] available in the [Base] library, does not force the lazy value,
only converts it if it's already computed and non-exception. *)

0 comments on commit c584a60

Please sign in to comment.