Skip to content

Commit

Permalink
Error-monad: fewer names, more explicit names
Browse files Browse the repository at this point in the history
  • Loading branch information
raphael-proust committed Sep 21, 2021
1 parent 353db0a commit e102211
Show file tree
Hide file tree
Showing 14 changed files with 17 additions and 50 deletions.
2 changes: 0 additions & 2 deletions src/lib_error_monad/TzCore.mli
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,4 @@ type error = ..

include Sig.CORE with type error := error

include Sig.EXT with type error := error

include Sig.WITH_WRAPPED with type error := error
2 changes: 1 addition & 1 deletion src/lib_error_monad/TzMonad.ml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@
type error = TzCore.error = ..

include TzLwtreslib.Monad
include Monad_ext_maker.Make (TzCore) (TzTrace) (TzLwtreslib.Monad)
include Monad_extension_maker.Make (TzCore) (TzTrace) (TzLwtreslib.Monad)
2 changes: 1 addition & 1 deletion src/lib_error_monad/TzMonad.mli
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ include
with type 'error trace := 'error TzTrace.trace

include
Sig.MONAD_EXT
Sig.MONAD_EXTENSION
with type error := error
and type 'error trace := 'error TzTrace.trace
4 changes: 0 additions & 4 deletions src/lib_error_monad/core_maker.ml
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ module Make (Prefix : Sig.PREFIX) : sig

include Sig.CORE with type error := error

include Sig.EXT with type error := error

include Sig.WITH_WRAPPED with type error := error
end = struct
type error = ..
Expand All @@ -55,8 +53,6 @@ end = struct

include Sig.CORE with type error := unwrapped

include Sig.EXT with type error := unwrapped

val unwrap : error -> unwrapped option

val wrap : unwrapped -> error
Expand Down
2 changes: 0 additions & 2 deletions src/lib_error_monad/core_maker.mli
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,5 @@ module Make (Prefix : Sig.PREFIX) : sig

include Sig.CORE with type error := error

include Sig.EXT with type error := error

include Sig.WITH_WRAPPED with type error := error
end
4 changes: 1 addition & 3 deletions src/lib_error_monad/error_monad.mli
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ type error = TzCore.error = ..

include Sig.CORE with type error := error

include Sig.EXT with type error := error

include Sig.WITH_WRAPPED with type error := error

module TzTrace : Sig.TRACE with type 'error trace = 'error list
Expand All @@ -55,7 +53,7 @@ include
with type 'error trace := 'error TzTrace.trace

include
Sig.MONAD_EXT
Sig.MONAD_EXTENSION
with type error := error
and type 'error trace := 'error TzTrace.trace

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,11 @@ module Make (Error : sig
type error = ..

include Sig.CORE with type error := error

include Sig.EXT with type error := error
end)
(Trace : Sig.TRACE)
(Monad : Tezos_lwt_result_stdlib.Lwtreslib.TRACED_MONAD
with type 'error trace := 'error Trace.trace) :
Sig.MONAD_EXT
Sig.MONAD_EXTENSION
with type error := Error.error
and type 'error trace := 'error Trace.trace = struct
open Monad
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,10 @@ module Make (Error : sig
type error = ..

include Sig.CORE with type error := error

include Sig.EXT with type error := error
end)
(Trace : Sig.TRACE)
(Monad : Tezos_lwt_result_stdlib.Lwtreslib.TRACED_MONAD
with type 'error trace := 'error Trace.trace) :
Sig.MONAD_EXT
Sig.MONAD_EXTENSION
with type error := Error.error
and type 'error trace := 'error Trace.trace
23 changes: 7 additions & 16 deletions src/lib_error_monad/sig.ml
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,11 @@ module type PREFIX = sig
end

module type CORE = sig
type error
type error = ..

val error_encoding : error Data_encoding.t

val pp : Format.formatter -> error -> unit
end

(** [EXT] is the extensions on top of a [CORE]. The separation is largely
artificial and will most likely disappear with the next round of
refactoring. See https://gitlab.com/tezos/tezos/-/issues/1579 *)
module type EXT = sig
type error = ..

(** The error data type is extensible. Each module can register specialized
error serializers
Expand Down Expand Up @@ -164,8 +157,6 @@ module type WITH_WRAPPED = sig

include CORE with type error := unwrapped

include EXT with type error := unwrapped

(** [unwrap e] returns [Some] when [e] matches variant constructor [C]
and [None] otherwise *)
val unwrap : error -> unwrapped option
Expand Down Expand Up @@ -216,12 +207,12 @@ module type TRACE = sig
val fold : ('a -> 'error -> 'a) -> 'a -> 'error trace -> 'a
end

(** [MONAD_EXT] is the Tezos-specific extension to the generic monad provided by
Lwtreslib. It sets some defaults (e.g., it defaults traced failures), it
brings some qualified identifiers into the main unqualified part (e.g.,
[return_unit]), it provides some tracing helpers and some in-monad assertion
checks. *)
module type MONAD_EXT = sig
(** [MONAD_EXTENSION] is the Tezos-specific extension to the generic monad
provided by Lwtreslib. It sets some defaults (e.g., it defaults traced
failures), it brings some qualified identifiers into the main unqualified
part (e.g., [return_unit]), it provides some tracing helpers and some
in-monad assertion checks. *)
module type MONAD_EXTENSION = sig
(** for substitution *)
type error

Expand Down
4 changes: 1 addition & 3 deletions src/lib_protocol_environment/environment_V0.ml
Original file line number Diff line number Diff line change
Expand Up @@ -353,8 +353,6 @@ struct
Error_core :
sig
include Tezos_error_monad.Sig.CORE with type error := unwrapped

include Tezos_error_monad.Sig.EXT with type error := unwrapped
end)

let unwrap = function Ecoproto_error ecoerror -> Some ecoerror | _ -> None
Expand All @@ -372,7 +370,7 @@ struct
include Error_core
include Tezos_error_monad.TzLwtreslib.Monad
include
Tezos_error_monad.Monad_ext_maker.Make (Error_core) (TzTrace)
Tezos_error_monad.Monad_extension_maker.Make (Error_core) (TzTrace)
(Tezos_error_monad.TzLwtreslib.Monad)

(* below is for backward compatibility *)
Expand Down
4 changes: 1 addition & 3 deletions src/lib_protocol_environment/environment_V1.ml
Original file line number Diff line number Diff line change
Expand Up @@ -540,8 +540,6 @@ struct
Error_core :
sig
include Tezos_error_monad.Sig.CORE with type error := unwrapped

include Tezos_error_monad.Sig.EXT with type error := unwrapped
end)

let unwrap = function Ecoproto_error ecoerror -> Some ecoerror | _ -> None
Expand All @@ -559,7 +557,7 @@ struct
include Error_core
include Tezos_error_monad.TzLwtreslib.Monad
include
Tezos_error_monad.Monad_ext_maker.Make (Error_core) (TzTrace)
Tezos_error_monad.Monad_extension_maker.Make (Error_core) (TzTrace)
(Tezos_error_monad.TzLwtreslib.Monad)

(* Backwards compatibility additions (traversors, dont_wait, trace) *)
Expand Down
4 changes: 1 addition & 3 deletions src/lib_protocol_environment/environment_V2.ml
Original file line number Diff line number Diff line change
Expand Up @@ -548,8 +548,6 @@ struct
Error_core :
sig
include Tezos_error_monad.Sig.CORE with type error := unwrapped

include Tezos_error_monad.Sig.EXT with type error := unwrapped
end)

let unwrap = function Ecoproto_error ecoerror -> Some ecoerror | _ -> None
Expand All @@ -567,7 +565,7 @@ struct
include Error_core
include Tezos_error_monad.TzLwtreslib.Monad
include
Tezos_error_monad.Monad_ext_maker.Make (Error_core) (TzTrace)
Tezos_error_monad.Monad_extension_maker.Make (Error_core) (TzTrace)
(Tezos_error_monad.TzLwtreslib.Monad)

(* Backwards compatibility additions (traversors, dont_wait, trace helpers) *)
Expand Down
4 changes: 1 addition & 3 deletions src/lib_protocol_environment/environment_V3.ml
Original file line number Diff line number Diff line change
Expand Up @@ -612,8 +612,6 @@ struct
Error_core :
sig
include Tezos_error_monad.Sig.CORE with type error := unwrapped
include Tezos_error_monad.Sig.EXT with type error := unwrapped
end)
let unwrap = function Ecoproto_error ecoerror -> Some ecoerror | _ -> None
Expand All @@ -631,7 +629,7 @@ struct
include Error_core
include Tezos_error_monad.TzLwtreslib.Monad
include
Tezos_error_monad.Monad_ext_maker.Make (Error_core) (TzTrace)
Tezos_error_monad.Monad_extension_maker.Make (Error_core) (TzTrace)
(Tezos_error_monad.TzLwtreslib.Monad)
(* Backwards compatibility additions (dont_wait, trace helpers) *)
Expand Down
4 changes: 1 addition & 3 deletions src/lib_protocol_environment/environment_V4.ml
Original file line number Diff line number Diff line change
Expand Up @@ -624,8 +624,6 @@ struct
Error_core :
sig
include Tezos_error_monad.Sig.CORE with type error := unwrapped
include Tezos_error_monad.Sig.EXT with type error := unwrapped
end)
let unwrap = function Ecoproto_error ecoerror -> Some ecoerror | _ -> None
Expand All @@ -643,7 +641,7 @@ struct
include Error_core
include Tezos_error_monad.TzLwtreslib.Monad
include
Tezos_error_monad.Monad_ext_maker.Make (Error_core) (TzTrace)
Tezos_error_monad.Monad_extension_maker.Make (Error_core) (TzTrace)
(Tezos_error_monad.TzLwtreslib.Monad)
(* Backwards compatibility additions (dont_wait, trace helpers) *)
Expand Down

0 comments on commit e102211

Please sign in to comment.